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 9d79d11a6c
commit 9660774fd1
2 changed files with 20 additions and 2 deletions

View File

@ -586,11 +586,18 @@ func GetGraphiteTags(at *auth.Token, denyPartialResponse bool, filter string, li
} }
// 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)
@ -604,6 +611,15 @@ func GetGraphiteTags(at *auth.Token, denyPartialResponse bool, filter string, li
return labels, isPartial, nil return labels, isPartial, 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(at *auth.Token, denyPartialResponse bool, deadline searchutils.Deadline) ([]string, bool, error) { func GetLabels(at *auth.Token, denyPartialResponse bool, deadline searchutils.Deadline) ([]string, bool, 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)