Skip to content

Commit

Permalink
Set OpenMetrics content header
Browse files Browse the repository at this point in the history
  • Loading branch information
mrueg committed Feb 3, 2023
1 parent 5da24c2 commit 0e0becd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ func buildTelemetryServer(registry prometheus.Gatherer) *http.ServeMux {
mux := http.NewServeMux()

// Add metricsPath
mux.Handle(metricsPath, promhttp.HandlerFor(registry, promhttp.HandlerOpts{ErrorLog: promLogger{}}))
mux.Handle(metricsPath, promhttp.HandlerFor(registry, promhttp.HandlerOpts{ErrorLog: promLogger{}, EnableOpenMetrics: true}))
// Add index
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
Expand Down
4 changes: 3 additions & 1 deletion pkg/metricshandler/metrics_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -206,6 +206,8 @@ func (m *MetricsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}

w.Write([]byte("# EOF"))

// In case we gzipped the response, we have to close the writer.
if closer, ok := writer.(io.Closer); ok {
err := closer.Close()
Expand Down

0 comments on commit 0e0becd

Please sign in to comment.