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

AlertmanagerConfig validation for opsgenie_config.responder.type does not allow template strings #4882

Closed
dembaca opened this issue Jun 30, 2022 · 5 comments · Fixed by #6378

Comments

@dembaca
Copy link

dembaca commented Jun 30, 2022

What happened?

According to the Alertmanager documentation a <tmpl_string> should be accepted as value for opsgenie_config.responder.type.

Prometheus Operator refuses to accept a template string (see log output below).

Did you expect to see something different?

I expect a tmpl_string, i.e. a string containing valid go-template code, to be accepted as value for field responder.type.
This tmpl_string must evaluate to ^(team|teams|user|escalation|schedule)$ – but only after template evaluation and not to be valid alertmanager configuration.

Currently this prevents to have it evaluated during alert routing and to dynamically assign responders type (just like name, id, username) according to alert label values.

How to reproduce it (as minimally and precisely as possible):

Try to apply alertmanager config with a responder type as in the manifest snippet below (or any other template string).

responder:
  - type: '{{ .GroupLabels.opsgenie_responder_type }}'

Environment

  • Prometheus Operator version:

    quay.io/prometheus-operator/prometheus-operator:v0.56.3

  • Kubernetes version information:

    v1.21.5

  • Kubernetes cluster kind:

    plain vanilla kubespray cluster

  • Manifests:

kube-prometheus-stack helm values:

...
alertmanager:
  config:
    receivers:
      - name: opsgenie-responder-by-name
        opsgenie_configs:
          - responders:
              - type: '{{ .GroupLabels.opsgenie_responder_type }}'
                name: '{{ .GroupLabels.opsgenie_responder_name }}'
      - name: opsgenie-responder-by-id
        opsgenie_configs:
          - responders:
              - type: '{{ .GroupLabels.opsgenie_responder_type }}'
                id: '{{ .GroupLabels.opsgenie_responder_id }}'
...
  • Prometheus Operator Logs:
level=info ts=2022-06-30T13:26:09.590839794Z caller=operator.go:748 component=alertmanageroperator key=managed-prometheus-apps-dev/apps-dev-alertmanager msg="sync alertmanager"
level=error ts=2022-06-30T13:26:09.595331568Z caller=klog.go:116 component=k8s_client_runtime func=ErrorDepth msg="Sync \"managed-prometheus-apps-dev/apps-dev-alertmanager\" failed: provision alertmanager configuration: failed to initialize from secret: OpsGenieConfig responder { {{ .GroupLabels.opsgenie_responder_name }}  {{ .grouplabels.opsgenie_responder_type }}} type does not match valid options ^(team|teams|user|escalation|schedule)$"

Anything else we need to know?:

Problematic validation on string enum was probably introduced here:
d8454e4

@simonpasquier
Copy link
Contributor

good catch! would you like to submit a fix?

@simonpasquier
Copy link
Contributor

hmm in fact the Alertmanager documentation isn't accurate because the config validation only accepts ^(team|teams|user|escalation|schedule)$.

https://github.com/prometheus/alertmanager/blob/528b9588bf814c394b3111a21c66aab71828131c/config/notifiers.go#L503-L506

@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has not had any activity in the last 60 days. Thank you for your contributions.

@simonpasquier
Copy link
Contributor

Depends on prometheus/alertmanager#3060

@yp969803
Copy link
Contributor

yp969803 commented Mar 8, 2024

/assign

yp969803 added a commit to yp969803/prometheus-operator that referenced this issue Mar 8, 2024
yp969803 added a commit to yp969803/prometheus-operator that referenced this issue Apr 8, 2024
…r#4882)

rfac: OpsGenieConfigResponder Validation

chore: unit tests added
yp969803 added a commit to yp969803/prometheus-operator that referenced this issue Apr 8, 2024
…r#4882)

rfac: OpsGenieConfigResponder Validation

chore: unit tests added

rfac: alertmanagerCfg unit test
simonpasquier added a commit that referenced this issue May 6, 2024
chore: Template string allowed for Responder.Type (#4882)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants