app/vmselect: properly handle empty label (aka __name__) in LabelEntries handler

This commit is contained in:
Aliaksandr Valialkin 2019-06-10 19:51:05 +03:00
parent 75a0acf72d
commit 945894e049
2 changed files with 11 additions and 6 deletions

View File

@ -579,9 +579,6 @@ func GetLabelEntries(at *auth.Token, deadline Deadline) ([]storage.TagEntry, boo
isPartialResult = true
}
// Deduplicate label entries
labelEntries = deduplicateLabelEntries(labelEntries)
// Substitute "" with "__name__"
for i := range labelEntries {
e := &labelEntries[i]
@ -590,6 +587,9 @@ func GetLabelEntries(at *auth.Token, deadline Deadline) ([]storage.TagEntry, boo
}
}
// Deduplicate label entries
labelEntries = deduplicateLabelEntries(labelEntries)
// Sort labelEntries by the number of label values in each entry.
sort.Slice(labelEntries, func(i, j int) bool {
a, b := labelEntries[i].Values, labelEntries[j].Values

View File

@ -641,11 +641,16 @@ func (s *Server) processVMSelectLabelEntries(ctx *vmselectRequestCtx) error {
// Send labelEntries to vmselect
for i := range labelEntries {
e := &labelEntries[i]
if err := ctx.writeString(e.Key); err != nil {
return fmt.Errorf("cannot write label %q: %s", e.Key, err)
label := e.Key
if label == "" {
// Do this substitution in order to prevent clashing with 'end of response' marker.
label = "__name__"
}
if err := ctx.writeString(label); err != nil {
return fmt.Errorf("cannot write label %q: %s", label, err)
}
if err := writeLabelValues(ctx, e.Values); err != nil {
return fmt.Errorf("cannot write label values for %q: %s", e.Key, err)
return fmt.Errorf("cannot write label values for %q: %s", label, err)
}
}