Merge pull request #18382 from roidelapluie/roidelapluie/fix-summary-no-quantiles-panic

textparse: fix panic in protobuf parser for summary with no quantiles
This commit is contained in:
Julien 2026-03-31 14:51:14 +02:00 committed by GitHub
commit f99f3bb65d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 0 deletions

View file

@ -674,6 +674,10 @@ func (p *ProtobufParser) getMagicLabel() (bool, string, string) {
switch p.dec.GetType() {
case dto.MetricType_SUMMARY:
qq := p.dec.GetSummary().GetQuantile()
if p.fieldPos >= len(qq) {
p.fieldsDone = true
return false, "", ""
}
q := qq[p.fieldPos]
p.fieldsDone = p.fieldPos == len(qq)-1
return true, model.QuantileLabel, labels.FormatOpenMetricsFloat(q.GetQuantile())

View file

@ -5911,6 +5911,32 @@ func generateValidMetricName(r *rand.Rand) string {
return generateString(r, validFirstRunes, validMetricNameRunes)
}
// TestProtobufParseSummaryNoQuantilesNoPanic is a regression test for a panic
// when Next() is called without Series() on a summary with no quantiles.
func TestProtobufParseSummaryNoQuantilesNoPanic(t *testing.T) {
buf := metricFamiliesToProtobuf(t, []string{`
name: "no_quantile_summary"
help: "A summary with no quantile entries."
type: SUMMARY
metric: <
summary: <
sample_count: 10
sample_sum: 1.5
>
>
`})
p := NewProtobufParser(buf.Bytes(), false, false, false, false, labels.NewSymbolTable())
require.NotPanics(t, func() {
for {
_, err := p.Next()
if errors.Is(err, io.EOF) || err != nil {
break
}
}
})
}
func generateString(r *rand.Rand, firstRunes, restRunes []rune) string {
result := make([]rune, 1+r.Intn(20))
for i := range result {