-
-
Notifications
You must be signed in to change notification settings - Fork 398
Add metadata retrieved from the context
to the user agent when a new HTTP client is created
#2789
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
Changes from 5 commits
b7b5399
fe84afb
4f73e4c
fc6d0a6
527f7d2
2e7d6c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -123,14 +123,21 @@ func NewArduinoCliWithinEnvironment(env *Environment, config *ArduinoCLIConfig) | |||||
// It returns a testsuite.Environment and an ArduinoCLI client to perform the integration tests. | ||||||
// The Environment must be disposed by calling the CleanUp method via defer. | ||||||
func CreateEnvForDaemon(t *testing.T) (*Environment, *ArduinoCLI) { | ||||||
return CreateEnvForDaemonWithUserAgent(t, "cli-test/0.0.0") | ||||||
} | ||||||
|
||||||
// CreateEnvForDaemonWithUserAgent performs the minimum required operations to start the arduino-cli daemon. | ||||||
// It returns a testsuite.Environment and an ArduinoCLI client to perform the integration tests. | ||||||
// The Environment must be disposed by calling the CleanUp method via defer. | ||||||
func CreateEnvForDaemonWithUserAgent(t *testing.T, userAgent string) (*Environment, *ArduinoCLI) { | ||||||
env := NewEnvironment(t) | ||||||
|
||||||
cli := NewArduinoCliWithinEnvironment(env, &ArduinoCLIConfig{ | ||||||
ArduinoCLIPath: FindRepositoryRootPath(t).Join("arduino-cli"), | ||||||
UseSharedStagingFolder: true, | ||||||
}) | ||||||
|
||||||
_ = cli.StartDaemon(false) | ||||||
_ = cli.StartDaemon(false, userAgent) | ||||||
return env, cli | ||||||
} | ||||||
|
||||||
|
@@ -410,7 +417,7 @@ func (cli *ArduinoCLI) run(stdoutBuff, stderrBuff io.Writer, stdinBuff io.Reader | |||||
} | ||||||
|
||||||
// StartDaemon starts the Arduino CLI daemon. It returns the address of the daemon. | ||||||
func (cli *ArduinoCLI) StartDaemon(verbose bool) string { | ||||||
func (cli *ArduinoCLI) StartDaemon(verbose bool, userAgent string) string { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I cannot think of uses cases that we need to pass different userAgent. The My suggestion is to just hardcode the |
||||||
args := []string{"daemon", "--json"} | ||||||
if cli.cliConfigPath != nil { | ||||||
args = append([]string{"--config-file", cli.cliConfigPath.String()}, args...) | ||||||
|
@@ -450,7 +457,11 @@ func (cli *ArduinoCLI) StartDaemon(verbose bool) string { | |||||
for retries := 5; retries > 0; retries-- { | ||||||
time.Sleep(time.Second) | ||||||
|
||||||
conn, err := grpc.NewClient(cli.daemonAddr, grpc.WithTransportCredentials(insecure.NewCredentials())) | ||||||
conn, err := grpc.NewClient( | ||||||
cli.daemonAddr, | ||||||
grpc.WithTransportCredentials(insecure.NewCredentials()), | ||||||
grpc.WithUserAgent(userAgent), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I'd simply hardcode the user-agent here. |
||||||
) | ||||||
if err != nil { | ||||||
connErr = err | ||||||
continue | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CreateEnvForDaemonWithUserAgent
this function is used only by theCreateEnvForDaemon
I would simplify and put everything in the same function as it was before.
The useragent will be hardcoded inside the
StartDaemon