Skip to content

Commit 2e52389

Browse files
authored
Adds bearer token support for mimirtool's analyze ruler/prometheus co… (#9587)
* Adds bearer token support for mimirtool's analyze ruler/prometheus commands * Update with suggested verbiage * Group changelog update with other enhancements * Run 'make docs' for formatting
1 parent 42284e7 commit 2e52389

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
* [FEATURE] Alertmanager: limit added for maximum size of the Grafana state (`-alertmanager.max-grafana-state-size-bytes`). #9475
2828
* [FEATURE] Alertmanager: limit added for maximum size of the Grafana configuration (`-alertmanager.max-config-size-bytes`). #9402
2929
* [FEATURE] Ingester: Experimental support for ingesting out-of-order native histograms. This is disabled by default and can be enabled by setting `-ingester.ooo-native-histograms-ingestion-enabled` to `true`. #7175
30+
* [ENHANCEMENT] mimirtool: Adds bearer token support for mimirtool's analyze ruler/prometheus commands. #9587
3031
* [ENHANCEMENT] Ruler: Support `exclude_alerts` parameter in `<prometheus-http-prefix>/api/v1/rules` endpoint. #9300
3132
* [ENHANCEMENT] Distributor: add a metric to track tenants who are sending newlines in their label values called `cortex_distributor_label_values_with_newlines_total`. #9400
3233
* [ENHANCEMENT] Ingester: improve performance of reading the WAL. #9508

docs/sources/mimir/manage/tools/mimirtool.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -729,12 +729,13 @@ mimirtool analyze ruler --address=<url> --id=<tenant_id>
729729

730730
##### Configuration
731731

732-
| Environment variable | Flag | Description |
733-
| -------------------- | ----------- | ----------------------------------------------------------------------------------------------- |
734-
| `MIMIR_ADDRESS` | `--address` | Sets the address of the Prometheus instance. |
735-
| `MIMIR_TENANT_ID` | `--id` | Sets the basic auth username. If you're using Grafana Cloud, this variable is your instance ID. |
736-
| `MIMIR_API_KEY` | `--key` | Sets the basic auth password. If you're using Grafana Cloud, this variable is your API key. |
737-
| - | `--output` | Sets the output file path, which by default is `metrics-in-ruler.json`. |
732+
| Environment variable | Flag | Description |
733+
| -------------------- | -------------- | --------------------------------------------------------------------------------------------------------- |
734+
| `MIMIR_ADDRESS` | `--address` | Sets the address of the Prometheus instance. |
735+
| `MIMIR_TENANT_ID` | `--id` | Sets the basic authentication username. If you're using Grafana Cloud, this variable is your instance ID. |
736+
| `MIMIR_API_KEY` | `--key` | Sets the basic authentication password. If you're using Grafana Cloud, this variable is your API key. |
737+
| `MIMIR_AUTH_TOKEN` | `--auth-token` | Sets the bearer or JWT token that is required for Mimir clusters authenticating with this method. |
738+
| - | `--output` | Sets the output file path, which by default is `metrics-in-ruler.json`. |
738739

739740
##### Example output file
740741

@@ -809,15 +810,16 @@ mimirtool analyze prometheus --address=<url> --id=<tenant_id>
809810

810811
##### Configuration
811812

812-
| Environment variable | Flag | Description |
813-
| -------------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
814-
| `MIMIR_ADDRESS` | `--address` | Sets the address of the Prometheus instance. |
815-
| `MIMIR_TENANT_ID` | `--id` | Sets the basic auth username. If you're using Grafana Cloud this variable is your instance ID, also set as tenant ID. |
816-
| `MIMIR_API_KEY` | `--key` | Sets the basic auth password. If you're using Grafana Cloud, this variable is your API key. |
817-
| - | `--grafana-metrics-file` | `mimirtool analyze grafana` or `mimirtool analyze dashboard` output file, which by default is `metrics-in-grafana.json`. |
818-
| - | `--ruler-metrics-file` | `mimirtool analyze ruler` or `mimirtool analyze rule-file` output file, which by default is `metrics-in-ruler.json`. |
819-
| - | `--output` | Sets the output file path, which by default is `prometheus-metrics.json`. |
820-
| - | `--prometheus-http-prefix` | Sets the HTTP URL path under which the Prometheus api will be served. |
813+
| Environment variable | Flag | Description |
814+
| -------------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
815+
| `MIMIR_ADDRESS` | `--address` | Sets the address of the Prometheus instance. |
816+
| `MIMIR_TENANT_ID` | `--id` | Sets the basic authentication username. If you're using Grafana Cloud this variable is your instance ID, also set as tenant ID. |
817+
| `MIMIR_API_KEY` | `--key` | Sets the basic authentication password. If you're using Grafana Cloud, this variable is your API key. |
818+
| `MIMIR_AUTH_TOKEN` | `--auth-token` | Sets the bearer or JWT token that is required for Mimir clusters authenticating with this method. |
819+
| - | `--grafana-metrics-file` | `mimirtool analyze grafana` or `mimirtool analyze dashboard` output file, which by default is `metrics-in-grafana.json`. |
820+
| - | `--ruler-metrics-file` | `mimirtool analyze ruler` or `mimirtool analyze rule-file` output file, which by default is `metrics-in-ruler.json`. |
821+
| - | `--output` | Sets the output file path, which by default is `prometheus-metrics.json`. |
822+
| - | `--prometheus-http-prefix` | Sets the HTTP URL path under which the Prometheus api will be served. |
821823

822824
##### Example output
823825

pkg/mimirtool/commands/analyse.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ func (cmd *AnalyzeCommand) Register(app *kingpin.Application, envVars EnvVarName
2626
prometheusAnalyzeCmd.Flag("prometheus-http-prefix", "HTTP URL path under which the Prometheus api will be served.").
2727
Default("").
2828
StringVar(&paCmd.prometheusHTTPPrefix)
29+
prometheusAnalyzeCmd.Flag("auth-token", "Authentication token bearer authentication; alternatively, set "+envVars.AuthToken+".").
30+
Default("").
31+
Envar(envVars.AuthToken).
32+
StringVar(&paCmd.authToken)
2933
prometheusAnalyzeCmd.Flag("id", "Basic auth username to use when contacting Prometheus or Grafana Mimir, also set as tenant ID; alternatively, set "+envVars.TenantID+".").
3034
Envar(envVars.TenantID).
3135
Default("").
@@ -88,6 +92,10 @@ func (cmd *AnalyzeCommand) Register(app *kingpin.Application, envVars EnvVarName
8892
rulerAnalyzeCmd.Flag("output", "The path for the output file").
8993
Default("metrics-in-ruler.json").
9094
StringVar(&raCmd.outputFile)
95+
rulerAnalyzeCmd.Flag("auth-token", "Authentication token bearer authentication; alternatively, set "+envVars.AuthToken+".").
96+
Default("").
97+
Envar(envVars.AuthToken).
98+
StringVar(&raCmd.ClientConfig.AuthToken)
9199

92100
daCmd := &DashboardAnalyzeCommand{}
93101
dashboardAnalyzeCmd := analyzeCmd.Command("dashboard", "Analyze and output the metrics used in Grafana dashboard files").Action(daCmd.run)

pkg/mimirtool/commands/analyse_prometheus.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type PrometheusAnalyzeCommand struct {
3535
prometheusHTTPPrefix string
3636
username string
3737
password string
38+
authToken string
3839
readTimeout time.Duration
3940

4041
grafanaMetricsFile string
@@ -89,7 +90,9 @@ func (cmd *PrometheusAnalyzeCommand) parseUsedMetrics() (model.LabelValues, erro
8990
func (cmd *PrometheusAnalyzeCommand) newAPI() (v1.API, error) {
9091
rt := api.DefaultRoundTripper
9192
rt = config.NewUserAgentRoundTripper(client.UserAgent(), rt)
92-
if cmd.username != "" {
93+
if cmd.authToken != "" {
94+
rt = config.NewAuthorizationCredentialsRoundTripper("Bearer", config.NewInlineSecret(cmd.authToken), rt)
95+
} else if cmd.username != "" {
9396
rt = &setTenantIDTransport{
9497
RoundTripper: rt,
9598
tenantID: cmd.username,

0 commit comments

Comments
 (0)