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

vnext, add context to client #1067

Closed
wants to merge 13 commits into from
Closed

Conversation

weidongxu-microsoft
Copy link
Member

Proposed implementation to add context for UserAgentPolicy

Common AzureServiceClient fill common part, OS, Java version.
Client fill mgmt client name.
Method fill api version.

@weidongxu-microsoft
Copy link
Member Author

Let me know your opinion before I start implement the generator.

@weidongxu-microsoft weidongxu-microsoft changed the title vraft, add context to client vnext, draft, add context to client Mar 3, 2020
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()))));
Copy link
Contributor

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).

Copy link
Member Author

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).

Copy link
Contributor

Choose a reason for hiding this comment

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

I've tested for azure-storage-blob, 12.4.0, it use this whole artifactId in user-agent. I'm not sure if all the data-plane teams use it in user-agent.
image

Copy link
Member

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?

Copy link
Member Author

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.

@weidongxu-microsoft
Copy link
Member Author

Intended for #1090

Context in LRO seems not working correctly.

@weidongxu-microsoft weidongxu-microsoft changed the title vnext, draft, add context to client vnext, add context to client Mar 24, 2020
@weidongxu-microsoft weidongxu-microsoft marked this pull request as ready for review March 24, 2020 01:49
if (sdkName == null) {
String packageName = this.getClass().getPackage().getName();
if (packageName.endsWith(".models")) {
sdkName = packageName.substring(0, packageName.length() - ".models".length());
Copy link
Member Author

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

@weidongxu-microsoft
Copy link
Member Author

weidongxu-microsoft commented Mar 25, 2020

@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).

User-Agent:azsdk-java-com.azure.management.resources/2.0.0 (13.0.1; Windows 10 10.0)

f5a3179 is regen of resources with context enabled.

@weidongxu-microsoft
Copy link
Member Author

weidongxu-microsoft commented Mar 25, 2020

As mentioned, the context for LRO is not solved yet. So only first request to it had context.

@yungezz
Copy link
Member

yungezz commented Mar 25, 2020

@weidongxu-microsoft what's v1 useragent looks like? how to distinguish them in future? by version or by namespace?

Copy link
Member

@yungezz yungezz left a 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);
Copy link
Member

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?

Copy link
Member Author

@weidongxu-microsoft weidongxu-microsoft Mar 25, 2020

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)

Copy link
Member

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?

Copy link
Member

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?

Copy link
Contributor

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.

Copy link
Member Author

@weidongxu-microsoft weidongxu-microsoft Mar 30, 2020

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.

Copy link
Member

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!

Copy link
Contributor

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

Copy link
Contributor

@ChenTanyi ChenTanyi left a 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.

@weidongxu-microsoft
Copy link
Member Author

weidongxu-microsoft commented Mar 27, 2020

@yungezz

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.

@yungezz
Copy link
Member

yungezz commented Mar 27, 2020

@yungezz

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.

@weidongxu-microsoft
Copy link
Member Author

weidongxu-microsoft commented Mar 30, 2020

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).

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.

3 participants