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

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

Closed
abcdegorov opened this issue Apr 19, 2024 · 2 comments · Fixed by #4357
Closed

Comments

@abcdegorov
Copy link

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

@abcdegorov abcdegorov added the bug Something isn't working label Apr 19, 2024
@abcdegorov
Copy link
Author

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?

@mderynck
Copy link
Collaborator

mderynck commented May 3, 2024

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

github-merge-queue bot pushed a commit that referenced this issue May 23, 2024
…4357)

# What this PR does
When editing a jinja route template the filtering_term_type was not
being provided so it was being validated as regex instead. This adds the
missing flag so that the route will use the correct validation. The
reason this was not being hit in the past is most jinja templates were
still passing regex validation.

## Which issue(s) this PR closes

Closes #4259 

<!--
*Note*: if you have more than one GitHub issue that this PR closes, be
sure to preface
each issue link with a [closing
keyword](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue).
This ensures that the issue(s) are auto-closed once the PR has been
merged.
-->

## Checklist

- [ ] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
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