fix(models): grow tag index buffer if needed (#20138)

fixed #20136
pull/19201/merge
Tristan Su 2021-04-28 00:24:27 +08:00 committed by GitHub
parent 213082441e
commit 7490053b7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -648,6 +648,15 @@ func scanTags(buf []byte, i int, indices []int) (int, int, []int, error) {
case tagValueState:
state, i, err = scanTagsValue(buf, i)
case fieldsState:
// Grow our indices slice if we had exactly enough tags to fill it
if commas >= len(indices) {
// The parser is in `fieldsState`, so there are no more
// tags. We only need 1 more entry in the slice to store
// the final entry.
newIndics := make([]int, cap(indices)+1)
copy(newIndics, indices)
indices = newIndics
}
indices[commas] = i + 1
return i, commas, indices, nil
}

View File

@ -1243,6 +1243,17 @@ func TestParsePointWithDuplicateTags(t *testing.T) {
}
}
func TestParsePointWithVariousTags(t *testing.T) {
line := "m"
for i := 0; i < 1000; i++ {
line += fmt.Sprintf(",t%d=x", i+1)
_, err := models.ParsePointsString(line + " v=0")
if err != nil {
t.Errorf(`ParsePoints("%s") failed`, line)
}
}
}
func TestParsePointWithStringField(t *testing.T) {
test(t, `cpu,host=serverA,region=us-east value=1.0,str="foo",str2="bar" 1000000000`,
NewTestPoint("cpu",