Skip to content

Commit

Permalink
Fix .metricsUsed in mimirtool analyze rule-file (#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 #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]>
(cherry picked from commit 6a7bee2)
Signed-off-by: Oleg Zaytsev <[email protected]>
  • Loading branch information
colega committed Dec 18, 2023
1 parent 34f2602 commit b50df11
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 @@ -148,6 +148,7 @@
* [BUGFIX] Fix the issue where `--read-timeout` was applied to the entire `mimirtool analyze grafana` invocation rather than to individual Grafana API calls. #5915
* [BUGFIX] Fix incorrect remote-read path joining for `mimirtool remote-read` commands on Windows. #6011
* [BUGFIX] Fix template files full path being sent in `mimirtool alertmanager load` command. #6138
* [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 b50df11

Please sign in to comment.