Skip to content

Commit

Permalink
Fix .metricsUsed in mimirtool analyze rule-file (grafana#6953)
Browse files Browse the repository at this point in the history
* Fix .metricsUsed in mimirtool analyze rule-file

This field wasn't populated.

Fixes grafana#6952

Signed-off-by: Oleg Zaytsev <[email protected]>

* Update CHANGELOG.md

Signed-off-by: Oleg Zaytsev <[email protected]>

* make license

Signed-off-by: Oleg Zaytsev <[email protected]>

---------

Signed-off-by: Oleg Zaytsev <[email protected]>
  • Loading branch information
colega authored Dec 18, 2023
1 parent 680e6b6 commit 6a7bee2
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
### Mimirtool

* [ENHANCEMENT] Analyze Prometheus: set tenant header. #6737
* [BUGFIX] Analyze rule-file: .metricsUsed field wasn't populated. #6953

### Mimir Continuous Test

Expand Down
10 changes: 10 additions & 0 deletions pkg/mimirtool/commands/analyse_rulefiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
package commands

import (
"sort"

"github.com/alecthomas/kingpin/v2"
"github.com/pkg/errors"
"github.com/prometheus/common/model"

"github.com/grafana/mimir/pkg/mimirtool/analyze"
"github.com/grafana/mimir/pkg/mimirtool/rules"
Expand Down Expand Up @@ -51,5 +54,12 @@ func AnalyzeRuleFiles(ruleFiles []string) (*analyze.MetricsInRuler, error) {
}
}
}
var metricsUsed model.LabelValues
for metric := range output.OverallMetrics {
metricsUsed = append(metricsUsed, model.LabelValue(metric))
}
sort.Sort(metricsUsed)
output.MetricsUsed = metricsUsed

return output, nil
}
43 changes: 43 additions & 0 deletions pkg/mimirtool/commands/analyse_rulefiles_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: AGPL-3.0-only

package commands

import (
"testing"

"github.com/prometheus/common/model"
"github.com/stretchr/testify/require"
)

func TestAnalyzeRuleFiles(t *testing.T) {
mir, err := AnalyzeRuleFiles([]string{"testdata/prometheus_rules.yaml"})
require.NoError(t, err)
require.Equal(t, 24, len(mir.MetricsUsed))
expectedMetrics := model.LabelValues{
"apiserver_request_duration_seconds_bucket",
"apiserver_request_duration_seconds_count",
"apiserver_request_total",
"container_memory_cache",
"container_memory_rss",
"container_memory_swap",
"container_memory_working_set_bytes",
"kube_pod_container_resource_limits",
"kube_pod_container_resource_requests",
"kube_pod_info",
"kube_pod_owner",
"kube_pod_status_phase",
"kube_replicaset_owner",
"kubelet_node_name",
"kubelet_pleg_relist_duration_seconds_bucket",
"node_cpu_seconds_total",
"node_memory_Buffers_bytes",
"node_memory_Cached_bytes",
"node_memory_MemAvailable_bytes",
"node_memory_MemFree_bytes",
"node_memory_Slab_bytes",
"scheduler_binding_duration_seconds_bucket",
"scheduler_e2e_scheduling_duration_seconds_bucket",
"scheduler_scheduling_algorithm_duration_seconds_bucket",
}
require.Equal(t, expectedMetrics, mir.MetricsUsed)
}

0 comments on commit 6a7bee2

Please sign in to comment.