Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robertcoltheart committed Dec 10, 2023
1 parent 89f735d commit 50a9bde
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,38 +172,35 @@ private ExportResult OnCollect(Batch<Metric> metrics)

try
{
if (this.exporter.OpenMetricsRequested)
{
this.scopes.Clear();
this.scopes.Clear();

foreach (var metric in metrics)
foreach (var metric in metrics)
{
if (PrometheusSerializer.CanWriteMetric(metric))
{
if (PrometheusSerializer.CanWriteMetric(metric))
{
this.scopes.Add(metric.MeterName);
}
this.scopes.Add(metric.MeterName);
}
}

foreach (var scope in this.scopes)
foreach (var scope in this.scopes)
{
try
{
try
{
cursor = PrometheusSerializer.WriteScopeInfo(this.buffer, cursor, scope);
cursor = PrometheusSerializer.WriteScopeInfo(this.buffer, cursor, scope);

break;
}
catch (IndexOutOfRangeException)
break;
}
catch (IndexOutOfRangeException)
{
if (!this.IncreaseBufferSize())
{
if (!this.IncreaseBufferSize())
{
// there are two cases we might run into the following condition:
// 1. we have many metrics to be exported - in this case we probably want
// to put some upper limit and allow the user to configure it.
// 2. we got an IndexOutOfRangeException which was triggered by some other
// code instead of the buffer[cursor++] - in this case we should give up
// at certain point rather than allocating like crazy.
throw;
}
// there are two cases we might run into the following condition:
// 1. we have many metrics to be exported - in this case we probably want
// to put some upper limit and allow the user to configure it.
// 2. we got an IndexOutOfRangeException which was triggered by some other
// code instead of the buffer[cursor++] - in this case we should give up
// at certain point rather than allocating like crazy.
throw;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,10 @@ private static async Task RunPrometheusExporterMiddlewareIntegrationTest(
+ "# TYPE counter_double_total counter\n"
+ $"counter_double_total{{otel_scope_name='{MeterName}',otel_scope_version='{MeterVersion}',key1='value1',key2='value2'}} 101.17 (\\d+\\.\\d{{3}})\n"
+ "# EOF\n"
: "# TYPE counter_double_total counter\n"
: "# TYPE otel_scope_info info\n"
+ "# HELP otel_scope_info Scope metadata\n"
+ $"otel_scope_info{{otel_scope_name='{MeterName}'}} 1\n"
+ "# TYPE counter_double_total counter\n"
+ $"counter_double_total{{otel_scope_name='{MeterName}',otel_scope_version='{MeterVersion}',key1='value1',key2='value2'}} 101.17 (\\d+)\n"
+ "# EOF\n";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ private async Task RunPrometheusExporterHttpServerIntegrationTest(bool skipMetri
+ "# TYPE counter_double_total counter\n"
+ $"counter_double_total{{otel_scope_name='{MeterName}',otel_scope_version='{MeterVersion}',key1='value1',key2='value2'}} 101.17 (\\d+\\.\\d{{3}})\n"
+ "# EOF\n"
: "# TYPE counter_double_total counter\n"
: "# TYPE otel_scope_info info\n"
+ "# HELP otel_scope_info Scope metadata\n"
+ $"otel_scope_info{{otel_scope_name='{MeterName}'}} 1\n"
+ "# TYPE counter_double_total counter\n"
+ $"counter_double_total{{otel_scope_name='{MeterName}',otel_scope_version='{MeterVersion}',key1='value1',key2='value2'}} 101.17 (\\d+)\n"
+ "# EOF\n";

Expand Down
Loading

0 comments on commit 50a9bde

Please sign in to comment.