2019-02-26 18:48:41 +00:00
|
|
|
package influx_test
|
2018-03-28 00:30:51 +00:00
|
|
|
|
|
|
|
import (
|
2020-03-04 18:13:44 +00:00
|
|
|
"bytes"
|
2019-02-26 18:48:41 +00:00
|
|
|
"errors"
|
2018-03-28 00:30:51 +00:00
|
|
|
"fmt"
|
2020-03-04 18:13:44 +00:00
|
|
|
"io"
|
2018-03-28 00:30:51 +00:00
|
|
|
"testing"
|
|
|
|
|
2019-02-26 18:48:41 +00:00
|
|
|
"github.com/influxdata/telegraf/plugins/parsers/influx"
|
2018-03-28 00:30:51 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
type TestingHandler struct {
|
|
|
|
results []Result
|
|
|
|
}
|
|
|
|
|
2019-02-26 18:48:41 +00:00
|
|
|
func (h *TestingHandler) SetMeasurement(name []byte) error {
|
2020-03-04 18:13:44 +00:00
|
|
|
n := make([]byte, len(name))
|
|
|
|
copy(n, name)
|
|
|
|
|
2018-03-28 00:30:51 +00:00
|
|
|
mname := Result{
|
|
|
|
Name: Measurement,
|
2020-03-04 18:13:44 +00:00
|
|
|
Value: n,
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
h.results = append(h.results, mname)
|
2019-02-26 18:48:41 +00:00
|
|
|
return nil
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 18:48:41 +00:00
|
|
|
func (h *TestingHandler) AddTag(key []byte, value []byte) error {
|
2020-03-04 18:13:44 +00:00
|
|
|
k := make([]byte, len(key))
|
|
|
|
copy(k, key)
|
|
|
|
v := make([]byte, len(value))
|
|
|
|
copy(v, value)
|
|
|
|
|
2018-03-28 00:30:51 +00:00
|
|
|
tagkey := Result{
|
|
|
|
Name: TagKey,
|
2020-03-04 18:13:44 +00:00
|
|
|
Value: k,
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
tagvalue := Result{
|
|
|
|
Name: TagValue,
|
2020-03-04 18:13:44 +00:00
|
|
|
Value: v,
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
h.results = append(h.results, tagkey, tagvalue)
|
2019-02-26 18:48:41 +00:00
|
|
|
return nil
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 18:48:41 +00:00
|
|
|
func (h *TestingHandler) AddInt(key []byte, value []byte) error {
|
2020-03-04 18:13:44 +00:00
|
|
|
k := make([]byte, len(key))
|
|
|
|
copy(k, key)
|
|
|
|
v := make([]byte, len(value))
|
|
|
|
copy(v, value)
|
|
|
|
|
2018-03-28 00:30:51 +00:00
|
|
|
fieldkey := Result{
|
|
|
|
Name: FieldKey,
|
2020-03-04 18:13:44 +00:00
|
|
|
Value: k,
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
fieldvalue := Result{
|
|
|
|
Name: FieldInt,
|
2020-03-04 18:13:44 +00:00
|
|
|
Value: v,
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
h.results = append(h.results, fieldkey, fieldvalue)
|
2019-02-26 18:48:41 +00:00
|
|
|
return nil
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 18:48:41 +00:00
|
|
|
func (h *TestingHandler) AddUint(key []byte, value []byte) error {
|
2020-03-04 18:13:44 +00:00
|
|
|
k := make([]byte, len(key))
|
|
|
|
copy(k, key)
|
|
|
|
v := make([]byte, len(value))
|
|
|
|
copy(v, value)
|
|
|
|
|
2018-03-28 23:43:25 +00:00
|
|
|
fieldkey := Result{
|
|
|
|
Name: FieldKey,
|
|
|
|
Value: key,
|
|
|
|
}
|
|
|
|
fieldvalue := Result{
|
|
|
|
Name: FieldUint,
|
|
|
|
Value: value,
|
|
|
|
}
|
|
|
|
h.results = append(h.results, fieldkey, fieldvalue)
|
2019-02-26 18:48:41 +00:00
|
|
|
return nil
|
2018-03-28 23:43:25 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 18:48:41 +00:00
|
|
|
func (h *TestingHandler) AddFloat(key []byte, value []byte) error {
|
2020-03-04 18:13:44 +00:00
|
|
|
k := make([]byte, len(key))
|
|
|
|
copy(k, key)
|
|
|
|
v := make([]byte, len(value))
|
|
|
|
copy(v, value)
|
|
|
|
|
2018-03-28 00:30:51 +00:00
|
|
|
fieldkey := Result{
|
|
|
|
Name: FieldKey,
|
2020-03-04 18:13:44 +00:00
|
|
|
Value: k,
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
fieldvalue := Result{
|
|
|
|
Name: FieldFloat,
|
2020-03-04 18:13:44 +00:00
|
|
|
Value: v,
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
h.results = append(h.results, fieldkey, fieldvalue)
|
2019-02-26 18:48:41 +00:00
|
|
|
return nil
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 18:48:41 +00:00
|
|
|
func (h *TestingHandler) AddString(key []byte, value []byte) error {
|
2020-03-04 18:13:44 +00:00
|
|
|
k := make([]byte, len(key))
|
|
|
|
copy(k, key)
|
|
|
|
v := make([]byte, len(value))
|
|
|
|
copy(v, value)
|
|
|
|
|
2018-03-28 00:30:51 +00:00
|
|
|
fieldkey := Result{
|
|
|
|
Name: FieldKey,
|
2020-03-04 18:13:44 +00:00
|
|
|
Value: k,
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
fieldvalue := Result{
|
|
|
|
Name: FieldString,
|
2020-03-04 18:13:44 +00:00
|
|
|
Value: v,
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
h.results = append(h.results, fieldkey, fieldvalue)
|
2019-02-26 18:48:41 +00:00
|
|
|
return nil
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 18:48:41 +00:00
|
|
|
func (h *TestingHandler) AddBool(key []byte, value []byte) error {
|
2020-03-04 18:13:44 +00:00
|
|
|
k := make([]byte, len(key))
|
|
|
|
copy(k, key)
|
|
|
|
v := make([]byte, len(value))
|
|
|
|
copy(v, value)
|
|
|
|
|
2018-03-28 00:30:51 +00:00
|
|
|
fieldkey := Result{
|
|
|
|
Name: FieldKey,
|
2020-03-04 18:13:44 +00:00
|
|
|
Value: k,
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
fieldvalue := Result{
|
|
|
|
Name: FieldBool,
|
2020-03-04 18:13:44 +00:00
|
|
|
Value: v,
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
h.results = append(h.results, fieldkey, fieldvalue)
|
2019-02-26 18:48:41 +00:00
|
|
|
return nil
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 18:48:41 +00:00
|
|
|
func (h *TestingHandler) SetTimestamp(tm []byte) error {
|
2020-03-04 18:13:44 +00:00
|
|
|
t := make([]byte, len(tm))
|
|
|
|
copy(t, tm)
|
|
|
|
|
2018-03-28 00:30:51 +00:00
|
|
|
timestamp := Result{
|
|
|
|
Name: Timestamp,
|
2020-03-04 18:13:44 +00:00
|
|
|
Value: t,
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
h.results = append(h.results, timestamp)
|
2019-02-26 18:48:41 +00:00
|
|
|
return nil
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 18:48:41 +00:00
|
|
|
func (h *TestingHandler) Result(err error) {
|
|
|
|
var res Result
|
|
|
|
if err == nil {
|
|
|
|
res = Result{
|
|
|
|
Name: Success,
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
res = Result{
|
|
|
|
Name: Error,
|
|
|
|
err: err,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
h.results = append(h.results, res)
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *TestingHandler) Results() []Result {
|
|
|
|
return h.results
|
|
|
|
}
|
|
|
|
|
|
|
|
type BenchmarkingHandler struct {
|
|
|
|
}
|
|
|
|
|
2019-02-26 18:48:41 +00:00
|
|
|
func (h *BenchmarkingHandler) SetMeasurement(name []byte) error {
|
|
|
|
return nil
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 18:48:41 +00:00
|
|
|
func (h *BenchmarkingHandler) AddTag(key []byte, value []byte) error {
|
|
|
|
return nil
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 18:48:41 +00:00
|
|
|
func (h *BenchmarkingHandler) AddInt(key []byte, value []byte) error {
|
|
|
|
return nil
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 18:48:41 +00:00
|
|
|
func (h *BenchmarkingHandler) AddUint(key []byte, value []byte) error {
|
|
|
|
return nil
|
2018-03-28 23:43:25 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 18:48:41 +00:00
|
|
|
func (h *BenchmarkingHandler) AddFloat(key []byte, value []byte) error {
|
|
|
|
return nil
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 18:48:41 +00:00
|
|
|
func (h *BenchmarkingHandler) AddString(key []byte, value []byte) error {
|
|
|
|
return nil
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 18:48:41 +00:00
|
|
|
func (h *BenchmarkingHandler) AddBool(key []byte, value []byte) error {
|
|
|
|
return nil
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 18:48:41 +00:00
|
|
|
func (h *BenchmarkingHandler) SetTimestamp(tm []byte) error {
|
|
|
|
return nil
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type TokenType int
|
|
|
|
|
|
|
|
const (
|
|
|
|
NoMatch TokenType = iota
|
|
|
|
Measurement
|
|
|
|
TagKey
|
|
|
|
TagValue
|
|
|
|
FieldKey
|
|
|
|
FieldString
|
|
|
|
FieldInt
|
|
|
|
FieldUint
|
|
|
|
FieldFloat
|
|
|
|
FieldBool
|
|
|
|
Timestamp
|
|
|
|
EOL
|
|
|
|
EOF
|
|
|
|
Punc
|
|
|
|
WhiteSpace
|
2019-02-26 18:48:41 +00:00
|
|
|
Success
|
|
|
|
Error
|
2018-03-28 00:30:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (t TokenType) String() string {
|
|
|
|
switch t {
|
|
|
|
case NoMatch:
|
|
|
|
return "NoMatch"
|
|
|
|
case Measurement:
|
|
|
|
return "Measurement"
|
|
|
|
case TagKey:
|
|
|
|
return "TagKey"
|
|
|
|
case TagValue:
|
|
|
|
return "TagValue"
|
|
|
|
case FieldKey:
|
|
|
|
return "FieldKey"
|
|
|
|
case FieldInt:
|
|
|
|
return "FieldInt"
|
|
|
|
case FieldUint:
|
|
|
|
return "FieldUint"
|
|
|
|
case FieldFloat:
|
|
|
|
return "FieldFloat"
|
|
|
|
case FieldString:
|
|
|
|
return "FieldString"
|
|
|
|
case FieldBool:
|
|
|
|
return "FieldBool"
|
|
|
|
case Timestamp:
|
|
|
|
return "Timestamp"
|
|
|
|
case EOL:
|
|
|
|
return "EOL"
|
|
|
|
case EOF:
|
|
|
|
return "EOF"
|
|
|
|
case Punc:
|
|
|
|
return "Punc"
|
|
|
|
case WhiteSpace:
|
|
|
|
return "WhiteSpace"
|
2019-02-26 18:48:41 +00:00
|
|
|
case Success:
|
|
|
|
return "Success"
|
|
|
|
case Error:
|
|
|
|
return "Error"
|
2018-03-28 00:30:51 +00:00
|
|
|
default:
|
|
|
|
panic("Unknown TokenType")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type Token struct {
|
|
|
|
Name TokenType
|
|
|
|
Value []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t Token) String() string {
|
|
|
|
return fmt.Sprintf("(%s %q)", t.Name, t.Value)
|
|
|
|
}
|
|
|
|
|
|
|
|
type Result struct {
|
|
|
|
Name TokenType
|
|
|
|
Value []byte
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r Result) String() string {
|
|
|
|
return fmt.Sprintf("(%s, %q, %v)", r.Name, r.Value, r.err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var tests = []struct {
|
|
|
|
name string
|
|
|
|
input []byte
|
|
|
|
results []Result
|
|
|
|
err error
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "empty string",
|
|
|
|
input: []byte(""),
|
|
|
|
results: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "minimal",
|
|
|
|
input: []byte("cpu value=42"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "newline",
|
|
|
|
input: []byte("cpu value=42\n"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "minimal with timestamp",
|
|
|
|
input: []byte("cpu value=42 1516241192000000000"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Timestamp,
|
|
|
|
Value: []byte("1516241192000000000"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "measurement escape non-special",
|
|
|
|
input: []byte(`c\pu value=42`),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte(`c\pu`),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "measurement escaped trailing backslash",
|
|
|
|
input: []byte(`cpu\\ value=42`),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte(`cpu\\`),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "single char measurement",
|
|
|
|
input: []byte("c value=42"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("c"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "escape backslash in measurement",
|
|
|
|
input: []byte(`cp\\u value=42`),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte(`cp\\u`),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "measurement escape space",
|
|
|
|
input: []byte(`cpu\ abc value=42`),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte(`cpu\ abc`),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "scientific float",
|
|
|
|
input: []byte("cpu value=42e0"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42e0"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "scientific float negative mantissa",
|
|
|
|
input: []byte("cpu value=-42e0"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("-42e0"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "scientific float negative exponent",
|
|
|
|
input: []byte("cpu value=42e-1"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42e-1"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "scientific float big e",
|
|
|
|
input: []byte("cpu value=42E0"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42E0"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "scientific float missing exponent",
|
|
|
|
input: []byte("cpu value=42E"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2019-02-26 18:48:41 +00:00
|
|
|
Name: Error,
|
|
|
|
err: influx.ErrFieldParse,
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "float with decimal",
|
|
|
|
input: []byte("cpu value=42.2"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42.2"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "negative float",
|
|
|
|
input: []byte("cpu value=-42"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("-42"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "float without integer digits",
|
|
|
|
input: []byte("cpu value=.42"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte(".42"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
2018-04-23 20:29:49 +00:00
|
|
|
{
|
|
|
|
name: "float without integer digits negative",
|
|
|
|
input: []byte("cpu value=-.42"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-04-23 20:29:49 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-04-23 20:29:49 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-04-23 20:29:49 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("-.42"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-04-23 20:29:49 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "float with multiple leading 0",
|
|
|
|
input: []byte("cpu value=00.42"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-04-23 20:29:49 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-04-23 20:29:49 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-04-23 20:29:49 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("00.42"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-04-23 20:29:49 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid float with only dot",
|
|
|
|
input: []byte("cpu value=."),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-04-23 20:29:49 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2019-02-26 18:48:41 +00:00
|
|
|
Name: Error,
|
|
|
|
err: influx.ErrFieldParse,
|
2018-04-23 20:29:49 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
{
|
|
|
|
name: "multiple fields",
|
|
|
|
input: []byte("cpu x=42,y=42"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("x"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("y"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "integer field",
|
|
|
|
input: []byte("cpu value=42i"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldInt,
|
|
|
|
Value: []byte("42i"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "negative integer field",
|
|
|
|
input: []byte("cpu value=-42i"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldInt,
|
|
|
|
Value: []byte("-42i"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "zero integer field",
|
|
|
|
input: []byte("cpu value=0i"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldInt,
|
|
|
|
Value: []byte("0i"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "negative zero integer field",
|
|
|
|
input: []byte("cpu value=-0i"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldInt,
|
|
|
|
Value: []byte("-0i"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "integer field overflow okay",
|
|
|
|
input: []byte("cpu value=9223372036854775808i"),
|
|
|
|
results: []Result{
|
|
|
|
{
|
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: FieldInt,
|
|
|
|
Value: []byte("9223372036854775808i"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid field",
|
|
|
|
input: []byte("cpu value=howdy"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2019-02-26 18:48:41 +00:00
|
|
|
Name: Error,
|
|
|
|
err: influx.ErrFieldParse,
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "string field",
|
2019-02-26 18:48:41 +00:00
|
|
|
input: []byte("cpu value=\"42\""),
|
2018-03-28 00:30:51 +00:00
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldString,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "newline in string field",
|
|
|
|
input: []byte("cpu value=\"4\n2\""),
|
|
|
|
results: []Result{
|
|
|
|
{
|
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: FieldString,
|
|
|
|
Value: []byte("4\n2"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
2020-04-28 21:42:37 +00:00
|
|
|
{
|
|
|
|
name: "cr in string field",
|
|
|
|
input: []byte("cpu value=\"4\r2\""),
|
|
|
|
results: []Result{
|
|
|
|
{
|
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: FieldString,
|
|
|
|
Value: []byte("4\r2"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
{
|
|
|
|
name: "bool field",
|
2019-02-26 18:48:41 +00:00
|
|
|
input: []byte("cpu value=true"),
|
2018-03-28 00:30:51 +00:00
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldBool,
|
|
|
|
Value: []byte("true"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "tag",
|
2019-02-26 18:48:41 +00:00
|
|
|
input: []byte("cpu,host=localhost value=42"),
|
2018-03-28 00:30:51 +00:00
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: TagKey,
|
|
|
|
Value: []byte("host"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: TagValue,
|
|
|
|
Value: []byte("localhost"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "tag key escape space",
|
2019-02-26 18:48:41 +00:00
|
|
|
input: []byte("cpu,h\\ ost=localhost value=42"),
|
2018-03-28 00:30:51 +00:00
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: TagKey,
|
|
|
|
Value: []byte(`h\ ost`),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: TagValue,
|
|
|
|
Value: []byte("localhost"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "tag key escape comma",
|
2019-02-26 18:48:41 +00:00
|
|
|
input: []byte("cpu,h\\,ost=localhost value=42"),
|
2018-03-28 00:30:51 +00:00
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: TagKey,
|
|
|
|
Value: []byte(`h\,ost`),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: TagValue,
|
|
|
|
Value: []byte("localhost"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "tag key escape equal",
|
2019-02-26 18:48:41 +00:00
|
|
|
input: []byte("cpu,h\\=ost=localhost value=42"),
|
2018-03-28 00:30:51 +00:00
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: TagKey,
|
|
|
|
Value: []byte(`h\=ost`),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: TagValue,
|
|
|
|
Value: []byte("localhost"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "multiple tags",
|
2019-02-26 18:48:41 +00:00
|
|
|
input: []byte("cpu,host=localhost,cpu=cpu0 value=42"),
|
2018-03-28 00:30:51 +00:00
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: TagKey,
|
|
|
|
Value: []byte("host"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: TagValue,
|
|
|
|
Value: []byte("localhost"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: TagKey,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: TagValue,
|
|
|
|
Value: []byte("cpu0"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "tag value escape space",
|
|
|
|
input: []byte(`cpu,host=two\ words value=42`),
|
|
|
|
results: []Result{
|
|
|
|
{
|
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: TagKey,
|
|
|
|
Value: []byte("host"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: TagValue,
|
|
|
|
Value: []byte(`two\ words`),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "tag value double escape space",
|
|
|
|
input: []byte(`cpu,host=two\\ words value=42`),
|
|
|
|
results: []Result{
|
|
|
|
{
|
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: TagKey,
|
|
|
|
Value: []byte("host"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: TagValue,
|
|
|
|
Value: []byte(`two\\ words`),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "tag value triple escape space",
|
|
|
|
input: []byte(`cpu,host=two\\\ words value=42`),
|
|
|
|
results: []Result{
|
|
|
|
{
|
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: TagKey,
|
|
|
|
Value: []byte("host"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: TagValue,
|
|
|
|
Value: []byte(`two\\\ words`),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "tag invalid missing separator",
|
|
|
|
input: []byte("cpu,xyzzy value=42"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2019-02-26 18:48:41 +00:00
|
|
|
Name: Error,
|
|
|
|
err: influx.ErrTagParse,
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "tag invalid missing value",
|
|
|
|
input: []byte("cpu,xyzzy= value=42"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2019-02-26 18:48:41 +00:00
|
|
|
Name: Error,
|
|
|
|
err: influx.ErrTagParse,
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "tag invalid unescaped space",
|
|
|
|
input: []byte("cpu,h ost=localhost value=42"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2019-02-26 18:48:41 +00:00
|
|
|
Name: Error,
|
|
|
|
err: influx.ErrTagParse,
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "tag invalid unescaped comma",
|
|
|
|
input: []byte("cpu,h,ost=localhost value=42"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2019-02-26 18:48:41 +00:00
|
|
|
Name: Error,
|
|
|
|
err: influx.ErrTagParse,
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "tag invalid unescaped equals",
|
|
|
|
input: []byte("cpu,h=ost=localhost value=42"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2019-02-26 18:48:41 +00:00
|
|
|
Name: Error,
|
|
|
|
err: influx.ErrTagParse,
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "timestamp negative",
|
|
|
|
input: []byte("cpu value=42 -1"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Timestamp,
|
|
|
|
Value: []byte("-1"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "timestamp zero",
|
|
|
|
input: []byte("cpu value=42 0"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Timestamp,
|
|
|
|
Value: []byte("0"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "multiline",
|
2019-02-26 18:48:41 +00:00
|
|
|
input: []byte("cpu value=42\n\n\n\ncpu value=43"),
|
2018-03-28 00:30:51 +00:00
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("43"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "error recovery",
|
2019-02-26 18:48:41 +00:00
|
|
|
input: []byte("cpu value=howdy,value2=42\ncpu\ncpu value=42"),
|
2018-03-28 00:30:51 +00:00
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2019-02-26 18:48:41 +00:00
|
|
|
Name: Error,
|
|
|
|
err: influx.ErrFieldParse,
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2019-02-26 18:48:41 +00:00
|
|
|
Name: Error,
|
|
|
|
err: influx.ErrTagParse,
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "line whitespace",
|
|
|
|
input: []byte(" cpu value=42 1516241192000000000 \n\n cpu value=42"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Timestamp,
|
|
|
|
Value: []byte("1516241192000000000"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "leading newline",
|
|
|
|
input: []byte("\ncpu value=42"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid missing field value",
|
|
|
|
input: []byte("cpu value="),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2019-02-26 18:48:41 +00:00
|
|
|
Name: Error,
|
|
|
|
err: influx.ErrFieldParse,
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid eof field key",
|
|
|
|
input: []byte("cpu value"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2019-02-26 18:48:41 +00:00
|
|
|
Name: Error,
|
|
|
|
err: influx.ErrFieldParse,
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid measurement only",
|
|
|
|
input: []byte("cpu"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2019-02-26 18:48:41 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: Error,
|
|
|
|
err: influx.ErrTagParse,
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2019-02-26 18:48:41 +00:00
|
|
|
name: "invalid measurement char",
|
|
|
|
input: []byte(","),
|
2018-03-28 00:30:51 +00:00
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2019-02-26 18:48:41 +00:00
|
|
|
Name: Error,
|
|
|
|
err: influx.ErrNameParse,
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid missing tag",
|
|
|
|
input: []byte("cpu, value=42"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2019-02-26 18:48:41 +00:00
|
|
|
Name: Error,
|
|
|
|
err: influx.ErrTagParse,
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid missing field",
|
|
|
|
input: []byte("cpu,x=y "),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: TagKey,
|
|
|
|
Value: []byte("x"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: TagValue,
|
|
|
|
Value: []byte("y"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2019-02-26 18:48:41 +00:00
|
|
|
Name: Error,
|
|
|
|
err: influx.ErrFieldParse,
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid too many fields",
|
|
|
|
input: []byte("cpu value=42 value=43"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2019-02-26 18:48:41 +00:00
|
|
|
Name: Error,
|
|
|
|
err: influx.ErrTimestampParse,
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid timestamp too long",
|
|
|
|
input: []byte("cpu value=42 12345678901234567890"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2019-02-26 18:48:41 +00:00
|
|
|
Name: Error,
|
|
|
|
err: influx.ErrTimestampParse,
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid open string field",
|
|
|
|
input: []byte(`cpu value="42 12345678901234567890`),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2019-02-26 18:48:41 +00:00
|
|
|
Name: Error,
|
|
|
|
err: influx.ErrFieldParse,
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-04-09 22:29:52 +00:00
|
|
|
{
|
2019-02-26 18:48:41 +00:00
|
|
|
name: "invalid field value",
|
|
|
|
input: []byte("cpu value=howdy"),
|
2018-04-09 22:29:52 +00:00
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-04-09 22:29:52 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2019-02-26 18:48:41 +00:00
|
|
|
Name: Error,
|
|
|
|
err: influx.ErrFieldParse,
|
2018-04-09 22:29:52 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
{
|
2019-02-26 18:48:41 +00:00
|
|
|
name: "invalid quoted timestamp",
|
|
|
|
input: []byte("cpu value=42 \"12345678901234567890\""),
|
2018-03-28 00:30:51 +00:00
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2019-02-26 18:48:41 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: Error,
|
|
|
|
err: influx.ErrTimestampParse,
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2019-02-26 18:48:41 +00:00
|
|
|
name: "comment only",
|
|
|
|
input: []byte("# blah blah"),
|
|
|
|
results: []Result(nil),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "commented line",
|
|
|
|
input: []byte("# blah blah\ncpu value=42"),
|
2018-03-28 00:30:51 +00:00
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2019-02-26 18:48:41 +00:00
|
|
|
Name: Success,
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2019-02-26 18:48:41 +00:00
|
|
|
name: "middle comment",
|
|
|
|
input: []byte("cpu value=42\n# blah blah\ncpu value=42"),
|
2018-03-28 00:30:51 +00:00
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "end with comment",
|
|
|
|
input: []byte("cpu value=42\n# blah blah"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "end with comment and whitespace",
|
|
|
|
input: []byte("cpu value=42\n# blah blah\n\n "),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unicode",
|
|
|
|
input: []byte("cpu ☺=42"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("☺"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-03-28 00:30:51 +00:00
|
|
|
Name: FieldFloat,
|
|
|
|
Value: []byte("42"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-03-28 00:30:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMachine(t *testing.T) {
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
handler := &TestingHandler{}
|
2019-02-26 18:48:41 +00:00
|
|
|
fsm := influx.NewMachine(handler)
|
2018-03-28 00:30:51 +00:00
|
|
|
fsm.SetData(tt.input)
|
|
|
|
|
2019-02-26 18:48:41 +00:00
|
|
|
for i := 0; i < 20; i++ {
|
|
|
|
err := fsm.Next()
|
|
|
|
if err != nil && err == influx.EOF {
|
2018-03-28 00:30:51 +00:00
|
|
|
break
|
|
|
|
}
|
2019-02-26 18:48:41 +00:00
|
|
|
handler.Result(err)
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
results := handler.Results()
|
|
|
|
require.Equal(t, tt.results, results)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-04 18:13:44 +00:00
|
|
|
var positionTests = []struct {
|
|
|
|
name string
|
|
|
|
input []byte
|
|
|
|
lineno int
|
|
|
|
column int
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "empty string",
|
|
|
|
input: []byte(""),
|
|
|
|
lineno: 1,
|
|
|
|
column: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "minimal",
|
|
|
|
input: []byte("cpu value=42"),
|
|
|
|
lineno: 1,
|
|
|
|
column: 13,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "one newline",
|
|
|
|
input: []byte("cpu value=42\ncpu value=42"),
|
|
|
|
lineno: 2,
|
|
|
|
column: 13,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "several newlines",
|
|
|
|
input: []byte("cpu value=42\n\n\n"),
|
|
|
|
lineno: 4,
|
|
|
|
column: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "error on second line",
|
|
|
|
input: []byte("cpu value=42\ncpu value=invalid"),
|
|
|
|
lineno: 2,
|
|
|
|
column: 11,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "error after comment line",
|
|
|
|
input: []byte("cpu value=42\n# comment\ncpu value=invalid"),
|
|
|
|
lineno: 3,
|
|
|
|
column: 11,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "dos line endings",
|
|
|
|
input: []byte("cpu value=42\r\ncpu value=invalid"),
|
|
|
|
lineno: 2,
|
|
|
|
column: 11,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "mac line endings not supported",
|
|
|
|
input: []byte("cpu value=42\rcpu value=invalid"),
|
|
|
|
lineno: 1,
|
|
|
|
column: 14,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-02-26 18:48:41 +00:00
|
|
|
func TestMachinePosition(t *testing.T) {
|
2020-03-04 18:13:44 +00:00
|
|
|
for _, tt := range positionTests {
|
2019-02-26 18:48:41 +00:00
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
handler := &TestingHandler{}
|
|
|
|
fsm := influx.NewMachine(handler)
|
|
|
|
fsm.SetData(tt.input)
|
|
|
|
|
|
|
|
// Parse until an error or eof
|
|
|
|
for i := 0; i < 20; i++ {
|
|
|
|
err := fsm.Next()
|
|
|
|
if err != nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
require.Equal(t, tt.lineno, fsm.LineNumber(), "lineno")
|
|
|
|
require.Equal(t, tt.column, fsm.Column(), "column")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-28 00:30:51 +00:00
|
|
|
func BenchmarkMachine(b *testing.B) {
|
|
|
|
for _, tt := range tests {
|
|
|
|
b.Run(tt.name, func(b *testing.B) {
|
|
|
|
handler := &BenchmarkingHandler{}
|
2019-02-26 18:48:41 +00:00
|
|
|
fsm := influx.NewMachine(handler)
|
2018-03-28 00:30:51 +00:00
|
|
|
|
|
|
|
for n := 0; n < b.N; n++ {
|
|
|
|
fsm.SetData(tt.input)
|
|
|
|
|
2019-02-26 18:48:41 +00:00
|
|
|
for {
|
|
|
|
err := fsm.Next()
|
|
|
|
if err != nil {
|
|
|
|
break
|
|
|
|
}
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMachineProcstat(t *testing.T) {
|
2019-06-14 18:27:24 +00:00
|
|
|
input := []byte("procstat,exe=bash,process_name=bash voluntary_context_switches=42i,memory_rss=5103616i,rlimit_memory_data_hard=2147483647i,cpu_time_user=0.02,rlimit_file_locks_soft=2147483647i,pid=29417i,cpu_time_nice=0,rlimit_memory_locked_soft=65536i,read_count=259i,rlimit_memory_vms_hard=2147483647i,memory_swap=0i,rlimit_num_fds_soft=1024i,rlimit_nice_priority_hard=0i,cpu_time_soft_irq=0,cpu_time=0i,rlimit_memory_locked_hard=65536i,realtime_priority=0i,signals_pending=0i,nice_priority=20i,cpu_time_idle=0,memory_stack=139264i,memory_locked=0i,rlimit_memory_stack_soft=8388608i,cpu_time_iowait=0,cpu_time_guest=0,cpu_time_guest_nice=0,rlimit_memory_data_soft=2147483647i,read_bytes=0i,rlimit_cpu_time_soft=2147483647i,involuntary_context_switches=2i,write_bytes=106496i,cpu_time_system=0,cpu_time_irq=0,cpu_usage=0,memory_vms=21659648i,memory_data=1576960i,rlimit_memory_stack_hard=2147483647i,num_threads=1i,rlimit_memory_rss_soft=2147483647i,rlimit_realtime_priority_soft=0i,num_fds=4i,write_count=35i,rlimit_signals_pending_soft=78994i,cpu_time_steal=0,rlimit_num_fds_hard=4096i,rlimit_file_locks_hard=2147483647i,rlimit_cpu_time_hard=2147483647i,rlimit_signals_pending_hard=78994i,rlimit_nice_priority_soft=0i,rlimit_memory_rss_hard=2147483647i,rlimit_memory_vms_soft=2147483647i,rlimit_realtime_priority_hard=0i 1517620624000000000")
|
2018-03-28 00:30:51 +00:00
|
|
|
handler := &TestingHandler{}
|
2019-02-26 18:48:41 +00:00
|
|
|
fsm := influx.NewMachine(handler)
|
2018-03-28 00:30:51 +00:00
|
|
|
fsm.SetData(input)
|
2019-02-26 18:48:41 +00:00
|
|
|
for {
|
|
|
|
err := fsm.Next()
|
|
|
|
if err != nil {
|
|
|
|
break
|
|
|
|
}
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkMachineProcstat(b *testing.B) {
|
2019-06-14 18:27:24 +00:00
|
|
|
input := []byte("procstat,exe=bash,process_name=bash voluntary_context_switches=42i,memory_rss=5103616i,rlimit_memory_data_hard=2147483647i,cpu_time_user=0.02,rlimit_file_locks_soft=2147483647i,pid=29417i,cpu_time_nice=0,rlimit_memory_locked_soft=65536i,read_count=259i,rlimit_memory_vms_hard=2147483647i,memory_swap=0i,rlimit_num_fds_soft=1024i,rlimit_nice_priority_hard=0i,cpu_time_soft_irq=0,cpu_time=0i,rlimit_memory_locked_hard=65536i,realtime_priority=0i,signals_pending=0i,nice_priority=20i,cpu_time_idle=0,memory_stack=139264i,memory_locked=0i,rlimit_memory_stack_soft=8388608i,cpu_time_iowait=0,cpu_time_guest=0,cpu_time_guest_nice=0,rlimit_memory_data_soft=2147483647i,read_bytes=0i,rlimit_cpu_time_soft=2147483647i,involuntary_context_switches=2i,write_bytes=106496i,cpu_time_system=0,cpu_time_irq=0,cpu_usage=0,memory_vms=21659648i,memory_data=1576960i,rlimit_memory_stack_hard=2147483647i,num_threads=1i,rlimit_memory_rss_soft=2147483647i,rlimit_realtime_priority_soft=0i,num_fds=4i,write_count=35i,rlimit_signals_pending_soft=78994i,cpu_time_steal=0,rlimit_num_fds_hard=4096i,rlimit_file_locks_hard=2147483647i,rlimit_cpu_time_hard=2147483647i,rlimit_signals_pending_hard=78994i,rlimit_nice_priority_soft=0i,rlimit_memory_rss_hard=2147483647i,rlimit_memory_vms_soft=2147483647i,rlimit_realtime_priority_hard=0i 1517620624000000000")
|
2018-03-28 00:30:51 +00:00
|
|
|
handler := &BenchmarkingHandler{}
|
2019-02-26 18:48:41 +00:00
|
|
|
fsm := influx.NewMachine(handler)
|
2018-03-28 00:30:51 +00:00
|
|
|
for n := 0; n < b.N; n++ {
|
|
|
|
fsm.SetData(input)
|
2019-02-26 18:48:41 +00:00
|
|
|
for {
|
|
|
|
err := fsm.Next()
|
|
|
|
if err != nil {
|
|
|
|
break
|
|
|
|
}
|
2018-03-28 00:30:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-05-14 18:00:03 +00:00
|
|
|
|
|
|
|
func TestSeriesMachine(t *testing.T) {
|
|
|
|
var tests = []struct {
|
|
|
|
name string
|
|
|
|
input []byte
|
|
|
|
results []Result
|
|
|
|
err error
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "empty string",
|
|
|
|
input: []byte(""),
|
|
|
|
results: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "no tags",
|
|
|
|
input: []byte("cpu"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-05-14 18:00:03 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-05-14 18:00:03 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "tags",
|
|
|
|
input: []byte("cpu,a=x,b=y"),
|
|
|
|
results: []Result{
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-05-14 18:00:03 +00:00
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-05-14 18:00:03 +00:00
|
|
|
Name: TagKey,
|
|
|
|
Value: []byte("a"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-05-14 18:00:03 +00:00
|
|
|
Name: TagValue,
|
|
|
|
Value: []byte("x"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-05-14 18:00:03 +00:00
|
|
|
Name: TagKey,
|
|
|
|
Value: []byte("b"),
|
|
|
|
},
|
2018-10-19 20:32:54 +00:00
|
|
|
{
|
2018-05-14 18:00:03 +00:00
|
|
|
Name: TagValue,
|
|
|
|
Value: []byte("y"),
|
|
|
|
},
|
2019-02-26 18:48:41 +00:00
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
2018-05-14 18:00:03 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
handler := &TestingHandler{}
|
2019-02-26 18:48:41 +00:00
|
|
|
fsm := influx.NewSeriesMachine(handler)
|
2018-05-14 18:00:03 +00:00
|
|
|
fsm.SetData(tt.input)
|
|
|
|
|
2019-02-26 18:48:41 +00:00
|
|
|
for {
|
|
|
|
err := fsm.Next()
|
|
|
|
if err != nil {
|
2018-05-14 18:00:03 +00:00
|
|
|
break
|
|
|
|
}
|
2019-02-26 18:48:41 +00:00
|
|
|
handler.Result(err)
|
2018-05-14 18:00:03 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 18:48:41 +00:00
|
|
|
results := handler.Results()
|
|
|
|
require.Equal(t, tt.results, results)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type MockHandler struct {
|
|
|
|
SetMeasurementF func(name []byte) error
|
|
|
|
AddTagF func(key []byte, value []byte) error
|
|
|
|
AddIntF func(key []byte, value []byte) error
|
|
|
|
AddUintF func(key []byte, value []byte) error
|
|
|
|
AddFloatF func(key []byte, value []byte) error
|
|
|
|
AddStringF func(key []byte, value []byte) error
|
|
|
|
AddBoolF func(key []byte, value []byte) error
|
|
|
|
SetTimestampF func(tm []byte) error
|
|
|
|
|
|
|
|
TestingHandler
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *MockHandler) SetMeasurement(name []byte) error {
|
|
|
|
h.TestingHandler.SetMeasurement(name)
|
|
|
|
return h.SetMeasurementF(name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *MockHandler) AddTag(name, value []byte) error {
|
|
|
|
return h.AddTagF(name, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *MockHandler) AddInt(name, value []byte) error {
|
|
|
|
err := h.AddIntF(name, value)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
h.TestingHandler.AddInt(name, value)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *MockHandler) AddUint(name, value []byte) error {
|
|
|
|
err := h.AddUintF(name, value)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
h.TestingHandler.AddUint(name, value)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *MockHandler) AddFloat(name, value []byte) error {
|
|
|
|
return h.AddFloatF(name, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *MockHandler) AddString(name, value []byte) error {
|
|
|
|
return h.AddStringF(name, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *MockHandler) AddBool(name, value []byte) error {
|
|
|
|
return h.AddBoolF(name, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *MockHandler) SetTimestamp(tm []byte) error {
|
|
|
|
return h.SetTimestampF(tm)
|
|
|
|
}
|
|
|
|
|
2020-03-04 18:13:44 +00:00
|
|
|
var errorRecoveryTests = []struct {
|
|
|
|
name string
|
|
|
|
input []byte
|
|
|
|
handler *MockHandler
|
|
|
|
results []Result
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "integer",
|
|
|
|
input: []byte("cpu value=43i\ncpu value=42i"),
|
|
|
|
handler: &MockHandler{
|
|
|
|
SetMeasurementF: func(name []byte) error {
|
|
|
|
return nil
|
2019-02-26 18:48:41 +00:00
|
|
|
},
|
2020-03-04 18:13:44 +00:00
|
|
|
AddIntF: func(name, value []byte) error {
|
|
|
|
if string(value) != "42i" {
|
|
|
|
return errors.New("handler error")
|
|
|
|
}
|
|
|
|
return nil
|
2019-02-26 18:48:41 +00:00
|
|
|
},
|
|
|
|
},
|
2020-03-04 18:13:44 +00:00
|
|
|
results: []Result{
|
|
|
|
{
|
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
2019-02-26 18:48:41 +00:00
|
|
|
},
|
2020-03-04 18:13:44 +00:00
|
|
|
{
|
|
|
|
Name: Error,
|
|
|
|
err: errors.New("handler error"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: FieldInt,
|
|
|
|
Value: []byte("42i"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: Success,
|
2019-02-26 18:48:41 +00:00
|
|
|
},
|
|
|
|
},
|
2020-03-04 18:13:44 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "integer with timestamp",
|
|
|
|
input: []byte("cpu value=43i 1516241192000000000\ncpu value=42i"),
|
|
|
|
handler: &MockHandler{
|
|
|
|
SetMeasurementF: func(name []byte) error {
|
|
|
|
return nil
|
2019-02-26 18:48:41 +00:00
|
|
|
},
|
2020-03-04 18:13:44 +00:00
|
|
|
AddIntF: func(name, value []byte) error {
|
|
|
|
if string(value) != "42i" {
|
|
|
|
return errors.New("handler error")
|
|
|
|
}
|
|
|
|
return nil
|
2019-02-26 18:48:41 +00:00
|
|
|
},
|
|
|
|
},
|
2020-03-04 18:13:44 +00:00
|
|
|
results: []Result{
|
|
|
|
{
|
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: Error,
|
|
|
|
err: errors.New("handler error"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: FieldInt,
|
|
|
|
Value: []byte("42i"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unsigned",
|
|
|
|
input: []byte("cpu value=43u\ncpu value=42u"),
|
|
|
|
handler: &MockHandler{
|
|
|
|
SetMeasurementF: func(name []byte) error {
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
AddUintF: func(name, value []byte) error {
|
|
|
|
if string(value) != "42u" {
|
|
|
|
return errors.New("handler error")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
results: []Result{
|
|
|
|
{
|
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: Error,
|
|
|
|
err: errors.New("handler error"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: Measurement,
|
|
|
|
Value: []byte("cpu"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: FieldKey,
|
|
|
|
Value: []byte("value"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: FieldUint,
|
|
|
|
Value: []byte("42u"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: Success,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHandlerErrorRecovery(t *testing.T) {
|
|
|
|
for _, tt := range errorRecoveryTests {
|
2019-02-26 18:48:41 +00:00
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
fsm := influx.NewMachine(tt.handler)
|
|
|
|
fsm.SetData(tt.input)
|
|
|
|
|
|
|
|
for i := 0; i < 20; i++ {
|
|
|
|
err := fsm.Next()
|
|
|
|
if err != nil && err == influx.EOF {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
tt.handler.Result(err)
|
2018-05-14 18:00:03 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 18:48:41 +00:00
|
|
|
results := tt.handler.Results()
|
2018-05-14 18:00:03 +00:00
|
|
|
require.Equal(t, tt.results, results)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2020-03-04 18:13:44 +00:00
|
|
|
|
|
|
|
func TestStreamMachine(t *testing.T) {
|
|
|
|
type testcase struct {
|
|
|
|
name string
|
|
|
|
input io.Reader
|
|
|
|
results []Result
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
|
|
|
|
var tc []testcase
|
|
|
|
for _, tt := range tests {
|
|
|
|
tc = append(tc, testcase{
|
|
|
|
name: tt.name,
|
|
|
|
input: bytes.NewBuffer([]byte(tt.input)),
|
|
|
|
results: tt.results,
|
|
|
|
err: tt.err,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tc {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
handler := &TestingHandler{}
|
|
|
|
fsm := influx.NewStreamMachine(tt.input, handler)
|
|
|
|
|
|
|
|
// Parse only up to 20 metrics; to avoid any bugs where the parser
|
|
|
|
// isn't terminated.
|
|
|
|
for i := 0; i < 20; i++ {
|
|
|
|
err := fsm.Next()
|
|
|
|
if err != nil && err == influx.EOF {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
handler.Result(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
results := handler.Results()
|
|
|
|
require.Equal(t, tt.results, results)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStreamMachinePosition(t *testing.T) {
|
|
|
|
type testcase struct {
|
|
|
|
name string
|
|
|
|
input io.Reader
|
|
|
|
lineno int
|
|
|
|
column int
|
|
|
|
}
|
|
|
|
|
|
|
|
var tc []testcase
|
|
|
|
for _, tt := range positionTests {
|
|
|
|
tc = append(tc, testcase{
|
|
|
|
name: tt.name,
|
|
|
|
input: bytes.NewBuffer([]byte(tt.input)),
|
|
|
|
lineno: tt.lineno,
|
|
|
|
column: tt.column,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tc {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
handler := &TestingHandler{}
|
|
|
|
fsm := influx.NewStreamMachine(tt.input, handler)
|
|
|
|
|
|
|
|
// Parse until an error or eof
|
|
|
|
for i := 0; i < 20; i++ {
|
|
|
|
err := fsm.Next()
|
|
|
|
if err != nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
require.Equal(t, tt.lineno, fsm.LineNumber(), "lineno")
|
|
|
|
require.Equal(t, tt.column, fsm.Column(), "column")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|