From 236a94973b68e8751d98d02d8b0aa79f1ea3abea Mon Sep 17 00:00:00 2001 From: Martin Chodur Date: Thu, 7 Mar 2024 23:39:57 +0100 Subject: [PATCH] fix: sort tenants in the validator human readable output Signed-off-by: Martin Chodur --- CHANGELOG.md | 1 + pkg/validator/others.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29d3d3e..2ffdcb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [2.12.0] - 2024-03-07 - Fixed resolving of the path in `paramsFromFile`. Formerly it was resolved from the current working directory, now it must be a relative path, that will be resolved from the config file location. +- Fixed: tenants in the `hasSourceTenantsForMetrics` validator are now sorted in the human readable output. ## [2.11.0] - 2024-03-07 - :warning: CHANGED: Params of the `hasSourceTenantsForMetrics` validator (again FACEPALM). Now the tenant can have multiple regexp matchers. diff --git a/pkg/validator/others.go b/pkg/validator/others.go index 5b48f65..2380b36 100644 --- a/pkg/validator/others.go +++ b/pkg/validator/others.go @@ -56,9 +56,14 @@ type hasSourceTenantsForMetrics struct { func (h hasSourceTenantsForMetrics) String() string { tenantStrings := []string{} - for tenant, metrics := range h.sourceTenants { - for _, m := range metrics { - tenantStrings = append(tenantStrings, fmt.Sprintf("`%s`: `%s` (%s)", tenant, m.regexp.String(), m.description)) + tenants := make([]string, 0, len(h.sourceTenants)) + for tenant := range h.sourceTenants { + tenants = append(tenants, tenant) + } + slices.Sort(tenants) + for _, t := range tenants { + for _, m := range h.sourceTenants[t] { + tenantStrings = append(tenantStrings, fmt.Sprintf("`%s`: `%s` (%s)", t, m.regexp.String(), m.description)) } } return fmt.Sprintf("rule group, the rule belongs to, has the required `source_tenants` configured, according to the mapping of metric names to tenants: \n %s", strings.Join(tenantStrings, "\n "))