Skip to content

Commit

Permalink
also add user to alertmanager command
Browse files Browse the repository at this point in the history
  • Loading branch information
kubicgruenfeld committed May 28, 2021
1 parent da9c5c0 commit 19fd3f9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ Config commands interact with the Cortex api and read/create/update/delete user
| Env Variables | Flag | Description |
| ----------------- | --------- | ------------------------------------------------------------------------------------------------------------- |
| CORTEX_ADDRESS | `address` | Address of the API of the desired Cortex cluster. |
| CORTEX_API_KEY | `key` | In cases where the Cortex API is set behind a basic auth gateway, an key can be set as a basic auth password. |
| CORTEX_API_USER | `user` | In cases where the Cortex API is set behind a basic auth gateway, an user can be set as a basic auth user. If empty and CORTEX_API_KEY is set, TENANT_ID will be used as default. |
| CORTEX_API_KEY | `key` | In cases where the Cortex API is set behind a basic auth gateway, a key can be set as a basic auth password. |
| CORTEX_TENANT_ID | `id` | The tenant ID of the Cortex instance to interact with. |

#### Alertmanager
Expand Down
4 changes: 4 additions & 0 deletions pkg/alerting/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type RunnerConfig struct {
AlertmanagerID string
RulerURL string
RulerID string
User string
Key string

RulesConfigFile string
Expand All @@ -62,6 +63,7 @@ func (cfg *RunnerConfig) RegisterFlags(f *flag.FlagSet) {
f.StringVar(&cfg.RulerURL, "configs.ruler-url", "", "The URL under the Ruler is reachable")
f.StringVar(&cfg.RulerID, "configs.ruler-id", "", "The user ID of the Ruler tenant")

f.StringVar(&cfg.User, "configs.user", "", "The API user to use for syncing configuration. The same user is used for both the alertmanager and ruler. If empty, the ID wil be used.")
f.StringVar(&cfg.Key, "configs.key", "", "The API key to use for syncing configuration. The same key is used for both the alertmanager and ruler.")
f.DurationVar(&cfg.ConfigSyncInterval, "configs.sync-interval", 30*time.Minute, "How often should we sync the configuration with the ruler and alertmanager")
}
Expand All @@ -88,6 +90,7 @@ func NewRunner(cfg RunnerConfig, logger log.Logger) (*Runner, error) {
amClient, err := client.New(client.Config{
Address: cfg.AlertmanagerURL,
ID: cfg.AlertmanagerID,
User: cfg.User,
Key: cfg.Key,
})
if err != nil {
Expand All @@ -98,6 +101,7 @@ func NewRunner(cfg RunnerConfig, logger log.Logger) (*Runner, error) {
rulerClient, err := client.New(client.Config{
Address: cfg.RulerURL,
ID: cfg.RulerID,
User: cfg.User,
Key: cfg.Key,
})
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions pkg/commands/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (a *AlertmanagerCommand) Register(app *kingpin.Application) {
alertCmd := app.Command("alertmanager", "View & edit alertmanager configs stored in cortex.").PreAction(a.setup)
alertCmd.Flag("address", "Address of the cortex cluster, alternatively set CORTEX_ADDRESS.").Envar("CORTEX_ADDRESS").Required().StringVar(&a.ClientConfig.Address)
alertCmd.Flag("id", "Cortex tenant id, alternatively set CORTEX_TENANT_ID.").Envar("CORTEX_TENANT_ID").Required().StringVar(&a.ClientConfig.ID)
alertCmd.Flag("user", "Api user to use when contacting cortex, alternatively set CORTEX_API_USER. If empty, ID will be used.").Default("").Envar("CORTEX_API_USER").StringVar(&a.ClientConfig.User)
alertCmd.Flag("key", "Api key to use when contacting cortex, alternatively set CORTEX_API_KEY.").Default("").Envar("CORTEX_API_KEY").StringVar(&a.ClientConfig.Key)
alertCmd.Flag("tls-ca-path", "TLS CA certificate to verify cortex API as part of mTLS, alternatively set CORTEX_TLS_CA_PATH.").Default("").Envar("CORTEX_TLS_CA_PATH").StringVar(&a.ClientConfig.TLS.CAPath)
alertCmd.Flag("tls-cert-path", "TLS client certificate to authenticate with cortex API as part of mTLS, alternatively set CORTEX_TLS_CERT_PATH.").Default("").Envar("CORTEX_TLS_CERT_PATH").StringVar(&a.ClientConfig.TLS.CertPath)
Expand Down Expand Up @@ -141,6 +142,7 @@ func (a *AlertCommand) Register(app *kingpin.Application) {
alertCmd := app.Command("alerts", "View active alerts in alertmanager.").PreAction(a.setup)
alertCmd.Flag("address", "Address of the cortex cluster, alternatively set CORTEX_ADDRESS.").Envar("CORTEX_ADDRESS").Required().StringVar(&a.ClientConfig.Address)
alertCmd.Flag("id", "Cortex tenant id, alternatively set CORTEX_TENANT_ID.").Envar("CORTEX_TENANT_ID").Required().StringVar(&a.ClientConfig.ID)
alertCmd.Flag("user", "Api user to use when contacting cortex, alternatively set CORTEX_API_USER. If empty, ID will be used.").Default("").Envar("CORTEX_API_USER").StringVar(&a.ClientConfig.User)
alertCmd.Flag("key", "Api key to use when contacting cortex, alternatively set CORTEX_API_KEY.").Default("").Envar("CORTEX_API_KEY").StringVar(&a.ClientConfig.Key)

verifyAlertsCmd := alertCmd.Command("verify", "Verifies alerts in an alertmanager cluster are deduplicated; useful for verifying correct configuration when transferring from Prometheus to Cortex alert evaluation.").Action(a.verifyConfig)
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type RuleCommand struct {
// Register rule related commands and flags with the kingpin application
func (r *RuleCommand) Register(app *kingpin.Application) {
rulesCmd := app.Command("rules", "View & edit rules stored in cortex.").PreAction(r.setup)
rulesCmd.Flag("user", "Api user to use when contacting cortex, alternatively set $CORTEX_API_USER.").Default("").Envar("CORTEX_API_USER").StringVar(&r.ClientConfig.User)
rulesCmd.Flag("user", "Api user to use when contacting cortex, alternatively set $CORTEX_API_USER. If empty, ID will be used.").Default("").Envar("CORTEX_API_USER").StringVar(&r.ClientConfig.User)
rulesCmd.Flag("key", "Api key to use when contacting cortex, alternatively set $CORTEX_API_KEY.").Default("").Envar("CORTEX_API_KEY").StringVar(&r.ClientConfig.Key)
rulesCmd.Flag("backend", "Backend type to interact with: <cortex|loki>").Default("cortex").EnumVar(&r.Backend, backends...)

Expand Down

0 comments on commit 19fd3f9

Please sign in to comment.