Fixed overwrite global tags in Influx adapter
Kihamo
6 years ago
167 | 167 |
if len(labelValues)%2 != 0 {
|
168 | 168 |
panic("mergeTags received a labelValues with an odd number of strings")
|
169 | 169 |
}
|
|
170 |
|
|
171 |
ret := make(map[string]string, len(tags) + len(labelValues) / 2)
|
|
172 |
for k, v := range tags {
|
|
173 |
ret[k] = v
|
|
174 |
}
|
170 | 175 |
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
|
174 | 179 |
}
|
175 | 180 |
|
176 | 181 |
func sum(a []float64) float64 {
|
26 | 26 |
}
|
27 | 27 |
if err := teststat.TestCounter(counter, value); err != nil {
|
28 | 28 |
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 |
}
|
29 | 52 |
}
|
30 | 53 |
}
|
31 | 54 |
|