Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fix: fallback…
Browse files Browse the repository at this point in the history
… to `gauge` for `protofmt`-based negotiations
  • Loading branch information
rexagod committed Mar 26, 2024
1 parent e0c3e83 commit 8e7b38d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/metrics_store/metrics_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func SanitizeHeaders(contentType string, writers MetricsWriterList) MetricsWrite
// Skip this step if we encounter a repeated header, as it will be removed.
if header != lastHeader && strings.HasPrefix(header, "# HELP") {

// If the requested content type was proto-based, replace "info" and "statesets" with "gauge", as they are not recognized by Prometheus' protobuf machinery.
// If the requested content type was proto-based (such as FmtProtoDelim, FmtProtoText, or FmtProtoCompact), replace "info" and "statesets" with "gauge", as they are not recognized by Prometheus' protobuf machinery.
if strings.HasPrefix(contentType, expfmt.ProtoType) {
infoTypeString := string(metric.Info)
stateSetTypeString := string(metric.StateSet)
Expand Down
7 changes: 3 additions & 4 deletions pkg/metricshandler/metrics_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,9 @@ func (m *MetricsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var writer io.Writer = w

contentType := expfmt.NegotiateIncludingOpenMetrics(r.Header)
gotContentType := contentType

// We do not support protobuf at the moment. Fall back to FmtText if the negotiated exposition format is not FmtOpenMetrics See: https://github.com/kubernetes/kube-state-metrics/issues/2022
if contentType != expfmt.FmtOpenMetrics_1_0_0 && contentType != expfmt.FmtOpenMetrics_0_0_1 {
// Assume text/plain if no Content-Type header is set.
if contentType == expfmt.FmtUnknown {
contentType = expfmt.FmtText
}
resHeader.Set("Content-Type", string(contentType))
Expand All @@ -209,7 +208,7 @@ func (m *MetricsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}

m.metricsWriters = metricsstore.SanitizeHeaders(string(gotContentType), m.metricsWriters)
m.metricsWriters = metricsstore.SanitizeHeaders(string(contentType), m.metricsWriters)
for _, w := range m.metricsWriters {
err := w.WriteAll(writer)
if err != nil {
Expand Down

0 comments on commit 8e7b38d

Please sign in to comment.