Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robertcoltheart committed Nov 27, 2023
1 parent 676b700 commit 0203e64
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ public async Task PrometheusExporterMiddlewareIntegration_DisableExportScopeInfo
await RunPrometheusExporterMiddlewareIntegrationTest(
"/metrics",
app => app.UseOpenTelemetryPrometheusScrapingEndpoint(),
configureOptions: o => o.ScopeInfoEnabled = false);
configureOptions: o => o.ScopeInfoEnabled = false,
skipScopeInfo: true);
}

private static async Task RunPrometheusExporterMiddlewareIntegrationTest(
Expand All @@ -254,7 +255,8 @@ public async Task PrometheusExporterMiddlewareIntegration_DisableExportScopeInfo
Action<HttpResponseMessage> validateResponse = null,
bool registerMeterProvider = true,
Action<PrometheusAspNetCoreOptions> configureOptions = null,
bool skipMetrics = false)
bool skipMetrics = false,
bool skipScopeInfo = false)
{
using var host = await new HostBuilder()
.ConfigureWebHost(webBuilder => webBuilder
Expand Down Expand Up @@ -305,14 +307,22 @@ public async Task PrometheusExporterMiddlewareIntegration_DisableExportScopeInfo

string content = await response.Content.ReadAsStringAsync();

string expected = skipScopeInfo
? "# TYPE counter_double_total counter\n"
+ "counter_double_total{key1='value1',key2='value2'} 101.17 (\\d+)\n"
+ "\n"
+ "# EOF\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}',key1='value1',key2='value2'}} 101.17 (\\d+)\n"
+ "\n"
+ "# EOF\n";

var matches = Regex.Matches(
content,
("^"
+ "# TYPE counter_double_total counter\n"
+ "counter_double_total{key1='value1',key2='value2'} 101.17 (\\d+)\n"
+ "\n"
+ "# EOF\n"
+ "$").Replace('\'', '"'));
("^" + expected + "$").Replace('\'', '"'));

Assert.Single(matches);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,18 @@ private async Task RunPrometheusExporterHttpServerIntegrationTest(bool skipMetri
Assert.True(response.Content.Headers.Contains("Last-Modified"));
Assert.Equal("text/plain; charset=utf-8; version=0.0.4", response.Content.Headers.ContentType.ToString());

var content = await response.Content.ReadAsStringAsync();

Assert.Matches(
"^# TYPE counter_double_total counter\ncounter_double_total{key1='value1',key2='value2'} 101.17 \\d+\n\n# EOF\n$".Replace('\'', '"'),
await response.Content.ReadAsStringAsync());
("^"
+ "# TYPE otel_scope_info info\n"
+ "# HELP otel_scope_info Scope metadata\n"
+ $"otel_scope_info{{otel_scope_name='{this.meterName}'}} 1\n"
+ "# TYPE counter_double_total counter\n"
+ $"counter_double_total{{otel_scope_name='{this.meterName}',key1='value1',key2='value2'}} 101.17 \\d+\n\n"
+ "# EOF\n"
+ "$").Replace('\'', '"'),
content);
}
else
{
Expand Down

0 comments on commit 0203e64

Please sign in to comment.