-
Notifications
You must be signed in to change notification settings - Fork 533
Expand file tree
/
Copy pathClientConfigurationTraceDatum.cs
More file actions
137 lines (109 loc) · 6.19 KB
/
ClientConfigurationTraceDatum.cs
File metadata and controls
137 lines (109 loc) · 6.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// ------------------------------------------------------------
namespace Microsoft.Azure.Cosmos.Tracing.TraceData
{
using System;
using System.Globalization;
using Microsoft.Azure.Cosmos.Json;
using Microsoft.Azure.Cosmos.Telemetry;
using System.Text.Json;
using System.Buffers;
internal sealed class ClientConfigurationTraceDatum : TraceDatum
{
public ClientConfigurationTraceDatum(CosmosClientContext cosmosClientContext, DateTime startTime)
{
this.ClientCreatedDateTimeUtc = startTime;
this.UserAgentContainer = cosmosClientContext.DocumentClient.ConnectionPolicy.UserAgentContainer;
this.GatewayConnectionConfig = new GatewayConnectionConfig(cosmosClientContext.ClientOptions.GatewayModeMaxConnectionLimit,
cosmosClientContext.ClientOptions.RequestTimeout,
cosmosClientContext.ClientOptions.WebProxy,
cosmosClientContext.ClientOptions.HttpClientFactory);
#if !COSMOS_GW_AOT
this.RntbdConnectionConfig = cosmosClientContext.DocumentClient.RecordTcpSettings(this);
#endif
this.OtherConnectionConfig = new OtherConnectionConfig(cosmosClientContext.ClientOptions.LimitToEndpoint,
cosmosClientContext.ClientOptions.AllowBulkExecution);
this.ConsistencyConfig = new ConsistencyConfig(cosmosClientContext.ClientOptions.ConsistencyLevel,
cosmosClientContext.ClientOptions.ApplicationPreferredRegions, cosmosClientContext.ClientOptions.ApplicationRegion);
this.cachedNumberOfClientCreated = CosmosClient.numberOfClientsCreated;
this.cachedNumberOfActiveClient = CosmosClient.NumberOfActiveClients;
this.cachedUserAgentString = this.UserAgentContainer.UserAgent;
this.cachedMachineId = VmMetadataApiHandler.GetMachineId();
this.ProcessorCount = Environment.ProcessorCount;
this.ConnectionMode = cosmosClientContext.ClientOptions.ConnectionMode;
this.cachedVMRegion = VmMetadataApiHandler.GetMachineRegion();
this.cachedSerializedJson = this.GetSerializedDatum();
}
public DateTime ClientCreatedDateTimeUtc { get; }
public GatewayConnectionConfig GatewayConnectionConfig { get; }
#if !COSMOS_GW_AOT
public RntbdConnectionConfig RntbdConnectionConfig { get; }
#endif
public OtherConnectionConfig OtherConnectionConfig { get; }
public ConsistencyConfig ConsistencyConfig { get; }
public int ProcessorCount { get; }
public ConnectionMode ConnectionMode { get; }
public ReadOnlyMemory<byte> SerializedJson
{
get
{
if (this.cachedUserAgentString != this.UserAgentContainer.UserAgent ||
this.cachedNumberOfClientCreated != CosmosClient.numberOfClientsCreated ||
this.cachedNumberOfActiveClient != CosmosClient.NumberOfActiveClients ||
!ReferenceEquals(this.cachedMachineId, VmMetadataApiHandler.GetMachineId()) ||
!ReferenceEquals(this.cachedVMRegion, VmMetadataApiHandler.GetMachineRegion()))
{
this.cachedNumberOfActiveClient = CosmosClient.NumberOfActiveClients;
this.cachedNumberOfClientCreated = CosmosClient.numberOfClientsCreated;
this.cachedUserAgentString = this.UserAgentContainer.UserAgent;
this.cachedMachineId = VmMetadataApiHandler.GetMachineId();
this.cachedVMRegion = VmMetadataApiHandler.GetMachineRegion();
this.cachedSerializedJson = this.GetSerializedDatum();
}
return this.cachedSerializedJson;
}
}
internal readonly UserAgentContainer UserAgentContainer;
private ReadOnlyMemory<byte> cachedSerializedJson;
private int cachedNumberOfClientCreated;
private int cachedNumberOfActiveClient;
private string cachedUserAgentString;
private string cachedMachineId;
private string cachedVMRegion;
internal override void Accept(ITraceDatumVisitor traceDatumVisitor)
{
traceDatumVisitor.Visit(this);
}
private ReadOnlyMemory<byte> GetSerializedDatum()
{
var buffer = new ArrayBufferWriter<byte>();
using (var writer = new Utf8JsonWriter(buffer))
{
writer.WriteStartObject();
writer.WriteString("Client Created Time Utc", this.ClientCreatedDateTimeUtc.ToString("o", CultureInfo.InvariantCulture));
writer.WriteString("MachineId", this.cachedMachineId);
if (this.cachedVMRegion != null)
{
writer.WriteString("VM Region", this.cachedVMRegion);
}
writer.WriteNumber("NumberOfClientsCreated", this.cachedNumberOfClientCreated);
writer.WriteNumber("NumberOfActiveClients", this.cachedNumberOfActiveClient);
writer.WriteString("ConnectionMode", this.ConnectionMode.ToString());
writer.WriteString("User Agent", this.cachedUserAgentString);
writer.WritePropertyName("ConnectionConfig");
writer.WriteStartObject();
writer.WriteString("gw", this.GatewayConnectionConfig.ToString());
#if !COSMOS_GW_AOT
writer.WriteString("rntbd", this.RntbdConnectionConfig.ToString());
#endif
writer.WriteString("other", this.OtherConnectionConfig.ToString());
writer.WriteEndObject();
writer.WriteString("ConsistencyConfig", this.ConsistencyConfig.ToString());
writer.WriteNumber("ProcessorCount", this.ProcessorCount);
writer.WriteEndObject();
}
return buffer.WrittenMemory;
}
}
}