-
Notifications
You must be signed in to change notification settings - Fork 74
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 library to store cmd-exec-id in context #2439
base: main
Are you sure you want to change the base?
Conversation
@@ -106,7 +107,7 @@ func getCobraCmdForTest(f fixtures.HTTPFixture) (*cobra.Command, *bytes.Buffer) | |||
func TestTokenCmdWithProfilePrintsHelpfulLoginMessageOnRefreshFailure(t *testing.T) { | |||
cmd, output := getCobraCmdForTest(refreshFailureTokenResponse) | |||
cmd.SetArgs([]string{"auth", "token", "--profile", "expired"}) | |||
err := cmd.Execute() | |||
err := root.Execute(cmd.Context(), cmd) |
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.
These unrelated tests were modified to use the root.Execute
execute function, which ensures that cmd-exec-id
is set in the context since, otherwise, these tests fail.
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.
Are there other side effects of doing so?
@@ -106,7 +107,7 @@ func getCobraCmdForTest(f fixtures.HTTPFixture) (*cobra.Command, *bytes.Buffer) | |||
func TestTokenCmdWithProfilePrintsHelpfulLoginMessageOnRefreshFailure(t *testing.T) { | |||
cmd, output := getCobraCmdForTest(refreshFailureTokenResponse) | |||
cmd.SetArgs([]string{"auth", "token", "--profile", "expired"}) | |||
err := cmd.Execute() | |||
err := root.Execute(cmd.Context(), cmd) |
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.
Are there other side effects of doing so?
@@ -124,6 +125,9 @@ Stack Trace: | |||
%s`, version, r, string(trace)) | |||
}() | |||
|
|||
// Set a cmd-exec-id value in the context |
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.
That it is used as cmd-exec-id
in the UA is not important here.
I suggest also not abbreviating here.
// execIDKey is the context key for the execution ID. | ||
// The value of 1 is arbitrary and can be any number. | ||
// Other keys in the same package must have different values. | ||
execIDKey = key(1) |
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.
Mix of initialism and not, please use one.
execIDKey = key(1) | ||
) | ||
|
||
func SetExecId(ctx context.Context) context.Context { |
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.
Set implies (to me) that the user specifies a value. That's not the case here. Maybe GenerateExecutionID
?
require.Len(t, matches, 1) | ||
_, err := uuid.Parse(matches[0][1]) | ||
assert.NoError(t, err) | ||
assert.Contains(t, ua, "cmd-exec-id/some-exec-id") |
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.
If the mock function is only included to make this test not use a regexp, it can be omitted IMO.
Why
The command execution ID is a UUID that should be initialized once, and then have a consistent read value for the duration of the command.
As we start emitting telemetry events, we also want to emit the command execution ID in the telemetry payload. This library helps consolidate all reads to the
cmd-exec-id
value, and ensures there's only one write for the UUID.relevant comment: #2432 (comment)
Tests
Unit tests.