grafana / grafana/alerting

feature request: add sprig library or other library for templating support

Open
#253 2 comments 3 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
89
Forks
74
Avg merge
2d 7h
Merged PRs (30d)
8

Description

Why is this needed:

The Grafana templates are low in features, with not fully oddly documented template functions. They are not documented https://grafana.com/docs/grafana/latest/alerting/fundamentals/notifications/templates/ not at https://grafana.com/docs/grafana/latest/alerting/configure-notifications/template-notifications/reference/ , but at https://grafana.com/docs/grafana/latest/alerting/alerting-rules/templating-labels-annotations/ .

There are not enough functions for good templating.

In particular I am writing grafana alerts where different people have to be tagged on Microsoft Teams depending on if the input label matches a specific regex. It is not possible to if match a label with a regex, it is not possible to split a string.

What would you like to be added:

There is sprig library https://masterminds.github.io/sprig/ . Please add it in all templating contexts to be available.

Who is this feature for?

For any programmers that write grafana alerts.

For example hashicorp/nomad added all sprig library with sprig_ prefix for templating not to break backward compatibility: https://github.com/hashicorp/nomad/blob/0f6561bdfe93d2a5d387c5b0ebbbc946130ed436/command/data_format.go#L108

Thanks!

Contributor guide

Open the contributing guide

Research direction

Start by inventorying the repository's alerting template contexts and their existing function registration, then compare the compatibility approach in the linked Nomad data_format.go example with Sprig's documented functions. Confirm the regex and string-splitting use cases and define what “all templating contexts” covers; done means the selected functions are available without breaking existing templates and are covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.