-
Notifications
You must be signed in to change notification settings - Fork 229
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
feat: add metric headers #1503
feat: add metric headers #1503
Conversation
|
||
package com.google.auth; | ||
|
||
public enum CredentialType { |
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.
Since these are strictly defined by our metrics implementation, can we make that more clear everywhere?
For instance we might call this "CredentialNameForMetrics" (or something better than that).
That way we know that we can't add enum items without a definition that is established elsewhere, and there won't be Credentials that have a CredentialType of Unknown (when we actually do know the type, we just don't want to score it for metrics.)
oauth2_http/java/com/google/auth/oauth2/ComputeEngineCredentials.java
Outdated
Show resolved
Hide resolved
oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java
Outdated
Show resolved
Hide resolved
oauth2_http/java/com/google/auth/oauth2/ComputeEngineCredentials.java
Outdated
Show resolved
Hide resolved
oauth2_http/javatests/com/google/auth/oauth2/MockMetadataServerTransport.java
Show resolved
Hide resolved
oauth2_http/java/com/google/auth/oauth2/ComputeEngineCredentials.java
Outdated
Show resolved
Hide resolved
assertTrue(headers.containsKey(MetricsUtils.API_CLIENT_HEADER)); | ||
String actualMetricsValue = headers.get(MetricsUtils.API_CLIENT_HEADER).get(0); | ||
String expectedMetricsValue; | ||
if (requestType.equals("untracked")) { |
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.
nit: Can we use the enum value here?
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.
note requestType
and credentialType
here are String values. They represent part of the expected value in this utils method. I am leaning towards checking against plain text here
MetricsUtils.getLanguageAndAuthLibraryVersions(), | ||
MetricsUtils.CRED_TYPE, | ||
credentialType); | ||
} else if (credentialType.isEmpty()) { |
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.
Why isEmpty()
and not check for DO NOT SEND
?
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.
updating to be consistent with requestType
above.
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.
LGTM. Added two questions in the tests. Thanks for addressing the comments and questions!
Quality Gate passedIssues Measures |
This is POC change in gax-java for auth metrics requirements on token usage. See go/googleapis-auth-metric-design for context. [Credentials](https://github.com/googleapis/google-auth-library-java/blob/main/credentials/java/com/google/auth/Credentials.java) will expose `getMetricsCredentialType()` method, this change appends it to existing `x-goog-api-client` header Note: Currently implement in gax at client level. There are 2 edge cases not covered and will create followups for: if handwritten library overrides credentials at rpc level; If handwritten library does not build on gax. (ref: b/370039645, b/370038458) related change in `google-auth-library`googleapis/google-auth-library-java#1503 included in 1.28.0.
context: b/339259830 and go/send-auth-metrics-java
Changes include:
Credentials
type viagetMetricsCredentialType()
. Override this method for UserCredentials, ServiceAccountCredentials, ImpersonatedCredentials, and ComputeEngineCredentials. This is used in both token request and token usage flows.Related pr: adding for cred_type for token usage requests
googleapis/sdk-platform-java#3186