mirror of
https://github.com/prometheus/prometheus.git
synced 2026-06-13 18:40:16 -04:00
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:
commit
f99f3bb65d
2 changed files with 30 additions and 0 deletions
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue