private async Task <PartitionKeyRangeBatchExecutionResult> ExecuteAsync( PartitionKeyRangeServerBatchRequest serverRequest, CancellationToken cancellationToken) { CosmosDiagnosticsContext diagnosticsContext = new CosmosDiagnosticsContext(); CosmosDiagnosticScope limiterScope = diagnosticsContext.CreateScope("BatchAsyncContainerExecutor.Limiter"); SemaphoreSlim limiter = this.GetOrAddLimiterForPartitionKeyRange(serverRequest.PartitionKeyRangeId); using (await limiter.UsingWaitAsync(cancellationToken)) { limiterScope.Dispose(); using (Stream serverRequestPayload = serverRequest.TransferBodyStream()) { Debug.Assert(serverRequestPayload != null, "Server request payload expected to be non-null"); ResponseMessage responseMessage = await this.cosmosClientContext.ProcessResourceOperationStreamAsync( this.cosmosContainer.LinkUri, ResourceType.Document, OperationType.Batch, new RequestOptions(), cosmosContainerCore : this.cosmosContainer, partitionKey : null, streamPayload : serverRequestPayload, requestEnricher : requestMessage => BatchAsyncContainerExecutor.AddHeadersToRequestMessage(requestMessage, serverRequest.PartitionKeyRangeId), diagnosticsScope : diagnosticsContext, cancellationToken : cancellationToken).ConfigureAwait(false); using (diagnosticsContext.CreateScope("BatchAsyncContainerExecutor.ToResponse")) { TransactionalBatchResponse serverResponse = await TransactionalBatchResponse.FromResponseMessageAsync(responseMessage, serverRequest, this.cosmosClientContext.SerializerCore).ConfigureAwait(false); return(new PartitionKeyRangeBatchExecutionResult(serverRequest.PartitionKeyRangeId, serverRequest.Operations, serverResponse)); } } } }
public CosmosDiagnosticsContextCore() { this.StartUtc = DateTime.UtcNow; this.ContextList = new List <CosmosDiagnosticsInternal>(); this.Diagnostics = new CosmosDiagnosticsCore(this); this.overallScope = new CosmosDiagnosticScope("Overall"); }
internal override IDisposable CreateScope(string name) { CosmosDiagnosticScope scope = new CosmosDiagnosticScope(name); this.ContextList.Add(scope); return(scope); }
internal CosmosDiagnosticScope CreateScope(string name) { CosmosDiagnosticScope scope = new CosmosDiagnosticScope(name); this.ContextList.AddDiagnostics(scope); return(scope); }
public CosmosDiagnosticsContextCore( string operationName, string userAgentString) { this.UserAgent = userAgentString ?? throw new ArgumentNullException(nameof(userAgentString)); this.OperationName = operationName ?? throw new ArgumentNullException(nameof(operationName)); this.StartUtc = DateTime.UtcNow; this.ContextList = new BoundedList <CosmosDiagnosticsInternal>(Capacity); this.Diagnostics = new CosmosDiagnosticsCore(this); this.overallScope = new CosmosDiagnosticScope("Overall"); }
internal override CosmosDiagnosticScope CreateOverallScope(string name) { CosmosDiagnosticScope scope; // If overall is already set then let the original set the elapsed time. if (this.isOverallScopeSet) { scope = new CosmosDiagnosticScope(name); } else { scope = new CosmosDiagnosticScope(name, this.SetElapsedTime); this.isOverallScopeSet = true; } this.ContextList.Add(scope); return(scope); }
private static void ValidateScope(CosmosDiagnosticScope scope, TimeSpan?totalElapsedTime) { Assert.IsFalse(string.IsNullOrWhiteSpace(scope.Id)); Assert.IsTrue(scope.TryGetElapsedTime(out TimeSpan elapsedTime)); Assert.IsTrue(elapsedTime > TimeSpan.Zero); if (totalElapsedTime.HasValue) { Assert.IsTrue(elapsedTime <= totalElapsedTime, $"Scope should not have larger time than the entire context. Scope: {elapsedTime} Total: {totalElapsedTime.Value}"); } string info = scope.ToString(); Assert.IsNotNull(info); JObject jObject = JObject.Parse(info.ToString()); Assert.IsNotNull(jObject["Id"].ToString()); string elapsedTimeFromJson = jObject["ElapsedTime"].ToString(); Assert.IsNotNull(elapsedTimeFromJson); TimeSpan.Parse(elapsedTimeFromJson); }
public abstract TResult Visit(CosmosDiagnosticScope cosmosDiagnosticScope);
public abstract void Visit(CosmosDiagnosticScope cosmosDiagnosticScope);
public override void Visit(CosmosDiagnosticScope cosmosDiagnosticScope) { }
public override void Visit(CosmosDiagnosticScope cosmosDiagnosticScope) { this.isScopeVisited = true; ValidateScope(cosmosDiagnosticScope, this.TotalElapsedTime.Value); }
public override void Visit(CosmosDiagnosticScope cosmosDiagnosticScope) { Assert.IsTrue(this.isContextVisited); this.isScopeVisited = true; DiagnosticValidator.ValidateScope(cosmosDiagnosticScope, this.TotalElapsedTime); }