mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-30 23:20:51 -08:00
Merge pull request #9008 from cw9/cw9/openmetricsparsets
Return error on NaN and Inf timestamps for OpenMetrics parser
This commit is contained in:
commit
1a1394fc58
|
@ -336,6 +336,9 @@ func (p *OpenMetricsParser) Next() (Entry, error) {
|
||||||
if ts, err = parseFloat(yoloString(p.l.buf()[1:])); err != nil {
|
if ts, err = parseFloat(yoloString(p.l.buf()[1:])); err != nil {
|
||||||
return EntryInvalid, err
|
return EntryInvalid, err
|
||||||
}
|
}
|
||||||
|
if math.IsNaN(ts) || math.IsInf(ts, 0) {
|
||||||
|
return EntryInvalid, errors.New("invalid timestamp")
|
||||||
|
}
|
||||||
p.ts = int64(ts * 1000)
|
p.ts = int64(ts * 1000)
|
||||||
switch t3 := p.nextToken(); t3 {
|
switch t3 := p.nextToken(); t3 {
|
||||||
case tLinebreak:
|
case tLinebreak:
|
||||||
|
@ -392,6 +395,9 @@ func (p *OpenMetricsParser) parseComment() error {
|
||||||
if ts, err = parseFloat(yoloString(p.l.buf()[1:])); err != nil {
|
if ts, err = parseFloat(yoloString(p.l.buf()[1:])); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if math.IsNaN(ts) || math.IsInf(ts, 0) {
|
||||||
|
return errors.New("invalid exemplar timestamp")
|
||||||
|
}
|
||||||
p.exemplarTs = int64(ts * 1000)
|
p.exemplarTs = int64(ts * 1000)
|
||||||
switch t3 := p.nextToken(); t3 {
|
switch t3 := p.nextToken(); t3 {
|
||||||
case tLinebreak:
|
case tLinebreak:
|
||||||
|
|
|
@ -504,6 +504,30 @@ func TestOpenMetricsParseErrors(t *testing.T) {
|
||||||
input: `{b="c",} 1`,
|
input: `{b="c",} 1`,
|
||||||
err: `"INVALID" "{" is not a valid start token`,
|
err: `"INVALID" "{" is not a valid start token`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
input: `a 1 NaN`,
|
||||||
|
err: `invalid timestamp`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: `a 1 -Inf`,
|
||||||
|
err: `invalid timestamp`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: `a 1 Inf`,
|
||||||
|
err: `invalid timestamp`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "# TYPE hhh histogram\nhhh_bucket{le=\"+Inf\"} 1 # {aa=\"bb\"} 4 NaN",
|
||||||
|
err: `invalid exemplar timestamp`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "# TYPE hhh histogram\nhhh_bucket{le=\"+Inf\"} 1 # {aa=\"bb\"} 4 -Inf",
|
||||||
|
err: `invalid exemplar timestamp`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "# TYPE hhh histogram\nhhh_bucket{le=\"+Inf\"} 1 # {aa=\"bb\"} 4 Inf",
|
||||||
|
err: `invalid exemplar timestamp`,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, c := range cases {
|
for i, c := range cases {
|
||||||
|
|
Loading…
Reference in a new issue