Skip to content

Commit

Permalink
Fix a bug with ID generation for series with no tags. (#1392)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnikola authored Feb 20, 2019
1 parent bd3cc15 commit 71b1f91
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/query/models/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,17 @@ func EmptyTags() Tags {
}

// ID returns a byte slice representation of the tags, using the generation
// strategy from .
// strategy from the tag options.
func (t Tags) ID() []byte {
schemeType := t.Opts.IDSchemeType()
if len(t.Tags) == 0 {
if schemeType == TypeQuoted {
return []byte("{}")
}

return []byte("")
}

switch schemeType {
case TypeLegacy:
return t.legacyID()
Expand Down
18 changes: 18 additions & 0 deletions src/query/models/tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,24 @@ func buildTags(b *testing.B, count, length int, opts TagOptions, escape bool) Ta
return NewTags(count, opts).AddTags(tags)
}

func TestEmptyTags(t *testing.T) {
tests := []struct {
idType IDSchemeType
expected string
}{
{TypeLegacy, ""},
{TypePrependMeta, ""},
{TypeGraphite, ""},
{TypeQuoted, "{}"},
}

for _, tt := range tests {
tags := NewTags(0, NewTagOptions().SetIDSchemeType(tt.idType))
id := tags.ID()
assert.Equal(t, []byte(tt.expected), id)
}
}

var tagBenchmarks = []struct {
name string
tagCount, tagLength int
Expand Down

0 comments on commit 71b1f91

Please sign in to comment.