Skip to content

Commit

Permalink
Merge pull request #98 from oliver006/oh_fix_sanitize_metric_name
Browse files Browse the repository at this point in the history
fix sanitizeMetricName()
  • Loading branch information
oliver006 authored Sep 3, 2017
2 parents d4b0809 + aceb68f commit 01ace8c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion exporter/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func includeMetric(s string) bool {
}

func sanitizeMetricName(n string) string {
n = strings.Replace(n, "-", "_", 0)
n = strings.Replace(n, "-", "_", -1)
return n
}

Expand Down
14 changes: 13 additions & 1 deletion exporter/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@ func TestKeyValuesAndSizes(t *testing.T) {

func TestKeyValuesAndSizesWildcard(t *testing.T) {
s := dbNumStrFull + "=wild*"
fmt.Println(s)
e, _ := NewRedisExporter(defaultRedisHost, "test", s)

setupDBKeys(t, defaultRedisHost.Addrs[0])
Expand Down Expand Up @@ -703,6 +702,19 @@ func TestMoreThanOneHost(t *testing.T) {
}
}

func TestSanitizeMetricName(t *testing.T) {
tsts := map[string]string{
"cluster_stats_messages_auth-req_received": "cluster_stats_messages_auth_req_received",
"cluster_stats_messages_auth_req_received": "cluster_stats_messages_auth_req_received",
}

for m, want := range tsts {
if got := sanitizeMetricName(m); got != want {
t.Errorf("sanitizeMetricName( %s ) error, want: %s, got: %s", m, want, got)
}
}
}

func init() {
for _, n := range []string{"john", "paul", "ringo", "george"} {
key := fmt.Sprintf("key:%s-%d", n, ts)
Expand Down
6 changes: 3 additions & 3 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 01ace8c

Please sign in to comment.