app/vmselect/graphite: remove duplicate name tag from /tags/autoComplete/tags handler

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/942
This commit is contained in:
Aliaksandr Valialkin 2020-12-07 01:07:03 +02:00
parent 82972a8f2a
commit 007dbf273d
2 changed files with 20 additions and 2 deletions

View file

@ -485,11 +485,18 @@ func GetGraphiteTags(filter string, limit int, deadline searchutils.Deadline) ([
} }
// Substitute "__name__" with "name" for Graphite compatibility // Substitute "__name__" with "name" for Graphite compatibility
for i := range labels { for i := range labels {
if labels[i] == "__name__" { if labels[i] != "__name__" {
continue
}
// Prevent from duplicate `name` tag.
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/942
if hasString(labels, "name") {
labels = append(labels[:i], labels[i+1:]...)
} else {
labels[i] = "name" labels[i] = "name"
sort.Strings(labels) sort.Strings(labels)
break
} }
break
} }
if len(filter) > 0 { if len(filter) > 0 {
labels, err = applyGraphiteRegexpFilter(filter, labels) labels, err = applyGraphiteRegexpFilter(filter, labels)
@ -503,6 +510,15 @@ func GetGraphiteTags(filter string, limit int, deadline searchutils.Deadline) ([
return labels, nil return labels, nil
} }
func hasString(a []string, s string) bool {
for _, x := range a {
if x == s {
return true
}
}
return false
}
// GetLabels returns labels until the given deadline. // GetLabels returns labels until the given deadline.
func GetLabels(deadline searchutils.Deadline) ([]string, error) { func GetLabels(deadline searchutils.Deadline) ([]string, error) {
if deadline.Exceeded() { if deadline.Exceeded() {

View file

@ -6,6 +6,8 @@
Though [InfluxDB line protocol](https://docs.influxdata.com/influxdb/v1.8/write_protocols/line_protocol_tutorial/) denies multiple whitespace chars between these entities, Though [InfluxDB line protocol](https://docs.influxdata.com/influxdb/v1.8/write_protocols/line_protocol_tutorial/) denies multiple whitespace chars between these entities,
some apps improperly put multiple whitespace chars. This workaround allows accepting data from such apps. some apps improperly put multiple whitespace chars. This workaround allows accepting data from such apps.
* BUGFIX: prevent from duplicate `name` tag returned from `/tags/autoComplete/tags` handler. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/942
# [v1.49.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.49.0) # [v1.49.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.49.0)