Skip to content

Commit

Permalink
Merge pull request #404 from kihamo/overwrite_global_tags
Browse files Browse the repository at this point in the history
Fixed overwrite global tags in Influx adapter
  • Loading branch information
peterbourgon authored Dec 11, 2016
2 parents afebedc + 3d2e0cb commit 3226232
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
8 changes: 6 additions & 2 deletions metrics/influx/influx.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,14 @@ func mergeTags(tags map[string]string, labelValues []string) map[string]string {
if len(labelValues)%2 != 0 {
panic("mergeTags received a labelValues with an odd number of strings")
}
ret := make(map[string]string, len(tags)+len(labelValues)/2)
for k, v := range tags {
ret[k] = v
}
for i := 0; i < len(labelValues); i += 2 {
tags[labelValues[i]] = labelValues[i+1]
ret[labelValues[i]] = labelValues[i+1]
}
return tags
return ret
}

func sum(a []float64) float64 {
Expand Down
31 changes: 31 additions & 0 deletions metrics/influx/influx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,37 @@ func TestHistogramLabels(t *testing.T) {
}
}

func TestIssue404(t *testing.T) {
in := New(map[string]string{}, influxdb.BatchPointsConfig{}, log.NewNopLogger())

counterOne := in.NewCounter("influx_counter_one").With("a", "b")
counterOne.Add(123)

counterTwo := in.NewCounter("influx_counter_two").With("c", "d")
counterTwo.Add(456)

w := &bufWriter{}
in.WriteTo(w)

lines := strings.Split(strings.TrimSpace(w.buf.String()), "\n")
if want, have := 2, len(lines); want != have {
t.Fatalf("want %d, have %d", want, have)
}
for _, line := range lines {
if strings.HasPrefix(line, "influx_counter_one") {
if !strings.HasPrefix(line, "influx_counter_one,a=b count=123 ") {
t.Errorf("invalid influx_counter_one: %s", line)
}
} else if strings.HasPrefix(line, "influx_counter_two") {
if !strings.HasPrefix(line, "influx_counter_two,c=d count=456 ") {
t.Errorf("invalid influx_counter_two: %s", line)
}
} else {
t.Errorf("unexpected line: %s", line)
}
}
}

type bufWriter struct {
buf bytes.Buffer
}
Expand Down

0 comments on commit 3226232

Please sign in to comment.