-
Notifications
You must be signed in to change notification settings - Fork 493
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enrich user-agent with runtime context (#630)
* Adding EnvironmentInformation * Wiring in UserAgentContainer * Tests * More tests and clientid * Using valid separators * Addressing comments * ChangeLog * Using Build * Changed changelog * Delimiter
- Loading branch information
1 parent
50d944c
commit 304e185
Showing
5 changed files
with
140 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
//------------------------------------------------------------ | ||
namespace Microsoft.Azure.Cosmos | ||
{ | ||
using System; | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
|
||
internal sealed class EnvironmentInformation | ||
{ | ||
internal const string Delimiter = " "; | ||
private static readonly string clientId; | ||
private static readonly string clientSDKVersion; | ||
private static readonly string framework; | ||
private static readonly string architecture; | ||
|
||
static EnvironmentInformation() | ||
{ | ||
Version sdkVersion = Assembly.GetAssembly(typeof(CosmosClient)).GetName().Version; | ||
EnvironmentInformation.clientSDKVersion = $"{sdkVersion.Major}.{sdkVersion.Minor}.{sdkVersion.Build}"; | ||
EnvironmentInformation.framework = RuntimeInformation.FrameworkDescription; | ||
EnvironmentInformation.architecture = RuntimeInformation.ProcessArchitecture.ToString(); | ||
EnvironmentInformation.clientId = DateTime.UtcNow.Ticks.ToString(); | ||
} | ||
|
||
/// <summary> | ||
/// Unique identifier of a client | ||
/// </summary> | ||
public string ClientId => EnvironmentInformation.clientId; | ||
|
||
/// <summary> | ||
/// Version of the current client. | ||
/// </summary> | ||
public string ClientVersion => EnvironmentInformation.clientSDKVersion; | ||
|
||
/// <summary> | ||
/// Identifier of the Framework. | ||
/// </summary> | ||
/// <seealso cref="RuntimeInformation.FrameworkDescription"/> | ||
public string RuntimeFramework => EnvironmentInformation.framework; | ||
|
||
/// <summary> | ||
/// Type of architecture being used. | ||
/// </summary> | ||
/// <seealso cref="RuntimeInformation.ProcessArchitecture"/> | ||
public string ProcessArchitecture => EnvironmentInformation.architecture; | ||
|
||
public override string ToString() | ||
{ | ||
return $" {this.ClientVersion}-{this.RuntimeFramework} {this.ProcessArchitecture} {this.ClientId}"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/EnvironmentInformationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
//------------------------------------------------------------ | ||
|
||
namespace Microsoft.Azure.Cosmos.Tests | ||
{ | ||
using System; | ||
using System.Reflection; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
[TestClass] | ||
public class EnvironmentInformationTests | ||
{ | ||
[TestMethod] | ||
public void ClientVersionIsNotNull() | ||
{ | ||
var envInfo = new EnvironmentInformation(); | ||
Assert.IsNotNull(envInfo.ClientVersion); | ||
|
||
Version sdkVersion = Assembly.GetAssembly(typeof(CosmosClient)).GetName().Version; | ||
Assert.AreEqual($"{sdkVersion.Major}.{sdkVersion.Minor}.{sdkVersion.Build}", envInfo.ClientVersion, "Version format differs"); | ||
} | ||
|
||
[TestMethod] | ||
public void ProcessArchitectureIsNotNull() | ||
{ | ||
var envInfo = new EnvironmentInformation(); | ||
Assert.IsNotNull(envInfo.ProcessArchitecture); | ||
} | ||
|
||
[TestMethod] | ||
public void FrameworkIsNotNull() | ||
{ | ||
var envInfo = new EnvironmentInformation(); | ||
Assert.IsNotNull(envInfo.RuntimeFramework); | ||
} | ||
|
||
[TestMethod] | ||
public void ClientIdIsNotNull() | ||
{ | ||
var envInfo = new EnvironmentInformation(); | ||
Assert.IsNotNull(envInfo.ClientId); | ||
} | ||
|
||
[TestMethod] | ||
public void ToStringContainsAll() | ||
{ | ||
var envInfo = new EnvironmentInformation(); | ||
var serialization = envInfo.ToString(); | ||
Assert.IsTrue(serialization.Contains(envInfo.ClientVersion)); | ||
Assert.IsTrue(serialization.Contains(envInfo.ProcessArchitecture)); | ||
Assert.IsTrue(serialization.Contains(envInfo.RuntimeFramework)); | ||
Assert.IsTrue(serialization.Contains(envInfo.ClientId)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters