Accept values with a negative exponent in wavefront parser (#5462)

This commit is contained in:
Pierre Tessier 2019-02-21 17:49:52 -05:00 committed by Daniel Nelson
parent 33dfbfdf5e
commit 5f1bc9e49f
2 changed files with 22 additions and 1 deletions

View File

@ -60,7 +60,7 @@ func (ep *ValueParser) parse(p *PointParser, pt *Point) error {
tok, lit = p.scan()
}
for tok != EOF && (tok == LETTER || tok == NUMBER || tok == DOT) {
for tok != EOF && (tok == LETTER || tok == NUMBER || tok == DOT || tok == MINUS_SIGN) {
p.writeBuf.WriteString(lit)
tok, lit = p.scan()
}

View File

@ -63,6 +63,24 @@ func TestParse(t *testing.T) {
assert.NoError(t, err)
assert.EqualValues(t, parsedMetrics[0], testMetric)
parsedMetrics, err = parser.Parse([]byte("\"test.metric\" -1.1234 1530939936 \"source\"=\"mysource\" tag2=value2"))
assert.NoError(t, err)
testMetric, err = metric.New("test.metric", map[string]string{"source": "mysource", "tag2": "value2"}, map[string]interface{}{"value": -1.1234}, time.Unix(1530939936, 0))
assert.NoError(t, err)
assert.EqualValues(t, parsedMetrics[0], testMetric)
parsedMetrics, err = parser.Parse([]byte("\"test.metric\" 1.1234e04 1530939936 \"source\"=\"mysource\" tag2=value2"))
assert.NoError(t, err)
testMetric, err = metric.New("test.metric", map[string]string{"source": "mysource", "tag2": "value2"}, map[string]interface{}{"value": 1.1234e04}, time.Unix(1530939936, 0))
assert.NoError(t, err)
assert.EqualValues(t, parsedMetrics[0], testMetric)
parsedMetrics, err = parser.Parse([]byte("\"test.metric\" 1.1234e-04 1530939936 \"source\"=\"mysource\" tag2=value2"))
assert.NoError(t, err)
testMetric, err = metric.New("test.metric", map[string]string{"source": "mysource", "tag2": "value2"}, map[string]interface{}{"value": 1.1234e-04}, time.Unix(1530939936, 0))
assert.NoError(t, err)
assert.EqualValues(t, parsedMetrics[0], testMetric)
parsedMetrics, err = parser.Parse([]byte("test.metric 1.1234 1530939936 source=\"mysource\" tag2=value2 "))
assert.NoError(t, err)
testMetric, err = metric.New("test.metric", map[string]string{"source": "mysource", "tag2": "value2"}, map[string]interface{}{"value": 1.1234}, time.Unix(1530939936, 0))
@ -201,6 +219,9 @@ func TestParseInvalid(t *testing.T) {
_, err = parser.Parse([]byte("test.metric 1 1530939936 tag1=val\\\"ue1"))
assert.Error(t, err)
_, err = parser.Parse([]byte("\"test.metric\" -1.12-34 1530939936 \"source\"=\"mysource\" tag2=value2"))
assert.Error(t, err)
}
func TestParseDefaultTags(t *testing.T) {