Skip to content

Commit

Permalink
Sort labelnames for federation.
Browse files Browse the repository at this point in the history
This makes unittests with multiple labels possible,
and may be needed for performance with the new
ingestion text parser.
  • Loading branch information
brian-brazil committed Mar 30, 2017
1 parent dbb6584 commit d42e01b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion web/federate.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,16 @@ func (h *Handler) federation(w http.ResponseWriter, req *http.Request) {
Untyped: &dto.Untyped{},
}

for ln, lv := range s.Metric {
// Sort labelnames for unittest consistency.
labelnames := make([]string, 0, len(s.Metric))
for ln := range s.Metric {
labelnames = append(labelnames, string(ln))
}
sort.Strings(labelnames)

for _, labelname := range labelnames {
ln := model.LabelName(labelname)
lv := s.Metric[ln]
if lv == "" {
// No value means unset. Never consider those labels.
// This is also important to protect against nameless metrics.
Expand Down

0 comments on commit d42e01b

Please sign in to comment.