-
Notifications
You must be signed in to change notification settings - Fork 98
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
vnext, add context to client #1067
Conversation
Let me know your opinion before I start implement the generator. |
return service.get(this.client.getHost(), resourceGroupName, this.client.getSubscriptionId(), this.client.getApiVersion()); | ||
return FluxUtil | ||
.withContext(context -> service.get(this.client.getHost(), resourceGroupName, this.client.getSubscriptionId(), this.client.getApiVersion(), context)) | ||
.subscriberContext(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext().addData("Sdk-Version", this.client.getApiVersion())))); |
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.
In https://azure.github.io/azure-sdk/general_azurecore.html#telemetry-policy, the Sdk-Version is the version of sdk (1.31.0 etc.) instead of the api -version. For Sdk-Name, I think it should use the whole package name (azure.management.resources).
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.
Got it. Sdk-Name seems not the whole package name (storage.blobs is apparently not a package name).
Then I will leave both to be set from the builder (similar to host/subscriptionId, manager could set this part of 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.
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.
is it necessary or ok to track machine 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.
I think there is no machine id? Just OS name/version, package name/version, java version.
Intended for #1090 Context in LRO seems not working correctly. |
if (sdkName == null) { | ||
String packageName = this.getClass().getPackage().getName(); | ||
if (packageName.endsWith(".models")) { | ||
sdkName = packageName.substring(0, packageName.length() - ".models".length()); |
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.
I am doing a bit of trick here.
ComputeManagementClientImpl
from com.azure.management.compute.models
would have Sdk-Name com.azure.management.compute
@ChenTanyi @xccc-msft @yungezz Let me know if there is anything need discussion. Sample user-agent for now (2.0.0 is hardcoded, this.getClass().getPackage().getImplementationVersion() does not work in debug).
f5a3179 is regen of resources with context enabled. |
As mentioned, the context for LRO is not solved yet. So only first request to it had context. |
@weidongxu-microsoft what's v1 useragent looks like? how to distinguish them in future? by version or by namespace? |
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.
need to setContext in each service? what's the lowest layer it could be added so upper layer don't need to care about it
} | ||
} | ||
context = context.addData("Sdk-Name", sdkName); | ||
context = context.addData("Sdk-Version", SDK_VERSION); |
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.
I remember there's limitation on lenght of userAgent at different service, such as cosmos. how long is length of our fixed useragent string?
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.
A typical one is such
azsdk-java-com.azure.management.resources/2.0.0 (13.0.1; Windows 10 10.0)
Since user can set ApplicatinId, there is no limit on the length. Though we can truncate that ApplicationId if necessary. @ChenTanyi
https://github.com/Azure/azure-libraries-for-java/blob/vnext/azure-mgmt-resources/src/main/java/com/azure/management/UserAgentPolicy.java#L112-L117
track1 is not much to compare since Azure SDK gives new guideline for it.
https://azure.github.io/azure-sdk/general_azurecore.html#telemetry-policy
For reference track1 Azure-SDK-For-Java/null OS:Windows 10/10.0 MacAddressHash:9e21c3cc3783e949641d36ffd6a2e0c027267de76b62dcc951a57438fbc15f36 Java:13.0.1 (ResourceManagementClient, 2019-08-01)
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.
thanks Weidong for detail info. According to azure core tememetry, shouldn't sdk package name and version set by azure.core?
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.
@tanyi "DO enforce that the application ID is no more than 24 characters in length. " from azure core guideline, again, shouldn't this be done in azure.core/azure.core.mgmt?
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.
@yungezz The azure core has a User-Agent policy, but it could only send constant UA, we have raised an issue and pr about it. But the azure-core team advise us to implement out own. Meanwhile, I think currently all code in com.azure.management
could moved into azure-core-mgmt.
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.
Personally I do not see how azure.core could get sdk package name and sdk version without we setting it to azure.core in the first place. Maybe I misunderstood the question.
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.
so package-name
, pacakge-version
isn't in the constant UA? then that makes a lot of sense. Thanks both to help clarify!
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 are in the UA, but it cannot be changed between request. That
is not we need. We use a restclient for every package. So we need to change UA during request. https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core/src/main/java/com/azure/core/http/policy/UserAgentPolicy.java#L84
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.
I think it is ok except for LRO currently.
In my understanding, Context need to be set to each REST API call. This provides finest grain for user. The challenge is to provide user other levels of control consistently (e.g. global, per service, per cluster of requests e.g. those for doing one task requires a group of resources). Context is used for UserAgent, and Tracing, but it is more than that. Here the code is in parent class of ManagementClient, so this is one shared piece for all REST API. |
Normally SDK could expose a setUserAgent() interface which depends on service(some service exposing setUserAgent(), some not) to append user customized userAgent to system default ones, which includes context from different layers: service, SDK, user customized etc. The PR itself looks good, since it's our general context. |
For context and tracing, I think I am referring to these possible use cases. https://github.com/Azure/azure-sdk-for-java/tree/master/sdk/core/azure-core-tracing-opentelemetry#examples, which is user's own tracing. UserAgent appears to be our tracing (with or without user's knowledge). |
8672b74
to
bf85e7f
Compare
90ea1f1
to
6ebeb19
Compare
Proposed implementation to add context for UserAgentPolicy
Common AzureServiceClient fill common part, OS, Java version.
Client fill mgmt client name.
Method fill api version.