prometheus / prometheus/alertmanager
Feature Request: Add in functions to convert variable types in templates
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 8.6k
- Forks
- 2.5k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 61
Description
What did you do?
Writing template for email alert notifications
What did you expect to see?
A function to convert strings to ints, floats
What did you see instead? Under which circumstances?
I have not been able to find any functions for type conversion or syntax for type casting
Environment
- System information:
Linux 4.13.12-1.el7.elrepo.x86_64 x86_64
- Alertmanager version:
0.23.0
- Prometheus version:
v2.32.1
- Alertmanager configuration file:
{{range .Annotations.SortedPairs}}{{if (eq .Name "value")}}{{$temp_value = .Value float64}}{{if (ne ($temp_value | printf "%f") ($disk_value | printf "%f"))}}{{$disk_value = .Value | printf "%f"}}
- Prometheus configuration file:
N/A
- Logs:
header template: template: :1: function \"float64\" not defined"
I have tried many iterations of similar lines of code trying to cast the variables as floats in order to compare the values, but have had no luck thus far. I've printed the variable types before assignment and they are float64, but after assigning to .Value both variable types are string.
Is there any method for converting strings to floats? Or more specific to my problem, a way to compare numeric string values against each other? Ie. {{if gt "27.43" "87.39"}}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Alertmanager's email notification templates and the undefined float64 function shown in the error. Trace how template functions and .Value are handled, then define the supported conversion and numeric-comparison behavior and verify the examples in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100