diff --git a/app/vmselect/netstorage/netstorage.go b/app/vmselect/netstorage/netstorage.go index 15522e072..34a455bcc 100644 --- a/app/vmselect/netstorage/netstorage.go +++ b/app/vmselect/netstorage/netstorage.go @@ -485,11 +485,18 @@ func GetGraphiteTags(filter string, limit int, deadline searchutils.Deadline) ([ } // Substitute "__name__" with "name" for Graphite compatibility 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" sort.Strings(labels) - break } + break } if len(filter) > 0 { labels, err = applyGraphiteRegexpFilter(filter, labels) @@ -503,6 +510,15 @@ func GetGraphiteTags(filter string, limit int, deadline searchutils.Deadline) ([ 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. func GetLabels(deadline searchutils.Deadline) ([]string, error) { if deadline.Exceeded() { diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 4e0c99124..6f7487c91 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -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, 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)