-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dogstatsd_sink): support EXTRA_TAGS
When using the godogstats sink, previously the EXTRA_TAGS would not be emitted as datadog tags. Signed-off-by: Josh Jaques <[email protected]>
- Loading branch information
Showing
3 changed files
with
148 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package godogstats | ||
|
||
import ( | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSeparateExtraTags(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
givenMetric string | ||
expectOutput string | ||
expectTags []string | ||
}{ | ||
{ | ||
name: "has extra tags", | ||
givenMetric: "ratelimit.service.rate_limit.mongo_cps.database_users.total_hits.__COMMIT=12345.__DEPLOY=6890", | ||
expectOutput: "ratelimit.service.rate_limit.mongo_cps.database_users.total_hits", | ||
expectTags: []string{"COMMIT:12345", "DEPLOY:6890"}, | ||
}, | ||
{ | ||
name: "no extra tags", | ||
givenMetric: "ratelimit.service.rate_limit.mongo_cps.database_users.total_hits", | ||
expectOutput: "ratelimit.service.rate_limit.mongo_cps.database_users.total_hits", | ||
expectTags: nil, | ||
}, | ||
{ | ||
name: "invalid extra tags", | ||
givenMetric: "ratelimit.service.rate_limit.mongo_cps.database_users.total_hits.__COMMIT", | ||
expectOutput: "ratelimit.service.rate_limit.mongo_cps.database_users.total_hits", | ||
expectTags: []string{}, | ||
}, | ||
} | ||
|
||
g := &godogStatsSink{} | ||
for _, tt := range tests { | ||
actualName, actualTags := g.separateExtraTags(tt.givenMetric) | ||
|
||
assert.Equal(t, tt.expectOutput, actualName) | ||
assert.Equal(t, tt.expectTags, actualTags) | ||
} | ||
} | ||
|
||
func TestSinkMogrify(t *testing.T) { | ||
g := &godogStatsSink{ | ||
mogrifier: mogrifierMap{ | ||
regexp.MustCompile(`^ratelimit\.(.*)$`): func(matches []string) (string, []string) { | ||
return "custom." + matches[1], []string{"tag1:value1", "tag2:value2"} | ||
}, | ||
}, | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
input string | ||
expectedName string | ||
expectedTags []string | ||
}{ | ||
{ | ||
name: "mogrify with match and extra tags", | ||
input: "ratelimit.service.rate_limit.mongo_cps.database_users.total_hits.__COMMIT=12345.__DEPLOY=67890", | ||
expectedName: "custom.service.rate_limit.mongo_cps.database_users.total_hits", | ||
expectedTags: []string{"COMMIT:12345", "DEPLOY:67890", "tag1:value1", "tag2:value2"}, | ||
}, | ||
{ | ||
name: "mogrify with match without extra tags", | ||
input: "ratelimit.service.rate_limit.mongo_cps.database_users.total_hits", | ||
expectedName: "custom.service.rate_limit.mongo_cps.database_users.total_hits", | ||
expectedTags: []string{"tag1:value1", "tag2:value2"}, | ||
}, | ||
{ | ||
name: "extra tags with no match", | ||
input: "foo.service.rate_limit.mongo_cps.database_users.total_hits.__COMMIT=12345.__DEPLOY=67890", | ||
expectedName: "foo.service.rate_limit.mongo_cps.database_users.total_hits", | ||
expectedTags: []string{"COMMIT:12345", "DEPLOY:67890"}, | ||
}, | ||
{ | ||
name: "no mogrification", | ||
input: "other.metric.name", | ||
expectedName: "other.metric.name", | ||
expectedTags: nil, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
actualName, actualTags := g.mogrify(tt.input) | ||
|
||
assert.Equal(t, tt.expectedName, actualName) | ||
assert.Equal(t, tt.expectedTags, actualTags) | ||
} | ||
} |