Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new command on mimirtool used to render template #7325

Merged
merged 8 commits into from
Feb 16, 2024

Conversation

ncharaf
Copy link
Contributor

@ncharaf ncharaf commented Feb 7, 2024

What this PR does

Add a new command on mimirtool useful to render template since mimir has some custom function that are not available in amtool.

This PR is based on this

I faced some issue when working on alert template i was using amtool to render template but cannot use grafanaExploreURL

Checklist

  • Tests updated.
  • Documentation added.
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX].
  • about-versioning.md updated with experimental features.

@ncharaf ncharaf requested review from a team as code owners February 7, 2024 20:19
@CLAassistant
Copy link

CLAassistant commented Feb 7, 2024

CLA assistant check
All committers have signed the CLA.

@ncharaf ncharaf force-pushed the dev/ncharaf/add-template-render branch 4 times, most recently from 26e4ad8 to 9e688d0 Compare February 7, 2024 20:49
@ncharaf ncharaf requested a review from a team as a code owner February 7, 2024 20:49
@ncharaf ncharaf force-pushed the dev/ncharaf/add-template-render branch from 9e688d0 to 4581b2d Compare February 7, 2024 20:54
pkg/mimirtool/commands/template_render.go Outdated Show resolved Hide resolved
@@ -48,6 +48,10 @@ Mimirtool is a command-line tool that operators and tenants can use to execute a

For more information about the `backfill` command, refer to [Backfill]({{< relref "#backfill" >}})

- The `template` command enables you to render your alertmanager template.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding a new top-level command template, please make render be a subcommand of alertmanager: mimirtool alertmanager render <...>

Copy link
Contributor Author

@ncharaf ncharaf Feb 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got your point . I can change it but it might be confusing since it's doesn't do any interaction with the alertmanager that's why i used a new top-level command

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved

alertmanager render --template-glob=TEMPLATE-GLOB --template-text=TEMPLATE-TEXT [<flags>]
    Render a given definition in a template file to standard output.

nabil@laptop:~/mimir# go run cmd/mimirtool/main.go alertmanager --help
usage: mimirtool alertmanager [<flags>] <command> [<args> ...]

View and edit Alertmanager configurations that are stored in Grafana Mimir.


Flags:
  --[no-]help                 Show context-sensitive help (also try --help-long and --help-man).
  --log.level="info"          set level of the logger
  --push-gateway.endpoint=PUSH-GATEWAY.ENDPOINT
                              url for the push-gateway to register metrics
  --push-gateway.job=PUSH-GATEWAY.JOB
                              job name to register metrics
  --push-gateway.interval=1m  interval to forward metrics to the push gateway
  --user=""                   Basic auth API user to use when contacting Grafana Mimir; alternatively, set MIMIR_API_USER. If empty, MIMIR_TENANT_ID is used instead. ($MIMIR_API_USER)
  --key=""                    Basic auth API key to use when contacting Grafana Mimir; alternatively, set MIMIR_API_KEY. ($MIMIR_API_KEY)
  --tls-ca-path=""            TLS CA certificate to verify Grafana Mimir API as part of mTLS; alternatively, set MIMIR_TLS_CA_PATH. ($MIMIR_TLS_CA_PATH)
  --tls-cert-path=""          TLS client certificate to authenticate with the Grafana Mimir API as part of mTLS; alternatively, set MIMIR_TLS_CERT_PATH. ($MIMIR_TLS_CERT_PATH)
  --tls-key-path=""           TLS client certificate private key to authenticate with the Grafana Mimir API as part of mTLS; alternatively, set MIMIR_TLS_KEY_PATH. ($MIMIR_TLS_KEY_PATH)
  --[no-]tls-insecure-skip-verify
                              Skip TLS certificate verification; alternatively, set MIMIR_TLS_INSECURE_SKIP_VERIFY. ($MIMIR_TLS_INSECURE_SKIP_VERIFY)
  --auth-token=""             Authentication token bearer authentication; alternatively, set MIMIR_AUTH_TOKEN. ($MIMIR_AUTH_TOKEN)
  --[no-]utf8-strict-mode     Enable UTF-8 strict mode. Allows UTF-8 characters in the matchers for routes and inhibition rules, in silences, and in the labels for alerts.

Subcommands:
alertmanager get --address=ADDRESS --id=ID [<flags>]
    Get the Alertmanager configuration that is currently in the Grafana Mimir Alertmanager.

alertmanager delete --address=ADDRESS --id=ID
    Delete the Alertmanager configuration that is currently in the Grafana Mimir Alertmanager.

alertmanager load --address=ADDRESS --id=ID <config> [<template-files>...]
    Load Alertmanager tenant configuration and template files into Grafana Mimir.

alertmanager verify <config> [<template-files>...]
    Verify Alertmanager tenant configuration and template files.

alertmanager render --template-glob=TEMPLATE-GLOB --template-text=TEMPLATE-TEXT [<flags>]
    Render a given definition in a template file to standard output.


nabil@laptop:~/mimir# go run cmd/mimirtool/main.go alertmanager  render --help
usage: mimirtool alertmanager render --template-glob=TEMPLATE-GLOB --template-text=TEMPLATE-TEXT [<flags>]

Render a given definition in a template file to standard output.


Flags:
  --[no-]help                    Show context-sensitive help (also try --help-long and --help-man).
  --log.level="info"             set level of the logger
  --push-gateway.endpoint=PUSH-GATEWAY.ENDPOINT
                                 url for the push-gateway to register metrics
  --push-gateway.job=PUSH-GATEWAY.JOB
                                 job name to register metrics
  --push-gateway.interval=1m     interval to forward metrics to the push gateway
  --user=""                      Basic auth API user to use when contacting Grafana Mimir; alternatively, set MIMIR_API_USER. If empty, MIMIR_TENANT_ID is used instead. ($MIMIR_API_USER)
  --key=""                       Basic auth API key to use when contacting Grafana Mimir; alternatively, set MIMIR_API_KEY. ($MIMIR_API_KEY)
  --tls-ca-path=""               TLS CA certificate to verify Grafana Mimir API as part of mTLS; alternatively, set MIMIR_TLS_CA_PATH. ($MIMIR_TLS_CA_PATH)
  --tls-cert-path=""             TLS client certificate to authenticate with the Grafana Mimir API as part of mTLS; alternatively, set MIMIR_TLS_CERT_PATH. ($MIMIR_TLS_CERT_PATH)
  --tls-key-path=""              TLS client certificate private key to authenticate with the Grafana Mimir API as part of mTLS; alternatively, set MIMIR_TLS_KEY_PATH. ($MIMIR_TLS_KEY_PATH)
  --[no-]tls-insecure-skip-verify
                                 Skip TLS certificate verification; alternatively, set MIMIR_TLS_INSECURE_SKIP_VERIFY. ($MIMIR_TLS_INSECURE_SKIP_VERIFY)
  --auth-token=""                Authentication token bearer authentication; alternatively, set MIMIR_AUTH_TOKEN. ($MIMIR_AUTH_TOKEN)
  --[no-]utf8-strict-mode        Enable UTF-8 strict mode. Allows UTF-8 characters in the matchers for routes and inhibition rules, in silences, and in the labels for alerts.
  --template-glob=TEMPLATE-GLOB ...
                                 Glob of paths that will be expanded and used for rendering.
  --template-text=TEMPLATE-TEXT  The template that will be rendered.
  --template-type=TEMPLATE-TYPE  The type of the template. Can be either text (default) or html.
  --template-data=TEMPLATE-DATA  Full path to a file which contains the data of the alert(-s) with which the --template-text will be rendered. Must be in JSON. File must be formatted
                                 according to the following layout: https://pkg.go.dev/github.com/prometheus/alertmanager/template#Data. If none has been specified then a predefined,
                                 simple alert will be used for rendering.
  --id=""                        Basic auth username to use when contacting Prometheus or Grafana Mimir, also set as tenant ID; alternatively, set MIMIR_TENANT_ID. ($MIMIR_TENANT_ID)

pkg/mimirtool/commands/template.go Outdated Show resolved Hide resolved
pkg/mimirtool/commands/template_render.go Outdated Show resolved Hide resolved
pkg/mimirtool/commands/template_render.go Show resolved Hide resolved
pkg/mimirtool/commands/template_render_test.go Outdated Show resolved Hide resolved
pkg/mimirtool/commands/testdata/template/alert_data1.json Outdated Show resolved Hide resolved
ncharaf and others added 2 commits February 14, 2024 21:03
Co-authored-by: Nick Pillitteri <56quarters@users.noreply.github.com>
Co-authored-by: Nick Pillitteri <56quarters@users.noreply.github.com>
@ncharaf ncharaf force-pushed the dev/ncharaf/add-template-render branch 2 times, most recently from d22ec9d to 6ddbb07 Compare February 14, 2024 22:18
Copy link
Member

@jdbaldry jdbaldry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding some docs too!

I've added some suggestions to help make things more clear to a first time reader.

docs/sources/mimir/manage/tools/mimirtool.md Outdated Show resolved Hide resolved
docs/sources/mimir/manage/tools/mimirtool.md Show resolved Hide resolved
Comment on lines 187 to 188

It can also take a glob path that will be expended.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given my other suggestion to move the options description before the comand example, I believe this can be removed.

Suggested change
It can also take a glob path that will be expended.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modification made. Is that okay for you ?

docs/sources/mimir/manage/tools/mimirtool.md Outdated Show resolved Hide resolved
Copy link
Contributor

@56quarters 56quarters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM after the changes from @jdbaldry are implemented. @gotjosh or @grobinson-grafana, do you have any concerns about this new mimirtool AM command?

Co-authored-by: Jack Baldry <jack.baldry@grafana.com>
@ncharaf ncharaf force-pushed the dev/ncharaf/add-template-render branch from 5a3c279 to 433c973 Compare February 15, 2024 20:40
Copy link
Contributor

@56quarters 56quarters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@56quarters 56quarters merged commit 2b8eb00 into grafana:main Feb 16, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants