Skip to content

Commit

Permalink
Adding configurable flush interval.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Lipin committed Jun 19, 2023
1 parent 270aece commit 33a2597
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public class BenchmarkConfig
public string ResultsContainer { get; set; } = "runsummary";

[Option(Required = false, HelpText = "Metrics reporting interval in seconds")]
public int MetricsReportingIntervalInSec { get; set; }
public int MetricsReportingIntervalInSec { get; set; } = 5;

[Option(Required = false, HelpText = "Application Insights instrumentation key")]
public string AppInsightsInstrumentationKey { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,43 @@ internal static class MetricsCollectorProvider

private static readonly Meter readOperationMeter = new ("CosmosBenchmarkReadOperationMeter");

private static MetricCollectionWindow GetCurrentMetricCollectionWindow(MeterProvider meterProvider)
private static MetricCollectionWindow GetCurrentMetricCollectionWindow(MeterProvider meterProvider, BenchmarkConfig config)
{
if (CheckMetricCollectionInvalid(metricCollectionWindow))
if (CheckMetricCollectionInvalid(metricCollectionWindow, config))
{
lock (metricCollectionWindowLock)
{
if (CheckMetricCollectionInvalid(metricCollectionWindow))
if (CheckMetricCollectionInvalid(metricCollectionWindow, config))
{
// Reset Meter provider and meters.
metricCollectionWindow = new MetricCollectionWindow();
meterProvider.ForceFlush();
}
}
}

return metricCollectionWindow;
}

private static bool CheckMetricCollectionInvalid(MetricCollectionWindow metricCollectionWindow)
private static bool CheckMetricCollectionInvalid(MetricCollectionWindow metricCollectionWindow, BenchmarkConfig config)
{
return metricCollectionWindow is null || DateTime.Now > metricCollectionWindow.DateTimeCreated.AddSeconds(5);
return metricCollectionWindow is null || DateTime.Now > metricCollectionWindow.DateTimeCreated.AddSeconds(config.MetricsReportingIntervalInSec);
}

public static IMetricsCollector GetMetricsCollector(IBenchmarkOperation benchmarkOperation, MeterProvider meterProvider)
public static IMetricsCollector GetMetricsCollector(IBenchmarkOperation benchmarkOperation, MeterProvider meterProvider, BenchmarkConfig config)
{
Type benchmarkOperationType = benchmarkOperation.GetType();
if (typeof(InsertBenchmarkOperation).IsAssignableFrom(benchmarkOperationType))
{
return GetCurrentMetricCollectionWindow(meterProvider).GetInsertOperationMetricsCollector(insertOperationMeter);
return GetCurrentMetricCollectionWindow(meterProvider, config).GetInsertOperationMetricsCollector(insertOperationMeter);
}
else if (typeof(QueryBenchmarkOperation).IsAssignableFrom(benchmarkOperationType))
{
return GetCurrentMetricCollectionWindow(meterProvider).GetQueryOperationMetricsCollector(queryOperationMeter);
return GetCurrentMetricCollectionWindow(meterProvider, config).GetQueryOperationMetricsCollector(queryOperationMeter);
}
else if (typeof(ReadBenchmarkOperation).IsAssignableFrom(benchmarkOperationType))
{
return GetCurrentMetricCollectionWindow(meterProvider).GetReadOperationMetricsCollector(readOperationMeter);
return GetCurrentMetricCollectionWindow(meterProvider, config).GetReadOperationMetricsCollector(readOperationMeter);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public async Task ExecuteAsync(
int currentIterationCount = 0;
do
{
IMetricsCollector metricsCollector = MetricsCollectorProvider.GetMetricsCollector(this.operation, meterProvider);
IMetricsCollector metricsCollector = MetricsCollectorProvider.GetMetricsCollector(this.operation, meterProvider, benchmarkConfig);

OperationResult? operationResult = null;

Expand Down

0 comments on commit 33a2597

Please sign in to comment.