Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set User-Agent header in client #256

Merged
merged 4 commits into from
Apr 18, 2023
Merged

Set User-Agent header in client #256

merged 4 commits into from
Apr 18, 2023

Conversation

danstn
Copy link
Contributor

@danstn danstn commented Apr 17, 2023

This sets the user agent for api client.

Using Provider.UserAgent to set the header.

Also, this can now take a version coming from ldflags which is added as a suffix.

Rendered example:

Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.0.3 buildkite/v0.14.0-1-g3539448

@danstn danstn changed the title Sketch user-agent setup Set User-Agent header in client Apr 17, 2023
@danstn danstn force-pushed the user-agent-setup branch 2 times, most recently from 3ece3d4 to bd95cd9 Compare April 17, 2023 07:08
jradtilbrook
jradtilbrook previously approved these changes Apr 18, 2023
Copy link
Contributor

@jradtilbrook jradtilbrook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a good addition so we can track usage of versions.
Some tests are failing though

@jradtilbrook jradtilbrook requested a review from mcncl April 18, 2023 00:02
@yob
Copy link
Contributor

yob commented Apr 18, 2023

Yesterday we had an acceptance spec failure caused by the test org not being cleaned properly, and I manually deleted a lingering pipeline. It's possible rebasing this on main (to get the merged GET body fix) and triggering a new build might Just Work.

mcncl
mcncl previously approved these changes Apr 18, 2023
@danstn danstn dismissed stale reviews from mcncl and jradtilbrook via 74f3e01 April 18, 2023 00:53
@danstn danstn force-pushed the user-agent-setup branch from bd95cd9 to 74f3e01 Compare April 18, 2023 00:53
@danstn danstn marked this pull request as ready for review April 18, 2023 00:54
Dockerfile Outdated Show resolved Hide resolved
@danstn danstn force-pushed the user-agent-setup branch from 18a51bd to a98f3ca Compare April 18, 2023 01:25
@mcncl mcncl merged commit c0db21c into main Apr 18, 2023
@mcncl mcncl deleted the user-agent-setup branch April 18, 2023 02:58
@yob
Copy link
Contributor

yob commented Apr 18, 2023

I don't think it's a deal breaker in the short term, but looking at the user agents we're logging in production now it seems like maybe this only sets it for REST API calls, and not for graphql ones?

@jradtilbrook
Copy link
Contributor

Actually yes @yob that is correct. I'll create another task to do this for graphql as well

yob added a commit that referenced this pull request Apr 18, 2023
In #256 we starting setting a custom User-Agent header on REST API
calls, to help us understand the ways our API is used. It looks like this:

    Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.0.3 buildkite/0.15.0

This builds on that work and sets the same User-Agent on graphql API
requests as well.

It drops the unnescary use of golang.org/x/oauth2 to set a static bearer
token header, and uses the tripperware pattern [1] to set both headers we
care about:

1. the static bearer token for auth
2. the user agent

The same http.Client is used for both REST and graphql, so we'll get
identical behaviour on both APIs.

[1] https://dev.to/stevenacoffman/tripperwares-http-client-middleware-chaining-roundtrippers-3o00
yob added a commit that referenced this pull request Apr 18, 2023
In #256 we starting setting a custom User-Agent header on REST API
calls, to help us understand the ways our API is used. It looks like this:

    Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.0.3 buildkite/0.15.0

This builds on that work and sets the same User-Agent on graphql API
requests as well.

It drops the unnecessary use of golang.org/x/oauth2 to set a static bearer
token header, and uses the tripperware pattern [1] to set both headers we
care about:

1. the static bearer token for auth
2. the user agent

The same http.Client is used for both REST and graphql, so we'll get
identical behaviour on both APIs.

[1] https://dev.to/stevenacoffman/tripperwares-http-client-middleware-chaining-roundtrippers-3o00
yob added a commit that referenced this pull request Apr 20, 2023
In #256 we starting setting a custom User-Agent header on REST API
calls, to help us understand the ways our API is used. It looks like this:

    Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.0.3 buildkite/0.15.0

This builds on that work and sets the same User-Agent on graphql API
requests as well.

It drops the unnecessary use of golang.org/x/oauth2 to set a static bearer
token header, and uses the tripperware pattern [1] to set both headers we
care about:

1. the static bearer token for auth
2. the user agent

The same http.Client is used for both REST and graphql, so we'll get
identical behaviour on both APIs.

[1] https://dev.to/stevenacoffman/tripperwares-http-client-middleware-chaining-roundtrippers-3o00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants