Skip to content

Commit

Permalink
[Internal] CTL: Fixes retry configuration (#2263)
Browse files Browse the repository at this point in the history
* update

* adding log

* Enabling retry

* range
  • Loading branch information
ealsur committed Feb 27, 2021
1 parent 5420653 commit 79fa650
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
3 changes: 1 addition & 2 deletions Microsoft.Azure.Cosmos.Samples/Tools/CTL/CTLConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ internal CosmosClient CreateCosmosClient()
{
CosmosClientOptions clientOptions = new CosmosClientOptions()
{
ApplicationName = CTLConfig.UserAgentSuffix,
MaxRetryAttemptsOnRateLimitedRequests = 0
ApplicationName = CTLConfig.UserAgentSuffix
};

if (!string.IsNullOrWhiteSpace(this.ConsistencyLevel))
Expand Down
2 changes: 2 additions & 0 deletions Microsoft.Azure.Cosmos.Samples/Tools/CTL/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ await scenario.InitializeAsync(
cosmosClient: client,
logger: logger);

logger.LogInformation("Initialization completed.");

List<Task> tasks = new List<Task>
{
scenario.RunAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,22 @@ 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
{
private static readonly int DefaultDocumentFieldCount = 5;
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(
Expand Down Expand Up @@ -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<SimpleItem>("ctlProcessor",
.GetChangeFeedProcessorBuilder<SimpleItem>("ctlProcessor",
(IReadOnlyCollection<SimpleItem> 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())
Expand All @@ -100,15 +97,15 @@ 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++;
}
}
}

string previousMin = "";
foreach(FeedRange sortedRange in ranges.OrderBy(range => range.Min))
foreach (FeedRange sortedRange in ranges.OrderBy(range => range.Min))
{
if (previousMin != sortedRange.Min)
{
Expand Down

0 comments on commit 79fa650

Please sign in to comment.