Skip to content

Commit

Permalink
fix: Index out of range in metrics_store.SanitizeHeaders
Browse files Browse the repository at this point in the history
2023-08-24T18:08:21.796778057Z 2023/08/24 18:08:21 http: panic serving ip:port: runtime error: index out of range [0] with length 0
2023-08-24T18:08:21.796814387Z goroutine 589687 [running]:
2023-08-24T18:08:21.796823334Z net/http.(*conn).serve.func1()
2023-08-24T18:08:21.796830520Z  /usr/local/go/src/net/http/server.go:1854 +0xbf
2023-08-24T18:08:21.796838117Z panic({0x19c2060, 0xc0043060a8})
2023-08-24T18:08:21.796844764Z  /usr/local/go/src/runtime/panic.go:890 +0x263
2023-08-24T18:08:21.796852064Z k8s.io/kube-state-metrics/v2/pkg/metrics_store.SanitizeHeaders(...)
2023-08-24T18:08:21.796858974Z  /root/go/src/k8s.io/kube-state-metrics/pkg/metrics_store/metrics_writer.go:94
2023-08-24T18:08:21.796866007Z k8s.io/kube-state-metrics/v2/pkg/metricshandler.(*MetricsHandler).ServeHTTP(0xc000221490, {0x1d425a0, 0xc005872700}, 0xc003f9d300)
2023-08-24T18:08:21.796873054Z  /root/go/src/k8s.io/kube-state-metrics/pkg/metricshandler/metrics_handler.go:211 +0x8fe
...

Signed-off-by: Manuel Rüger <manuel@rueg.eu>
  • Loading branch information
mrueg committed Aug 24, 2023
1 parent e3dd5ff commit 1536c72
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pkg/metrics_store/metrics_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ func (m MetricsWriter) WriteAll(w io.Writer) error {
func SanitizeHeaders(writers MetricsWriterList) MetricsWriterList {
var lastHeader string
for _, writer := range writers {
for i, header := range writer.stores[0].headers {
if header == lastHeader {
writer.stores[0].headers[i] = ""
} else {
lastHeader = header
if len(writer.stores) > 0 {
for i, header := range writer.stores[0].headers {
if header == lastHeader {
writer.stores[0].headers[i] = ""
} else {
lastHeader = header
}
}
}
}
Expand Down

0 comments on commit 1536c72

Please sign in to comment.