From 79fa6507d46e5f6935b9b1e462ff45ad1b979916 Mon Sep 17 00:00:00 2001 From: Matias Quaranta Date: Fri, 26 Feb 2021 16:55:02 -0800 Subject: [PATCH] [Internal] CTL: Fixes retry configuration (#2263) * update * adding log * Enabling retry * range --- .../Tools/CTL/CTLConfig.cs | 3 +-- .../Tools/CTL/Program.cs | 2 ++ .../Scenarios/ChangeFeedProcessorScenario.cs | 23 ++++++++----------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/Microsoft.Azure.Cosmos.Samples/Tools/CTL/CTLConfig.cs b/Microsoft.Azure.Cosmos.Samples/Tools/CTL/CTLConfig.cs index 6b03f4a07e..e2ac890fcf 100644 --- a/Microsoft.Azure.Cosmos.Samples/Tools/CTL/CTLConfig.cs +++ b/Microsoft.Azure.Cosmos.Samples/Tools/CTL/CTLConfig.cs @@ -110,8 +110,7 @@ internal CosmosClient CreateCosmosClient() { CosmosClientOptions clientOptions = new CosmosClientOptions() { - ApplicationName = CTLConfig.UserAgentSuffix, - MaxRetryAttemptsOnRateLimitedRequests = 0 + ApplicationName = CTLConfig.UserAgentSuffix }; if (!string.IsNullOrWhiteSpace(this.ConsistencyLevel)) diff --git a/Microsoft.Azure.Cosmos.Samples/Tools/CTL/Program.cs b/Microsoft.Azure.Cosmos.Samples/Tools/CTL/Program.cs index a3e5e03f96..0373f4d7af 100644 --- a/Microsoft.Azure.Cosmos.Samples/Tools/CTL/Program.cs +++ b/Microsoft.Azure.Cosmos.Samples/Tools/CTL/Program.cs @@ -48,6 +48,8 @@ await scenario.InitializeAsync( cosmosClient: client, logger: logger); + logger.LogInformation("Initialization completed."); + List tasks = new List { scenario.RunAsync( diff --git a/Microsoft.Azure.Cosmos.Samples/Tools/CTL/Scenarios/ChangeFeedProcessorScenario.cs b/Microsoft.Azure.Cosmos.Samples/Tools/CTL/Scenarios/ChangeFeedProcessorScenario.cs index 14d0cd67be..e18f64e521 100644 --- a/Microsoft.Azure.Cosmos.Samples/Tools/CTL/Scenarios/ChangeFeedProcessorScenario.cs +++ b/Microsoft.Azure.Cosmos.Samples/Tools/CTL/Scenarios/ChangeFeedProcessorScenario.cs @@ -7,18 +7,15 @@ namespace CosmosCTL using System; using System.Collections.Concurrent; using System.Collections.Generic; - using System.Diagnostics; using System.Linq; using System.Threading; using System.Threading.Tasks; using App.Metrics; using App.Metrics.Counter; using App.Metrics.Gauge; - using App.Metrics.Timer; using Microsoft.Azure.Cosmos; using Microsoft.Extensions.Logging; using Newtonsoft.Json; - using Newtonsoft.Json.Linq; internal class ChangeFeedProcessorScenario : ICTLScenario { @@ -26,8 +23,6 @@ internal class ChangeFeedProcessorScenario : ICTLScenario private static readonly int DefaultDataFieldSize = 20; private static readonly string DataFieldValue = Convert.ToBase64String(Guid.NewGuid().ToByteArray()).Substring(0, DefaultDataFieldSize); - private readonly Random random = new Random(); - private InitializationResult initializationResult; public async Task InitializeAsync( @@ -65,17 +60,19 @@ public async Task RunAsync( CounterOptions documentCounter = new CounterOptions { Name = "#Documents received", Context = loggingContextIdentifier }; GaugeOptions leaseGauge = new GaugeOptions { Name = "#Leases created", Context = loggingContextIdentifier }; - Container leaseContainer = await cosmosClient.GetDatabase(config.Database).CreateContainerAsync(Guid.NewGuid().ToString(), "/id"); + string leaseContainerId = Guid.NewGuid().ToString(); + Container leaseContainer = await cosmosClient.GetDatabase(config.Database).CreateContainerAsync(leaseContainerId, "/id"); + logger.LogInformation("Created lease container {0}", leaseContainerId); try { ChangeFeedProcessor changeFeedProcessor = cosmosClient.GetContainer(config.Database, config.Collection) - .GetChangeFeedProcessorBuilder("ctlProcessor", + .GetChangeFeedProcessorBuilder("ctlProcessor", (IReadOnlyCollection docs, CancellationToken token) => - { - metrics.Measure.Counter.Increment(documentCounter, docs.Count); - return Task.CompletedTask; - }) + { + metrics.Measure.Counter.Increment(documentCounter, docs.Count); + return Task.CompletedTask; + }) .WithLeaseContainer(leaseContainer) .WithInstanceName(Guid.NewGuid().ToString()) .WithStartTime(DateTime.MinValue.ToUniversalTime()) @@ -100,7 +97,7 @@ public async Task RunAsync( { if (lease.LeaseToken != null) { - logger.LogInformation($"Lease for range {lease.LeaseToken}"); + logger.LogInformation($"Lease for range {lease.LeaseToken} - {lease.FeedRange.EffectiveRange.Min} - {lease.FeedRange.EffectiveRange.Max}"); ranges.Add(lease.FeedRange.EffectiveRange); leaseTotal++; } @@ -108,7 +105,7 @@ public async Task RunAsync( } string previousMin = ""; - foreach(FeedRange sortedRange in ranges.OrderBy(range => range.Min)) + foreach (FeedRange sortedRange in ranges.OrderBy(range => range.Min)) { if (previousMin != sortedRange.Min) {