mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-20 07:19:17 +01:00
app/vmselect: properly handle empty label (aka __name__) in LabelEntries handler
This commit is contained in:
parent
75a0acf72d
commit
945894e049
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user