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

Provide a way to set custom user agents for clients #33

Merged
merged 1 commit into from
May 4, 2018
Merged

Provide a way to set custom user agents for clients #33

merged 1 commit into from
May 4, 2018

Conversation

sethvargo
Copy link
Contributor

This adds a new interface that providers can implement that sets a user agent string. This is useful for upstream calling libraries.

/cc umm @pearkes - not sure who is managing this library anymore. Once this is merged, we can update Consul and Nomad upstream.

Copy link
Contributor

@pearkes pearkes left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution, @sethvargo! Left a few comments, mostly just curious if we need to make as many changes as we are to support this.

@@ -1,19 +1,79 @@
{
"comment": "",
"ignore": "test",
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mind formatting this file? I believe this was previously done manually. We don't have a Makefile or similar on this project, so there's no obvious way of knowing it, but should clean up the diff.

$ go get -u github.com/magiconair/vendorfmt/cmd/vendorfmt
$ vendorfmt

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm also wondering if we can drop the softlayer updates here too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Formatted. We have to keep the updates. The ability to set a custom user agent wasn't available in the vendored version.

Copy link
Contributor

Choose a reason for hiding this comment

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

@sethvargo Given softlayer isn't one of the providers we run regular acceptance tests against I'd rather drop these changes to it -- it is ok if it does not send the user agent at this time.

discover.go Outdated
type Option func(*Discover) error

// NewDiscover creates a new discover client with the given options.
func NewDiscover(opts ...Option) (*Discover, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm reading this right you're setting up a new way to initialize go-discover. Is it possible to limit the changes to fit with the existing APIs? If not, can you describe the use-case and example in Consul (I believe you're planning on utilizing this over there, per your comment)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also I'd name this New, not NewDiscover, since the package is already discover. This is just some guideline from "writing effective go".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to New. Thanks for the feedback.

The existing API doesn't change and is not obsoleted. However, I didn't want to make UserAgent a publicly accessible field on the Discover struct because it would introduce race conditions.

The API current is:

d := discover.Discover{}

That API will continue to function, but it's not very flexible, so I adopted the "options pattern" to allow for this:

d := discover.New(discovery.WithUserAgent("consul/1.0"))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be clearer: there exists a sad race condition in the current implementation. Since Providers is a public field on the struct, a user can set Providers to something, call a command, and then alter the field. However, since the init is done in a once, those changes won't take place.

@sethvargo
Copy link
Contributor Author

Ping @pearkes @mitchellh

This adds a new interface that providers can implement that sets a user
agent string. This is useful for upstream calling libraries.
@sethvargo
Copy link
Contributor Author

Removed the functionality from Softlayer @pearkes

@pearkes
Copy link
Contributor

pearkes commented May 4, 2018

Thanks @sethvargo!

@pearkes pearkes merged commit b55bdf9 into hashicorp:master May 4, 2018
@sethvargo sethvargo deleted the sethvargo/useragent branch May 4, 2018 18:42
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.

3 participants