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

UserAgent: Removes direct version #3173

Merged
merged 4 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions Microsoft.Azure.Cosmos/src/EnvironmentInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace Microsoft.Azure.Cosmos
internal sealed class EnvironmentInformation
{
private static readonly string clientSDKVersion;
private static readonly string directPackageVersion;
private static readonly string framework;
private static readonly string architecture;
private static readonly string os;
Expand All @@ -19,8 +18,6 @@ static EnvironmentInformation()
{
Version sdkVersion = Assembly.GetAssembly(typeof(CosmosClient)).GetName().Version;
EnvironmentInformation.clientSDKVersion = $"{sdkVersion.Major}.{sdkVersion.Minor}.{sdkVersion.Build}";
Version directVersion = Assembly.GetAssembly(typeof(Documents.UserAgentContainer)).GetName().Version;
EnvironmentInformation.directPackageVersion = $"{directVersion.Major}.{directVersion.Minor}.{directVersion.Build}";
EnvironmentInformation.framework = RuntimeInformation.FrameworkDescription;
EnvironmentInformation.architecture = RuntimeInformation.ProcessArchitecture.ToString();
EnvironmentInformation.os = RuntimeInformation.OSDescription;
Expand All @@ -30,11 +27,6 @@ public EnvironmentInformation()
{
}

/// <summary>
/// Version of the current direct package.
/// </summary>
public string DirectVersion => EnvironmentInformation.directPackageVersion;

/// <summary>
/// Version of the current client.
/// </summary>
Expand Down
5 changes: 1 addition & 4 deletions Microsoft.Azure.Cosmos/src/UserAgentContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ public UserAgentContainer(

protected virtual void GetEnvironmentInformation(
out string clientVersion,
out string directVersion,
out string processArchitecture,
out string operatingSystem,
out string runtimeFramework)
{
EnvironmentInformation environmentInformation = new EnvironmentInformation();
clientVersion = environmentInformation.ClientVersion;
directVersion = environmentInformation.DirectVersion;
processArchitecture = environmentInformation.ProcessArchitecture;
operatingSystem = environmentInformation.OperatingSystem;
runtimeFramework = environmentInformation.RuntimeFramework;
Expand All @@ -52,7 +50,6 @@ private string CreateBaseUserAgentString(
{
this.GetEnvironmentInformation(
out string clientVersion,
out string directVersion,
out string processArchitecture,
out string operatingSystem,
out string runtimeFramework);
Expand All @@ -68,7 +65,7 @@ private string CreateBaseUserAgentString(
#if PREVIEW
previewFlag = "P";
#endif
string baseUserAgent = $"cosmos-netstandard-sdk/{clientVersion}" + previewFlag + Regex.Replace($"|{directVersion}|{this.clientId}|{processArchitecture}|{operatingSystem}|{runtimeFramework}|", @"[^0-9a-zA-Z\.\|\-]+", " ");
string baseUserAgent = $"cosmos-netstandard-sdk/{clientVersion}" + previewFlag + Regex.Replace($"|{this.clientId}|{processArchitecture}|{operatingSystem}|{runtimeFramework}|", @"[^0-9a-zA-Z\.\|\-]+", " ");
if (!string.IsNullOrEmpty(regionConfiguration))
{
baseUserAgent += $"{regionConfiguration}|";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,10 @@ public void VerifyUserAgentContent()
previewFlag = "P";
#endif
Assert.AreEqual($"cosmos-netstandard-sdk/{envInfo.ClientVersion}" + previewFlag, values[0]);
Assert.AreEqual(envInfo.DirectVersion, values[1]);
Assert.AreEqual("0", values[2]);
Assert.AreEqual(envInfo.ProcessArchitecture, values[3]);
Assert.AreEqual(envInfo.OperatingSystem, values[4]);
Assert.AreEqual(envInfo.RuntimeFramework, values[5]);
Assert.AreEqual("0", values[1]);
Assert.AreEqual(envInfo.ProcessArchitecture, values[2]);
Assert.AreEqual(envInfo.OperatingSystem, values[3]);
Assert.AreEqual(envInfo.RuntimeFramework, values[4]);
}

[TestMethod]
Expand Down Expand Up @@ -193,11 +192,11 @@ public void VerifyClientIDForUserAgentString()
string userAgentString = client.DocumentClient.ConnectionPolicy.UserAgentContainer.UserAgent;
if (i <= max)
{
Assert.AreEqual(userAgentString.Split('|')[2], i.ToString());
Assert.AreEqual(userAgentString.Split('|')[1], i.ToString());
}
else
{
Assert.AreEqual(userAgentString.Split('|')[2], max.ToString());
Assert.AreEqual(userAgentString.Split('|')[1], max.ToString());
}
}
}
Expand All @@ -222,7 +221,7 @@ public async Task VerifyClientIDIncrements_Concurrent()

await Task.WhenAll(tasks);
List<int> actual = tasks.Select(r =>
int.Parse(r.Result.DocumentClient.ConnectionPolicy.UserAgentContainer.UserAgent.Split('|')[2])).ToList();
int.Parse(r.Result.DocumentClient.ConnectionPolicy.UserAgentContainer.UserAgent.Split('|')[1])).ToList();
actual.Sort();
CollectionAssert.AreEqual(expected, actual);
}
Expand Down Expand Up @@ -377,7 +376,6 @@ public MacOsUserAgentContainer(int clientId,

protected override void GetEnvironmentInformation(
out string clientVersion,
out string directVersion,
out string processArchitecture,
out string operatingSystem,
out string runtimeFramework)
Expand All @@ -387,7 +385,6 @@ protected override void GetEnvironmentInformation(

base.GetEnvironmentInformation(
clientVersion: out clientVersion,
directVersion: out directVersion,
processArchitecture: out processArchitecture,
operatingSystem: out _,
runtimeFramework: out runtimeFramework);
Expand All @@ -408,7 +405,7 @@ private string GetClientIdFromCosmosClient(CosmosClient client)
{
Cosmos.UserAgentContainer userAgentContainer = client.ClientOptions.GetConnectionPolicy(client.ClientId).UserAgentContainer;
string userAgentString = userAgentContainer.UserAgent;
string clientId = userAgentString.Split('|')[2];
string clientId = userAgentString.Split('|')[1];
return clientId;
}
}
Expand Down