This commit is contained in:
Owen Williams 2024-02-06 14:24:37 -05:00
parent a65ed08885
commit f6bc568d8b
3 changed files with 4 additions and 4 deletions

View file

@ -486,7 +486,7 @@ func (p *OpenMetricsParser) parseMetricSuffix(t token) (Entry, error) {
var ts float64 var ts float64
// A float is enough to hold what we need for millisecond resolution. // A float is enough to hold what we need for millisecond resolution.
if ts, err = parseFloat(yoloString(p.l.buf()[1:])); err != nil { if ts, err = parseFloat(yoloString(p.l.buf()[1:])); err != nil {
return EntryInvalid, fmt.Errorf("%v while parsing: %q", err, p.l.b[p.start:p.l.i]) return EntryInvalid, fmt.Errorf("%w while parsing: %q", err, p.l.b[p.start:p.l.i])
} }
if math.IsNaN(ts) || math.IsInf(ts, 0) { if math.IsNaN(ts) || math.IsInf(ts, 0) {
return EntryInvalid, fmt.Errorf("invalid timestamp %f", ts) return EntryInvalid, fmt.Errorf("invalid timestamp %f", ts)

View file

@ -302,7 +302,7 @@ foo_total 17.0 1520879607.789 # {id="counter-test"} 5`
func TestUTF8OpenMetricsParse(t *testing.T) { func TestUTF8OpenMetricsParse(t *testing.T) {
model.NameValidationScheme = model.UTF8Validation model.NameValidationScheme = model.UTF8Validation
defer func(){ defer func() {
model.NameValidationScheme = model.LegacyValidation model.NameValidationScheme = model.LegacyValidation
}() }()

View file

@ -462,7 +462,7 @@ func (p *PromParser) parseMetricSuffix(t token) (Entry, error) {
} }
var err error var err error
if p.val, err = parseFloat(yoloString(p.l.buf())); err != nil { if p.val, err = parseFloat(yoloString(p.l.buf())); err != nil {
return EntryInvalid, fmt.Errorf("%v while parsing: %q", err, p.l.b[p.start:p.l.i]) return EntryInvalid, fmt.Errorf("%w while parsing: %q", err, p.l.b[p.start:p.l.i])
} }
// Ensure canonical NaN value. // Ensure canonical NaN value.
if math.IsNaN(p.val) { if math.IsNaN(p.val) {
@ -475,7 +475,7 @@ func (p *PromParser) parseMetricSuffix(t token) (Entry, error) {
case tTimestamp: case tTimestamp:
p.hasTS = true p.hasTS = true
if p.ts, err = strconv.ParseInt(yoloString(p.l.buf()), 10, 64); err != nil { if p.ts, err = strconv.ParseInt(yoloString(p.l.buf()), 10, 64); err != nil {
return EntryInvalid, fmt.Errorf("%v while parsing: %q", err, p.l.b[p.start:p.l.i]) return EntryInvalid, fmt.Errorf("%w while parsing: %q", err, p.l.b[p.start:p.l.i])
} }
if t2 := p.nextToken(); t2 != tLinebreak { if t2 := p.nextToken(); t2 != tLinebreak {
return EntryInvalid, p.parseError("expected next entry after timestamp", t2) return EntryInvalid, p.parseError("expected next entry after timestamp", t2)