Sort labelnames for federation.

This makes unittests with multiple labels possible,
and may be needed for performance with the new
ingestion text parser.
This commit is contained in:
Brian Brazil 2017-03-27 15:44:37 +01:00 committed by Brian Brazil
parent dbb65846f1
commit d42e01b07c
1 changed files with 10 additions and 1 deletions

View File

@ -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.