Skip to content

Commit 8e7b38d

Browse files
committed
fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fix: fallback to gauge for protofmt-based negotiations
1 parent e0c3e83 commit 8e7b38d

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

pkg/metrics_store/metrics_writer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func SanitizeHeaders(contentType string, writers MetricsWriterList) MetricsWrite
100100
// Skip this step if we encounter a repeated header, as it will be removed.
101101
if header != lastHeader && strings.HasPrefix(header, "# HELP") {
102102

103-
// If the requested content type was proto-based, replace "info" and "statesets" with "gauge", as they are not recognized by Prometheus' protobuf machinery.
103+
// 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.
104104
if strings.HasPrefix(contentType, expfmt.ProtoType) {
105105
infoTypeString := string(metric.Info)
106106
stateSetTypeString := string(metric.StateSet)

pkg/metricshandler/metrics_handler.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,9 @@ func (m *MetricsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
187187
var writer io.Writer = w
188188

189189
contentType := expfmt.NegotiateIncludingOpenMetrics(r.Header)
190-
gotContentType := contentType
191190

192-
// 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
193-
if contentType != expfmt.FmtOpenMetrics_1_0_0 && contentType != expfmt.FmtOpenMetrics_0_0_1 {
191+
// Assume text/plain if no Content-Type header is set.
192+
if contentType == expfmt.FmtUnknown {
194193
contentType = expfmt.FmtText
195194
}
196195
resHeader.Set("Content-Type", string(contentType))
@@ -209,7 +208,7 @@ func (m *MetricsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
209208
}
210209
}
211210

212-
m.metricsWriters = metricsstore.SanitizeHeaders(string(gotContentType), m.metricsWriters)
211+
m.metricsWriters = metricsstore.SanitizeHeaders(string(contentType), m.metricsWriters)
213212
for _, w := range m.metricsWriters {
214213
err := w.WriteAll(writer)
215214
if err != nil {

0 commit comments

Comments
 (0)