Skip to content
This repository has been archived by the owner on Oct 17, 2018. It is now read-only.

Commit

Permalink
Slightly generalize NameAndTags for m3 ids
Browse files Browse the repository at this point in the history
  • Loading branch information
xichen2020 committed Jun 27, 2017
1 parent 833a34a commit e53fec5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion metric/id/m3/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (id metricID) TagValue(tagName []byte) ([]byte, bool) {
// NameAndTags returns the name and the tags of the given id.
func NameAndTags(id []byte) ([]byte, []byte, error) {
firstSplitterIdx := bytes.IndexByte(id, componentSplitter)
if !bytes.Equal(m3Prefix, id[:firstSplitterIdx+1]) {
if !bytes.HasSuffix(id[:firstSplitterIdx+1], m3Prefix) {
return nil, nil, errInvalidM3Metric
}
secondSplitterIdx := bytes.IndexByte(id[firstSplitterIdx+1:], componentSplitter)
Expand Down
12 changes: 12 additions & 0 deletions metric/id/m3/id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ func TestNameAndTags(t *testing.T) {
expectedTags []byte
expectedErr error
}{
{
id: []byte("stats.m3+foo+tagName1=tagValue1"),
expectedName: []byte("foo"),
expectedTags: []byte("tagName1=tagValue1"),
expectedErr: nil,
},
{
id: []byte("m3+foo+tagName1=tagValue1"),
expectedName: []byte("foo"),
Expand All @@ -144,6 +150,12 @@ func TestNameAndTags(t *testing.T) {
expectedTags: nil,
expectedErr: errInvalidM3Metric,
},
{
id: []byte("m34+illformed+tagName1=tagValue1"),
expectedName: nil,
expectedTags: nil,
expectedErr: errInvalidM3Metric,
},
{
id: []byte("m3+illformed"),
expectedName: nil,
Expand Down

0 comments on commit e53fec5

Please sign in to comment.