Skip to content

Commit

Permalink
fix(promhandler): sort labels and label values after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Jun 11, 2024
1 parent 9f3598e commit 17b6361
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions internal/promhandler/promhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package promhandler

import (
"context"
"slices"
"time"

"github.com/go-faster/errors"
Expand Down Expand Up @@ -97,7 +98,7 @@ func (h *PromAPI) GetLabelValues(ctx context.Context, params promapi.GetLabelVal
}

var (
data = map[string]struct{}{}
dedup = map[string]struct{}{}
warnings annotations.Annotations
)
for _, set := range sets {
Expand All @@ -107,15 +108,17 @@ func (h *PromAPI) GetLabelValues(ctx context.Context, params promapi.GetLabelVal
}

for _, val := range vals {
data[val] = struct{}{}
dedup[val] = struct{}{}
}
warnings = warnings.Merge(w)
}
data := maps.Keys(dedup)
slices.Sort(data)

return &promapi.LabelValuesResponse{
Status: "success",
Warnings: warnings.AsStrings("", 0),
Data: maps.Keys(data),
Data: data,
}, nil
}

Expand Down Expand Up @@ -164,7 +167,7 @@ func (h *PromAPI) GetLabels(ctx context.Context, params promapi.GetLabelsParams)
}

var (
data = map[string]struct{}{}
dedup = map[string]struct{}{}
warnings annotations.Annotations
)
for _, set := range sets {
Expand All @@ -174,15 +177,17 @@ func (h *PromAPI) GetLabels(ctx context.Context, params promapi.GetLabelsParams)
}

for _, val := range vals {
data[val] = struct{}{}
dedup[val] = struct{}{}
}
warnings = warnings.Merge(w)
}
data := maps.Keys(dedup)
slices.Sort(data)

return &promapi.LabelsResponse{
Status: "success",
Warnings: warnings.AsStrings("", 0),
Data: maps.Keys(data),
Data: data,
}, nil
}

Expand Down

0 comments on commit 17b6361

Please sign in to comment.