From 47c74278b7538fca741b5bd0fe8dd607f6afbc6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Fri, 3 Feb 2023 12:58:44 +0100 Subject: [PATCH] Set OpenMetrics content header See: https://github.com/prometheus/common/blob/main/expfmt/encode.go#L86 See: https://github.com/kubernetes/kube-state-metrics/issues/1973 --- pkg/metricshandler/metrics_handler.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/metricshandler/metrics_handler.go b/pkg/metricshandler/metrics_handler.go index a6a245dfe2..56d5bf9f3c 100644 --- a/pkg/metricshandler/metrics_handler.go +++ b/pkg/metricshandler/metrics_handler.go @@ -183,7 +183,7 @@ func (m *MetricsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { resHeader := w.Header() var writer io.Writer = w - resHeader.Set("Content-Type", `text/plain; version=`+"0.0.4") + resHeader.Set("Content-Type", `application/openmetrics-text; version=`+"0.0.1"+`; charset=utf-8`) if m.enableGZIPEncoding { // Gzip response if requested. Taken from @@ -206,6 +206,8 @@ func (m *MetricsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } } + w.Write([]byte("# EOF\n")) + // In case we gzipped the response, we have to close the writer. if closer, ok := writer.(io.Closer); ok { err := closer.Close()