Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure metrics labels are sorted #45

Merged
merged 2 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/up/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ func buildOptionsFromFlags(
Name: "__name__",
Value: opts.Name,
})
// We need to ensure labels are sorted before we proceed.
opts.Labels.Sort()

opts.Token = tokenProvider(token, tokenFile)

Expand Down
11 changes: 11 additions & 0 deletions pkg/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package options

import (
"net/url"
"sort"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -90,6 +91,16 @@ func (la *labelArg) Set(v string) error {
return nil
}

// Sort ensures all labels are ordered, in line with how upstream Prometheus code guarantees
// ordering. See https://github.com/prometheus/prometheus/pull/5372.
func (la *labelArg) Sort() {
sort.Sort(la)
}

func (la *labelArg) Len() int { return len(*la) }
func (la *labelArg) Swap(i, j int) { (*la)[i], (*la)[j] = (*la)[j], (*la)[i] }
func (la *labelArg) Less(i, j int) bool { return (*la)[i].Name < (*la)[j].Name }

type logs [][]string

func (va *logs) String() string {
Expand Down