Package list golang-github-go-kit-kit / b1e8249
Fixed overwrite global tags in Influx adapter Kihamo 4 years ago
2 changed file(s) with 31 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
167167 if len(labelValues)%2 != 0 {
168168 panic("mergeTags received a labelValues with an odd number of strings")
169169 }
170
171 ret := make(map[string]string, len(tags) + len(labelValues) / 2)
172 for k, v := range tags {
173 ret[k] = v
174 }
170175 for i := 0; i < len(labelValues); i += 2 {
171 tags[labelValues[i]] = labelValues[i+1]
172 }
173 return tags
176 ret[labelValues[i]] = labelValues[i+1]
177 }
178 return ret
174179 }
175180
176181 func sum(a []float64) float64 {
2626 }
2727 if err := teststat.TestCounter(counter, value); err != nil {
2828 t.Fatal(err)
29 }
30 }
31
32 func TestCounter_RewriteTags(t *testing.T) {
33 in := New(map[string]string{}, influxdb.BatchPointsConfig{}, log.NewNopLogger())
34
35 reFirst := regexp.MustCompile(`influx_counter_first,tag_for_counter_first=first count=([0-9\.]+) [0-9]+`)
36 counterFirst := in.NewCounter("influx_counter_first").With("tag_for_counter_first", "first")
37 counterFirst.Add(11)
38
39 reSecond := regexp.MustCompile(`influx_counter_second,tag_for_counter_second=second count=([0-9\.]+) [0-9]+`)
40 counterSecond := in.NewCounter("influx_counter_second").With("tag_for_counter_second", "second")
41 counterSecond.Add(22)
42
43 client := &bufWriter{}
44 in.WriteTo(client)
45
46 for _, row := range strings.Split(client.buf.String(), string('\n')) {
47 if strings.HasPrefix(row, "influx_counter_first") && !reFirst.MatchString(row) {
48 t.Fatal(`First counter not equal "`, reFirst.String() , `" want "`, row, `"`)
49 } else if strings.HasPrefix(row, "influx_counter_second") && !reSecond.MatchString(row) {
50 t.Fatal(`Second counter not equal "`, reSecond.String() , `" want "`, row, `"`)
51 }
2952 }
3053 }
3154