From 8e349c1cf4ad5f560a809710d38199dc7a251c8c Mon Sep 17 00:00:00 2001 From: dszmigielski Date: Fri, 9 Sep 2022 10:39:53 +0200 Subject: [PATCH 1/3] Change StatusCode to 200 when no metrics are collected --- .../PrometheusExporterMiddleware.cs | 2 +- .../PrometheusHttpListener.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusExporterMiddleware.cs b/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusExporterMiddleware.cs index d02339706bc..c6148cc8e35 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusExporterMiddleware.cs +++ b/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusExporterMiddleware.cs @@ -80,7 +80,7 @@ public async Task InvokeAsync(HttpContext httpContext) else { // It's not expected to have no metrics to collect, but it's not necessarily a failure, either. - response.StatusCode = 204; + response.StatusCode = 200; PrometheusExporterEventSource.Log.NoMetrics(); } } diff --git a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListener.cs b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListener.cs index 26994830a66..40ab4b93807 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListener.cs +++ b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListener.cs @@ -166,7 +166,7 @@ private async Task ProcessRequestAsync(HttpListenerContext context) else { // It's not expected to have no metrics to collect, but it's not necessarily a failure, either. - context.Response.StatusCode = 204; + context.Response.StatusCode = 200; PrometheusExporterEventSource.Log.NoMetrics(); } } From dde3ba27e680536b8faa202435a7f793918a7104 Mon Sep 17 00:00:00 2001 From: dszmigielski Date: Fri, 9 Sep 2022 10:48:03 +0200 Subject: [PATCH 2/3] Update changelog and tests --- src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md | 3 +++ .../CHANGELOG.md | 3 +++ .../PrometheusExporterMiddlewareTests.cs | 2 +- .../PrometheusHttpListenerTests.cs | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md b/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md index 7ca283721c9..3cd92536530 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +* Bug fix for Prometheus Exporter reporting StatusCode 204 +instead of 200, when no metrics are collected + ## 1.4.0-alpha.2 Released 2022-Aug-18 diff --git a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/CHANGELOG.md b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/CHANGELOG.md index 9f7671595c4..ebececaaeb9 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +* Bug fix for Prometheus Exporter reporting StatusCode 204 +instead of 200, when no metrics are collected + ## 1.4.0-alpha.2 Released 2022-Aug-18 diff --git a/test/OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests/PrometheusExporterMiddlewareTests.cs b/test/OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests/PrometheusExporterMiddlewareTests.cs index ff8b0bdc484..07db88f7102 100644 --- a/test/OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests/PrometheusExporterMiddlewareTests.cs +++ b/test/OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests/PrometheusExporterMiddlewareTests.cs @@ -281,7 +281,7 @@ private static async Task RunPrometheusExporterMiddlewareIntegrationTest( } else { - Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); } validateResponse?.Invoke(response); diff --git a/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusHttpListenerTests.cs b/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusHttpListenerTests.cs index fb281a3563f..a35dcf89b26 100644 --- a/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusHttpListenerTests.cs +++ b/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusHttpListenerTests.cs @@ -140,7 +140,7 @@ private async Task RunPrometheusExporterHttpServerIntegrationTest(bool skipMetri } else { - Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); } } } From c07397f5a05c6a0cef0462ce0e83f0742fb295a7 Mon Sep 17 00:00:00 2001 From: dszmigielski Date: Fri, 9 Sep 2022 11:03:23 +0200 Subject: [PATCH 3/3] Add bug link to changelogs --- src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md | 1 + .../CHANGELOG.md | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md b/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md index 3cd92536530..acd5d5ba488 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md @@ -4,6 +4,7 @@ * Bug fix for Prometheus Exporter reporting StatusCode 204 instead of 200, when no metrics are collected +([#3643](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3643)) ## 1.4.0-alpha.2 diff --git a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/CHANGELOG.md b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/CHANGELOG.md index ebececaaeb9..eb1859a39d0 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/CHANGELOG.md @@ -3,7 +3,8 @@ ## Unreleased * Bug fix for Prometheus Exporter reporting StatusCode 204 -instead of 200, when no metrics are collected + instead of 200, when no metrics are collected + ([#3643](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3643)) ## 1.4.0-alpha.2