grafana/oncall

Routing template evaluates the payload correctly yet 'Regular expression is incorrect'

abcdegorov opened this issue · 2 comments

What went wrong?

What happened:
Upon creating a routing template in an Alertmanager integration, the template evaluates to True or False depending on payload, yet I cannot save it due to a 'Regular expression is incorrect' error. Here is the template:

{% set allowed_clusters = ["lab", "dev", "stage"] -%}
{%- set allowed_namespaces = ["argocd", "cert-manager", "dex", "ingress-controller", "kube-system", "logging", "loki", "longhorn-system", "monitoring", "openebs-system"] -%}
{{ true if payload.commonLabels.cluster in allowed_clusters and (payload.commonLabels.namespace in allowed_namespaces or payload.commonLabels.namespace | regex_match(".*-operator")) else false }}

What did you expect to happen:
Since the template correctly evaluates to True of False, it should contain no errors and I must be able to save it

How do we reproduce it?

  1. Open Grafana OnCall and create an Alertmanager integration with the aforementioned routing template
  2. Click the 'Save' button
  3. A 'Regular expression is incorrect' will be displayed

Grafana OnCall Version

v1.4.3

Product Area

Alert Flow & Configuration

Grafana OnCall Platform?

Kubernetes

User's Browser?

Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:125.0) Gecko/20100101 Firefox/125.0

Anything else to add?

No response

After prodding at the expression some more, I have found out that the error is caused by hyphens in variable values (cert-manager, kube-system, etc.). Putting those in a regex_match function works, but why can't I have them as strings?

Looks like a bug where filtering_term_type is not being set so the entire template is being treated as regex instead of jinja2.