public void Visit(PointOperationStatisticsTraceDatum pointOperationStatisticsTraceDatum) { this.jsonWriter.WriteObjectStart(); this.jsonWriter.WriteFieldName("Id"); this.jsonWriter.WriteStringValue("PointOperationStatistics"); this.jsonWriter.WriteFieldName("ActivityId"); this.WriteStringValueOrNull(pointOperationStatisticsTraceDatum.ActivityId); this.jsonWriter.WriteFieldName("ResponseTimeUtc"); this.jsonWriter.WriteStringValue(pointOperationStatisticsTraceDatum.ResponseTimeUtc.ToString("o", CultureInfo.InvariantCulture)); this.jsonWriter.WriteFieldName("StatusCode"); this.jsonWriter.WriteNumber64Value((int)pointOperationStatisticsTraceDatum.StatusCode); this.jsonWriter.WriteFieldName("SubStatusCode"); this.jsonWriter.WriteNumber64Value((int)pointOperationStatisticsTraceDatum.SubStatusCode); this.jsonWriter.WriteFieldName("RequestCharge"); this.jsonWriter.WriteNumber64Value(pointOperationStatisticsTraceDatum.RequestCharge); this.jsonWriter.WriteFieldName("RequestUri"); this.WriteStringValueOrNull(pointOperationStatisticsTraceDatum.RequestUri); this.jsonWriter.WriteFieldName("ErrorMessage"); this.WriteStringValueOrNull(pointOperationStatisticsTraceDatum.ErrorMessage); this.jsonWriter.WriteFieldName("RequestSessionToken"); this.WriteStringValueOrNull(pointOperationStatisticsTraceDatum.RequestSessionToken); this.jsonWriter.WriteFieldName("ResponseSessionToken"); this.WriteStringValueOrNull(pointOperationStatisticsTraceDatum.ResponseSessionToken); this.jsonWriter.WriteObjectEnd(); }
public void Visit(PointOperationStatisticsTraceDatum pointOperationStatisticsTraceDatum) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine($"Activity ID: {pointOperationStatisticsTraceDatum.ActivityId}"); stringBuilder.AppendLine($"Status Code: {pointOperationStatisticsTraceDatum.StatusCode}/{pointOperationStatisticsTraceDatum.SubStatusCode}"); stringBuilder.AppendLine($"Response Time: {pointOperationStatisticsTraceDatum.ResponseTimeUtc.ToString("o", CultureInfo.InvariantCulture)}"); stringBuilder.AppendLine($"Request Charge: {pointOperationStatisticsTraceDatum.RequestCharge}"); stringBuilder.AppendLine($"Request URI: {pointOperationStatisticsTraceDatum.RequestUri}"); stringBuilder.AppendLine($"Session Tokens: {pointOperationStatisticsTraceDatum.RequestSessionToken} / {pointOperationStatisticsTraceDatum.ResponseSessionToken}"); if (pointOperationStatisticsTraceDatum.ErrorMessage != null) { stringBuilder.AppendLine($"Error Message: {pointOperationStatisticsTraceDatum.ErrorMessage}"); } this.toStringValue = stringBuilder.ToString(); }
public void TraceData() { List <Input> inputs = new List <Input>(); int startLineNumber; int endLineNumber; //---------------------------------------------------------------- // Point Operation Statistics //---------------------------------------------------------------- { { startLineNumber = GetLineNumber(); TraceForBaselineTesting rootTrace; using (rootTrace = TraceForBaselineTesting.GetRootTrace()) { PointOperationStatisticsTraceDatum datum = new PointOperationStatisticsTraceDatum( activityId: Guid.Empty.ToString(), responseTimeUtc: new DateTime(2020, 1, 2, 3, 4, 5, 6), statusCode: System.Net.HttpStatusCode.OK, subStatusCode: Documents.SubStatusCodes.WriteForbidden, requestCharge: 4, errorMessage: null, method: HttpMethod.Post, requestUri: "http://localhost.com", requestSessionToken: nameof(PointOperationStatisticsTraceDatum.RequestSessionToken), responseSessionToken: nameof(PointOperationStatisticsTraceDatum.ResponseSessionToken), beLatencyInMs: "0.42"); rootTrace.AddDatum("Point Operation Statistics", datum); } endLineNumber = GetLineNumber(); inputs.Add(new Input("Point Operation Statistics", rootTrace, startLineNumber, endLineNumber)); } { startLineNumber = GetLineNumber(); TraceForBaselineTesting rootTrace; using (rootTrace = TraceForBaselineTesting.GetRootTrace()) { PointOperationStatisticsTraceDatum datum = new PointOperationStatisticsTraceDatum( activityId: default,
public void ValidateTransportHandlerLogging() { DocumentClientException dce = new DocumentClientException( "test", null, new StoreResponseNameValueCollection(), HttpStatusCode.Gone, SubStatusCodes.PartitionKeyRangeGone, new Uri("htts://localhost.com")); ITrace trace; RequestMessage requestMessage; using (trace = Cosmos.Tracing.Trace.GetRootTrace("testing")) { requestMessage = new RequestMessage( HttpMethod.Get, "/dbs/test/colls/abc/docs/123", trace); } ResponseMessage response = dce.ToCosmosResponseMessage(requestMessage); Assert.AreEqual(HttpStatusCode.Gone, response.StatusCode); Assert.AreEqual(SubStatusCodes.PartitionKeyRangeGone, response.Headers.SubStatusCode); IEnumerable <PointOperationStatisticsTraceDatum> pointOperationStatistics = trace.Data.Values .Where(traceDatum => traceDatum is PointOperationStatisticsTraceDatum operationStatistics) .Select(x => (PointOperationStatisticsTraceDatum)x); if (pointOperationStatistics.Count() != 1) { Assert.Fail("PointOperationStatistics was not found in the diagnostics."); } PointOperationStatisticsTraceDatum operationStatistics = pointOperationStatistics.First(); Assert.AreEqual(operationStatistics.StatusCode, HttpStatusCode.Gone); Assert.AreEqual(operationStatistics.SubStatusCode, SubStatusCodes.PartitionKeyRangeGone); }
public async Task DiagnosticsAreSetThroughResponseAsync() { List <TransactionalBatchOperationResult> results = new List <TransactionalBatchOperationResult>(); ItemBatchOperation[] arrayOperations = new ItemBatchOperation[1]; ItemBatchOperation operation = new ItemBatchOperation(OperationType.Read, 0, Cosmos.PartitionKey.Null, "0"); results.Add( new TransactionalBatchOperationResult(HttpStatusCode.OK) { ResourceStream = new MemoryStream(new byte[] { 0x41, 0x42 }, index: 0, count: 2, writable: false, publiclyVisible: true), ETag = operation.Id }); arrayOperations[0] = operation; MemoryStream responseContent = await new BatchResponsePayloadWriter(results).GeneratePayloadAsync(); SinglePartitionKeyServerBatchRequest batchRequest = await SinglePartitionKeyServerBatchRequest.CreateAsync( partitionKey : null, operations : new ArraySegment <ItemBatchOperation>(arrayOperations), serializerCore : MockCosmosUtil.Serializer, trace : NoOpTrace.Singleton, cancellationToken : default(CancellationToken)); ResponseMessage responseMessage = new ResponseMessage(HttpStatusCode.OK) { Content = responseContent, }; PointOperationStatisticsTraceDatum diagnostics = new PointOperationStatisticsTraceDatum( activityId: Guid.NewGuid().ToString(), statusCode: HttpStatusCode.OK, subStatusCode: SubStatusCodes.Unknown, responseTimeUtc: DateTime.UtcNow, requestCharge: 0, errorMessage: string.Empty, method: HttpMethod.Get, requestUri: "http://localhost", requestSessionToken: null, responseSessionToken: null); TransactionalBatchResponse batchresponse; using (responseMessage.Trace = Trace.GetRootTrace("test trace")) { responseMessage.Trace.AddDatum("Point Operation Statistics", diagnostics); batchresponse = await TransactionalBatchResponse.FromResponseMessageAsync( responseMessage, batchRequest, MockCosmosUtil.Serializer, true, responseMessage.Trace, CancellationToken.None); } PartitionKeyRangeBatchResponse response = new PartitionKeyRangeBatchResponse(arrayOperations.Length, batchresponse, MockCosmosUtil.Serializer); if (!(response.Diagnostics is CosmosTraceDiagnostics cosmosTraceDiagnostics)) { Assert.Fail(); throw new Exception(); } Assert.AreEqual(diagnostics, cosmosTraceDiagnostics.Value.Data.Values.First()); }
public void Visit(PointOperationStatisticsTraceDatum pointOperationStatisticsTraceDatum) { Debug.Fail("QueryStatisticsDatumVisitor Assert", "PointOperationStatisticsTraceDatum is not supported"); }
public void TraceData() { List <Input> inputs = new List <Input>(); int startLineNumber; int endLineNumber; //---------------------------------------------------------------- // Point Operation Statistics //---------------------------------------------------------------- { startLineNumber = GetLineNumber(); TraceForBaselineTesting rootTrace; using (rootTrace = TraceForBaselineTesting.GetRootTrace()) { PointOperationStatisticsTraceDatum datum = new PointOperationStatisticsTraceDatum( activityId: Guid.Empty.ToString(), responseTimeUtc: new DateTime(2020, 1, 2, 3, 4, 5, 6), statusCode: System.Net.HttpStatusCode.OK, subStatusCode: Documents.SubStatusCodes.WriteForbidden, requestCharge: 4, errorMessage: null, method: HttpMethod.Post, requestUri: "http://localhost.com", requestSessionToken: nameof(PointOperationStatisticsTraceDatum.RequestSessionToken), responseSessionToken: nameof(PointOperationStatisticsTraceDatum.ResponseSessionToken)); rootTrace.AddDatum("Point Operation Statistics", datum); } endLineNumber = GetLineNumber(); inputs.Add(new Input("Point Operation Statistics", rootTrace, startLineNumber, endLineNumber)); } //---------------------------------------------------------------- //---------------------------------------------------------------- // Query Metrics //---------------------------------------------------------------- { startLineNumber = GetLineNumber(); TraceForBaselineTesting rootTrace; using (rootTrace = TraceForBaselineTesting.GetRootTrace()) { QueryMetricsTraceDatum datum = new QueryMetricsTraceDatum( new QueryMetrics( BackendMetricsTests.MockBackendMetrics, IndexUtilizationInfoTests.MockIndexUtilizationInfo, ClientSideMetricsTests.MockClientSideMetrics)); rootTrace.AddDatum("Query Metrics", datum); } endLineNumber = GetLineNumber(); inputs.Add(new Input("Query Metrics", rootTrace, startLineNumber, endLineNumber)); } //---------------------------------------------------------------- //---------------------------------------------------------------- // Client Side Request Stats //---------------------------------------------------------------- { startLineNumber = GetLineNumber(); TraceForBaselineTesting rootTrace; using (rootTrace = TraceForBaselineTesting.GetRootTrace()) { ClientSideRequestStatisticsTraceDatum datum = new ClientSideRequestStatisticsTraceDatum(DateTime.MinValue); Uri uri1 = new Uri("http://someUri1.com"); Uri uri2 = new Uri("http://someUri2.com"); datum.ContactedReplicas.Add(uri1); datum.ContactedReplicas.Add(uri2); ClientSideRequestStatisticsTraceDatum.AddressResolutionStatistics mockStatistics = new ClientSideRequestStatisticsTraceDatum.AddressResolutionStatistics( DateTime.MinValue, DateTime.MaxValue, "http://localhost.com"); datum.EndpointToAddressResolutionStatistics["asdf"] = mockStatistics; datum.EndpointToAddressResolutionStatistics["asdf2"] = mockStatistics; datum.FailedReplicas.Add(uri1); datum.FailedReplicas.Add(uri2); datum.RegionsContacted.Add(uri1); datum.RegionsContacted.Add(uri2); datum.RequestEndTimeUtc = DateTime.MaxValue; StoreResponseStatistics storeResponseStatistics = new StoreResponseStatistics( DateTime.MinValue, DateTime.MaxValue, new Documents.StoreResult( storeResponse: new StoreResponse(), exception: null, partitionKeyRangeId: 42.ToString(), lsn: 1337, quorumAckedLsn: 23, requestCharge: 3.14, currentReplicaSetSize: 4, currentWriteQuorum: 3, isValid: true, storePhysicalAddress: new Uri("http://storephysicaladdress.com"), globalCommittedLSN: 1234, numberOfReadRegions: 13, itemLSN: 15, sessionToken: new SimpleSessionToken(42), usingLocalLSN: true, activityId: Guid.Empty.ToString()), ResourceType.Document, OperationType.Query, uri1); datum.StoreResponseStatisticsList.Add(storeResponseStatistics); rootTrace.AddDatum("Client Side Request Stats", datum); } endLineNumber = GetLineNumber(); inputs.Add(new Input("Client Side Request Stats", rootTrace, startLineNumber, endLineNumber)); } //---------------------------------------------------------------- //---------------------------------------------------------------- // CPU History //---------------------------------------------------------------- { startLineNumber = GetLineNumber(); TraceForBaselineTesting rootTrace; using (rootTrace = TraceForBaselineTesting.GetRootTrace()) { CpuHistoryTraceDatum datum = new CpuHistoryTraceDatum( new Documents.Rntbd.CpuLoadHistory( new ReadOnlyCollection <Documents.Rntbd.CpuLoad>( new List <Documents.Rntbd.CpuLoad>() { new Documents.Rntbd.CpuLoad(DateTime.MinValue, 42), new Documents.Rntbd.CpuLoad(DateTime.MinValue, 23), }), monitoringInterval: TimeSpan.MaxValue)); rootTrace.AddDatum("CPU History", datum); } endLineNumber = GetLineNumber(); inputs.Add(new Input("CPU History", rootTrace, startLineNumber, endLineNumber)); } //---------------------------------------------------------------- this.ExecuteTestSuite(inputs); }