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

Add useragent #33

Merged
merged 3 commits into from
Dec 27, 2022
Merged

Add useragent #33

merged 3 commits into from
Dec 27, 2022

Conversation

rmweir
Copy link
Contributor

@rmweir rmweir commented Oct 18, 2022

Add the ability to configure useragent
Added the ability to configure a client's user agent. Added wrappers
for controllers, and factories that provide the ability to configure
the user agent of the clients they use.

Issue:
rancher/rancher#38775

@rmweir rmweir changed the title [WIP] Add useragent Add useragent Dec 9, 2022
return clientWithAgent
}

func (s *sharedClientFactoryWithAgent) clientWithAgent(client *Client) (*Client, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use client.WithAgent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤔 good call, WithAgent properly creates a copy as well. Replaced.

Comment on lines +13 to +15
Debugf = func(message string, obj ...interface{}) {
log.Printf("DEBUG: "+message+"\n", obj...)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Shouldn't these just be functions instead of variables pointing to functions?

Suggested change
Debugf = func(message string, obj ...interface{}) {
log.Printf("DEBUG: "+message+"\n", obj...)
}
)
func Debugf(message string, obj ...interface{}) {
log.Printf("DEBUG: "+message+"\n", obj...)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not write the package and am not sure what the intention was. For now I am conforming to how the other logs forms are written but for the longer term I made this issue for replacing it with an external logging package: rancher/wrangler#244.

Comment on lines 110 to 112
if config == nil {
return
}

Choose a reason for hiding this comment

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

I'm curious why you put the config == nil check here rather than around the caller. If someone uses setConfig elsewhere a nil config would be silently skipped. Where it's called this appears to be done for backwards compatibility. Shouldn't the nil check be there for better understanding of reading a section of code? Just thinking about it as someone who would read it 6 months from now and not be any of the reviewers or author.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I totally agree with this. There is no reason why it wouldn't be passed by value otherwise as well so I changed the function to accept it as a value.

@rmweir rmweir force-pushed the add-useragent branch 2 times, most recently from e8f7d20 to 5ce15a5 Compare December 13, 2022 01:14
@rmweir rmweir force-pushed the add-useragent branch 2 times, most recently from f376448 to 0aeab37 Compare December 14, 2022 15:59
@rmweir rmweir requested a review from KevinJoiner December 14, 2022 15:59
@rmweir rmweir requested a review from KevinJoiner December 14, 2022 23:03
Copy link

@mattfarina mattfarina left a comment

Choose a reason for hiding this comment

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

makes sense to me

@mattfarina
Copy link

@cmurphy do you want to re-review due to changes?

@@ -1,3 +1,6 @@
/*
Package cache provides a cache that maintains a list for a resource type which it updates as it
Copy link
Contributor

Choose a reason for hiding this comment

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

as it ...what?

sorry, missed this before

Choose a reason for hiding this comment

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

@rmweir you've left us hanging in suspense!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I was mid comment when I realized I didn't end up making any changes to the cache package 😛 . Removed.

Added the ability to configure a client's user agent. Added wrappers
for controllers, and factories that provide the ability to configure
the user agent of the clients they use.
@rmweir rmweir merged commit 6ea88ca into rancher:master Dec 27, 2022
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