From 033a9036179f170d10f26ae1b65e6d5c131a5698 Mon Sep 17 00:00:00 2001 From: Robert Coltheart Date: Sun, 10 Dec 2023 19:19:57 +1100 Subject: [PATCH] Scope info is not optional --- .../.publicApi/PublicAPI.Unshipped.txt | 2 - .../PrometheusAspNetCoreOptions.cs | 9 --- .../.publicApi/PublicAPI.Unshipped.txt | 2 - .../Internal/PrometheusCollectionManager.cs | 5 +- .../Internal/PrometheusExporter.cs | 3 - .../Internal/PrometheusExporterOptions.cs | 5 -- .../Internal/PrometheusSerializer.cs | 47 ++++++------- .../Internal/PrometheusSerializerExt.cs | 10 +-- ...pListenerMeterProviderBuilderExtensions.cs | 6 +- .../PrometheusHttpListenerOptions.cs | 5 -- .../PrometheusExporterMiddlewareTests.cs | 66 ++++--------------- .../PrometheusHttpListenerTests.cs | 58 ++++------------ .../PrometheusSerializerTests.cs | 8 +-- 13 files changed, 57 insertions(+), 169 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/.publicApi/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/.publicApi/PublicAPI.Unshipped.txt index f904582a47..0dd120b12d 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/.publicApi/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/.publicApi/PublicAPI.Unshipped.txt @@ -2,8 +2,6 @@ Microsoft.AspNetCore.Builder.PrometheusExporterApplicationBuilderExtensions Microsoft.AspNetCore.Builder.PrometheusExporterEndpointRouteBuilderExtensions OpenTelemetry.Exporter.PrometheusAspNetCoreOptions OpenTelemetry.Exporter.PrometheusAspNetCoreOptions.PrometheusAspNetCoreOptions() -> void -OpenTelemetry.Exporter.PrometheusAspNetCoreOptions.ScopeInfoEnabled.get -> bool -OpenTelemetry.Exporter.PrometheusAspNetCoreOptions.ScopeInfoEnabled.set -> void OpenTelemetry.Exporter.PrometheusAspNetCoreOptions.ScrapeEndpointPath.get -> string OpenTelemetry.Exporter.PrometheusAspNetCoreOptions.ScrapeEndpointPath.set -> void OpenTelemetry.Exporter.PrometheusAspNetCoreOptions.ScrapeResponseCacheDurationMilliseconds.get -> int diff --git a/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusAspNetCoreOptions.cs b/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusAspNetCoreOptions.cs index e1ca1636c3..aead3765af 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusAspNetCoreOptions.cs +++ b/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusAspNetCoreOptions.cs @@ -42,14 +42,5 @@ public int ScrapeResponseCacheDurationMilliseconds set => this.ExporterOptions.ScrapeResponseCacheDurationMilliseconds = value; } - /// - /// Gets or sets a value indicating whether to export scope info. Default value: true. - /// - public bool ScopeInfoEnabled - { - get => this.ExporterOptions.ScopeInfoEnabled; - set => this.ExporterOptions.ScopeInfoEnabled = value; - } - internal PrometheusExporterOptions ExporterOptions { get; } = new(); } diff --git a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/.publicApi/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/.publicApi/PublicAPI.Unshipped.txt index 62cb390376..9bc2e72461 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/.publicApi/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/.publicApi/PublicAPI.Unshipped.txt @@ -1,6 +1,4 @@ OpenTelemetry.Exporter.PrometheusHttpListenerOptions -OpenTelemetry.Exporter.PrometheusHttpListenerOptions.ScopeInfoEnabled.get -> bool -OpenTelemetry.Exporter.PrometheusHttpListenerOptions.ScopeInfoEnabled.set -> void OpenTelemetry.Exporter.PrometheusHttpListenerOptions.UriPrefixes.get -> System.Collections.Generic.IReadOnlyCollection OpenTelemetry.Exporter.PrometheusHttpListenerOptions.UriPrefixes.set -> void OpenTelemetry.Exporter.PrometheusHttpListenerOptions.PrometheusHttpListenerOptions() -> void diff --git a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs index 84509e8376..a00b0fd767 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs +++ b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs @@ -185,7 +185,7 @@ private ExportResult OnCollect(Batch metrics) try { - if (this.exporter.ScopeInfoEnabled && this.exporter.OpenMetricsRequested) + if (this.exporter.OpenMetricsRequested) { this.scopes.Clear(); @@ -237,8 +237,7 @@ private ExportResult OnCollect(Batch metrics) cursor, metric, this.GetPrometheusMetric(metric), - this.exporter.OpenMetricsRequested, - this.exporter.ScopeInfoEnabled); + this.exporter.OpenMetricsRequested); break; } diff --git a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusExporter.cs b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusExporter.cs index 2e8de84283..b02a3a64b6 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusExporter.cs +++ b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusExporter.cs @@ -38,7 +38,6 @@ public PrometheusExporter(PrometheusExporterOptions options) Guard.ThrowIfNull(options); this.ScrapeResponseCacheDurationMilliseconds = options.ScrapeResponseCacheDurationMilliseconds; - this.ScopeInfoEnabled = options.ScopeInfoEnabled; this.CollectionManager = new PrometheusCollectionManager(this); } @@ -66,8 +65,6 @@ public PrometheusExporter(PrometheusExporterOptions options) internal bool OpenMetricsRequested { get; set; } - internal bool ScopeInfoEnabled { get; set; } - /// public override ExportResult Export(in Batch metrics) { diff --git a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusExporterOptions.cs b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusExporterOptions.cs index af1e2f6f09..2d9a679124 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusExporterOptions.cs @@ -41,9 +41,4 @@ public int ScrapeResponseCacheDurationMilliseconds this.scrapeResponseCacheDurationMilliseconds = value; } } - - /// - /// Gets or sets a value indicating whether to export scope info. Default value: true. - /// - public bool ScopeInfoEnabled { get; set; } = true; } diff --git a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusSerializer.cs b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusSerializer.cs index e3cee944bf..e664e32edb 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusSerializer.cs +++ b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusSerializer.cs @@ -379,37 +379,32 @@ public static int WriteTimestamp(byte[] buffer, int cursor, long value, bool use } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int WriteTags(byte[] buffer, int cursor, Metric metric, ReadOnlyTagCollection tags, bool scopeInfoEnabled, bool writeEnclosingBraces = true) + public static int WriteTags(byte[] buffer, int cursor, Metric metric, ReadOnlyTagCollection tags, bool writeEnclosingBraces = true) { - if (tags.Count > 0 || scopeInfoEnabled) + if (writeEnclosingBraces) { - if (writeEnclosingBraces) - { - buffer[cursor++] = unchecked((byte)'{'); - } + buffer[cursor++] = unchecked((byte)'{'); + } - if (scopeInfoEnabled) - { - cursor = WriteLabel(buffer, cursor, "otel_scope_name", metric.MeterName); - buffer[cursor++] = unchecked((byte)','); - - if (!string.IsNullOrEmpty(metric.MeterVersion)) - { - cursor = WriteLabel(buffer, cursor, "otel_scope_version", metric.MeterVersion); - buffer[cursor++] = unchecked((byte)','); - } - } + cursor = WriteLabel(buffer, cursor, "otel_scope_name", metric.MeterName); + buffer[cursor++] = unchecked((byte)','); - foreach (var tag in tags) - { - cursor = WriteLabel(buffer, cursor, tag.Key, tag.Value); - buffer[cursor++] = unchecked((byte)','); - } + if (!string.IsNullOrEmpty(metric.MeterVersion)) + { + cursor = WriteLabel(buffer, cursor, "otel_scope_version", metric.MeterVersion); + buffer[cursor++] = unchecked((byte)','); + } - if (writeEnclosingBraces) - { - buffer[cursor - 1] = unchecked((byte)'}'); // Note: We write the '}' over the last written comma, which is extra. - } + foreach (var tag in tags) + { + cursor = WriteLabel(buffer, cursor, tag.Key, tag.Value); + buffer[cursor++] = unchecked((byte)','); + } + + if (writeEnclosingBraces) + { + buffer[cursor - 1] = + unchecked((byte)'}'); // Note: We write the '}' over the last written comma, which is extra. } return cursor; diff --git a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusSerializerExt.cs b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusSerializerExt.cs index 76396fd287..0dce96b335 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusSerializerExt.cs +++ b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusSerializerExt.cs @@ -35,7 +35,7 @@ public static bool CanWriteMetric(Metric metric) return true; } - public static int WriteMetric(byte[] buffer, int cursor, Metric metric, PrometheusMetric prometheusMetric, bool openMetricsRequested = false, bool scopeInfoEnabled = true) + public static int WriteMetric(byte[] buffer, int cursor, Metric metric, PrometheusMetric prometheusMetric, bool openMetricsRequested = false) { cursor = WriteTypeMetadata(buffer, cursor, prometheusMetric); cursor = WriteUnitMetadata(buffer, cursor, prometheusMetric); @@ -49,7 +49,7 @@ public static int WriteMetric(byte[] buffer, int cursor, Metric metric, Promethe // Counter and Gauge cursor = WriteMetricName(buffer, cursor, prometheusMetric); - cursor = WriteTags(buffer, cursor, metric, metricPoint.Tags, scopeInfoEnabled); + cursor = WriteTags(buffer, cursor, metric, metricPoint.Tags); buffer[cursor++] = unchecked((byte)' '); @@ -100,7 +100,7 @@ public static int WriteMetric(byte[] buffer, int cursor, Metric metric, Promethe cursor = WriteMetricName(buffer, cursor, prometheusMetric); cursor = WriteAsciiStringNoEscape(buffer, cursor, "_bucket{"); - cursor = WriteTags(buffer, cursor, metric, tags, scopeInfoEnabled, writeEnclosingBraces: false); + cursor = WriteTags(buffer, cursor, metric, tags, writeEnclosingBraces: false); cursor = WriteAsciiStringNoEscape(buffer, cursor, "le=\""); @@ -126,7 +126,7 @@ public static int WriteMetric(byte[] buffer, int cursor, Metric metric, Promethe // Histogram sum cursor = WriteMetricName(buffer, cursor, prometheusMetric); cursor = WriteAsciiStringNoEscape(buffer, cursor, "_sum"); - cursor = WriteTags(buffer, cursor, metric, metricPoint.Tags, scopeInfoEnabled); + cursor = WriteTags(buffer, cursor, metric, metricPoint.Tags); buffer[cursor++] = unchecked((byte)' '); @@ -140,7 +140,7 @@ public static int WriteMetric(byte[] buffer, int cursor, Metric metric, Promethe // Histogram count cursor = WriteMetricName(buffer, cursor, prometheusMetric); cursor = WriteAsciiStringNoEscape(buffer, cursor, "_count"); - cursor = WriteTags(buffer, cursor, metric, metricPoint.Tags, scopeInfoEnabled); + cursor = WriteTags(buffer, cursor, metric, metricPoint.Tags); buffer[cursor++] = unchecked((byte)' '); diff --git a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListenerMeterProviderBuilderExtensions.cs b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListenerMeterProviderBuilderExtensions.cs index 20b1eabcb9..62c5f386b0 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListenerMeterProviderBuilderExtensions.cs +++ b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListenerMeterProviderBuilderExtensions.cs @@ -78,11 +78,7 @@ public static MeterProviderBuilder AddPrometheusHttpListener(this MeterProviderB private static MetricReader BuildPrometheusHttpListenerMetricReader( PrometheusHttpListenerOptions options) { - var exporter = new PrometheusExporter(new PrometheusExporterOptions - { - ScrapeResponseCacheDurationMilliseconds = 0, - ScopeInfoEnabled = options.ScopeInfoEnabled, - }); + var exporter = new PrometheusExporter(new PrometheusExporterOptions { ScrapeResponseCacheDurationMilliseconds = 0 }); var reader = new BaseExportingMetricReader(exporter) { diff --git a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListenerOptions.cs b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListenerOptions.cs index 7f926f572f..51954fe15d 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListenerOptions.cs +++ b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListenerOptions.cs @@ -30,11 +30,6 @@ public class PrometheusHttpListenerOptions /// public string ScrapeEndpointPath { get; set; } = "/metrics"; - /// - /// Gets or sets a value indicating whether to export scope info. Default value: true. - /// - public bool ScopeInfoEnabled { get; set; } = true; - /// /// Gets or sets the URI (Uniform Resource Identifier) prefixes to use for the http listener. /// Default value: ["http://localhost:9464/"]. diff --git a/test/OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests/PrometheusExporterMiddlewareTests.cs b/test/OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests/PrometheusExporterMiddlewareTests.cs index 956b16079a..6d4098bf94 100644 --- a/test/OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests/PrometheusExporterMiddlewareTests.cs +++ b/test/OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests/PrometheusExporterMiddlewareTests.cs @@ -249,16 +249,6 @@ public Task PrometheusExporterMiddlewareIntegration_TextPlainResponse() acceptHeader: "text/plain"); } - [Fact] - public Task PrometheusExporterMiddlewareIntegration_TextPlainResponse_NoScopeInfo() - { - return RunPrometheusExporterMiddlewareIntegrationTest( - "/metrics", - app => app.UseOpenTelemetryPrometheusScrapingEndpoint(), - acceptHeader: "text/plain", - scopeInfoEnabled: false); - } - [Fact] public Task PrometheusExporterMiddlewareIntegration_UseOpenMetricsVersionHeader() { @@ -268,15 +258,6 @@ public Task PrometheusExporterMiddlewareIntegration_UseOpenMetricsVersionHeader( acceptHeader: "application/openmetrics-text; version=1.0.0"); } - [Fact] - public Task PrometheusExporterMiddlewareIntegration_NoScopeInfo() - { - return RunPrometheusExporterMiddlewareIntegrationTest( - "/metrics", - app => app.UseOpenTelemetryPrometheusScrapingEndpoint(), - scopeInfoEnabled: false); - } - private static async Task RunPrometheusExporterMiddlewareIntegrationTest( string path, Action configure, @@ -285,8 +266,7 @@ public Task PrometheusExporterMiddlewareIntegration_NoScopeInfo() bool registerMeterProvider = true, Action configureOptions = null, bool skipMetrics = false, - string acceptHeader = "application/openmetrics-text", - bool scopeInfoEnabled = true) + string acceptHeader = "application/openmetrics-text") { var requestOpenMetrics = acceptHeader.StartsWith("application/openmetrics-text"); @@ -301,7 +281,6 @@ public Task PrometheusExporterMiddlewareIntegration_NoScopeInfo() .AddMeter(MeterName) .AddPrometheusExporter(o => { - o.ScopeInfoEnabled = scopeInfoEnabled; configureOptions?.Invoke(o); })); } @@ -354,7 +333,17 @@ public Task PrometheusExporterMiddlewareIntegration_NoScopeInfo() } string content = await response.Content.ReadAsStringAsync(); - string expected = GetExpectedContent(requestOpenMetrics, scopeInfoEnabled); + + string expected = requestOpenMetrics + ? "# 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+\\.\\d{{3}})\n" + + "# EOF\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"; var matches = Regex.Matches(content, ("^" + expected + "$").Replace('\'', '"')); @@ -373,36 +362,5 @@ public Task PrometheusExporterMiddlewareIntegration_NoScopeInfo() await host.StopAsync(); } - - private static string GetExpectedContent(bool requestedOpenMetrics, bool scopeInfoEnabled) - { - if (requestedOpenMetrics && scopeInfoEnabled) - { - return "# 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+\\.\\d{{3}})\n" - + "# EOF\n"; - } - - if (!requestedOpenMetrics && scopeInfoEnabled) - { - return "# 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"; - } - - if (requestedOpenMetrics && !scopeInfoEnabled) - { - return "# TYPE counter_double_total counter\n" - + "counter_double_total{key1='value1',key2='value2'} 101.17 (\\d+\\.\\d{3})\n" - + "# EOF\n"; - } - - return "# TYPE counter_double_total counter\n" - + "counter_double_total{key1='value1',key2='value2'} 101.17 (\\d+)\n" - + "# EOF\n"; - } } #endif diff --git a/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusHttpListenerTests.cs b/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusHttpListenerTests.cs index f590c575d6..667d90a93d 100644 --- a/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusHttpListenerTests.cs +++ b/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusHttpListenerTests.cs @@ -98,56 +98,13 @@ public async Task PrometheusExporterHttpServerIntegration_NoOpenMetrics() await this.RunPrometheusExporterHttpServerIntegrationTest(acceptHeader: string.Empty); } - [Fact] - public async Task PrometheusExporterHttpServerIntegration_NoOpenMetrics_NoScopeInfo() - { - await this.RunPrometheusExporterHttpServerIntegrationTest(acceptHeader: string.Empty, scopeInfoEnabled: false); - } - [Fact] public async Task PrometheusExporterHttpServerIntegration_UseOpenMetricsVersionHeader() { await this.RunPrometheusExporterHttpServerIntegrationTest(acceptHeader: "application/openmetrics-text; version=1.0.0"); } - [Fact] - public async Task PrometheusExporterHttpServerIntegration_NoScopeInfo() - { - await this.RunPrometheusExporterHttpServerIntegrationTest(scopeInfoEnabled: false); - } - - private static string GetExpectedContent(bool requestedOpenMetrics, bool scopeInfoEnabled) - { - if (requestedOpenMetrics && scopeInfoEnabled) - { - return "# 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+\\.\\d{{3}})\n" - + "# EOF\n"; - } - - if (!requestedOpenMetrics && scopeInfoEnabled) - { - return "# 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"; - } - - if (requestedOpenMetrics && !scopeInfoEnabled) - { - return "# TYPE counter_double_total counter\n" - + "counter_double_total{key1='value1',key2='value2'} 101.17 (\\d+\\.\\d{3})\n" - + "# EOF\n"; - } - - return "# TYPE counter_double_total counter\n" - + "counter_double_total{key1='value1',key2='value2'} 101.17 (\\d+)\n" - + "# EOF\n"; - } - - private async Task RunPrometheusExporterHttpServerIntegrationTest(bool skipMetrics = false, string acceptHeader = "application/openmetrics-text", bool scopeInfoEnabled = true) + private async Task RunPrometheusExporterHttpServerIntegrationTest(bool skipMetrics = false, string acceptHeader = "application/openmetrics-text") { var requestOpenMetrics = acceptHeader.StartsWith("application/openmetrics-text"); @@ -170,7 +127,6 @@ private async Task RunPrometheusExporterHttpServerIntegrationTest(bool skipMetri .AddMeter(meter.Name) .AddPrometheusHttpListener(options => { - options.ScopeInfoEnabled = scopeInfoEnabled; options.UriPrefixes = new string[] { address }; }) .Build(); @@ -225,7 +181,17 @@ private async Task RunPrometheusExporterHttpServerIntegrationTest(bool skipMetri } var content = await response.Content.ReadAsStringAsync(); - var expected = GetExpectedContent(requestOpenMetrics, scopeInfoEnabled); + + var expected = requestOpenMetrics + ? "# 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+\\.\\d{{3}})\n" + + "# EOF\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"; Assert.Matches(("^" + expected + "$").Replace('\'', '"'), content); } diff --git a/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusSerializerTests.cs b/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusSerializerTests.cs index 9c8f8ecc2d..04b622f98c 100644 --- a/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusSerializerTests.cs +++ b/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusSerializerTests.cs @@ -613,7 +613,7 @@ public void SumWithOpenScopeInfo() counter.Add(10); counter.Add(-11); provider.ForceFlush(); - var cursor = WriteMetric(buffer, 0, metrics[0], true, true); + var cursor = WriteMetric(buffer, 0, metrics[0], true); Assert.Matches( ("^" + "# TYPE test_updown_counter gauge\n" @@ -640,7 +640,7 @@ public void HistogramOneDimensionWithScopeInfo() provider.ForceFlush(); - var cursor = WriteMetric(buffer, 0, metrics[0], true, true); + var cursor = WriteMetric(buffer, 0, metrics[0], true); Assert.Matches( ("^" + "# TYPE test_histogram histogram\n" @@ -666,8 +666,8 @@ public void HistogramOneDimensionWithScopeInfo() Encoding.UTF8.GetString(buffer, 0, cursor)); } - private static int WriteMetric(byte[] buffer, int cursor, Metric metric, bool useOpenMetrics = false, bool scopeInfoEnabled = false) + private static int WriteMetric(byte[] buffer, int cursor, Metric metric, bool useOpenMetrics = false) { - return PrometheusSerializer.WriteMetric(buffer, cursor, metric, PrometheusMetric.Create(metric), useOpenMetrics, scopeInfoEnabled); + return PrometheusSerializer.WriteMetric(buffer, cursor, metric, PrometheusMetric.Create(metric), useOpenMetrics); } }