Skip to content

Add queryEscape templating function #17403

@sylr

Description

@sylr

Proposal

My alerts' annotations have URLs that contains label values which have characters which need to be url escaped. Here an alert as seen in incident.io:

Image
diff --git a/template/template.go b/template/template.go
index 295380cc8..d74cefe98 100644
--- a/template/template.go
+++ b/template/template.go
@@ -288,6 +288,9 @@ func NewTemplateExpander(
 				}
 				return float64(time.Duration(v)) / float64(time.Second), nil
 			},
+			"urlQueryEscape": func(s string) string {
+				return url.QueryEscape(s)
+			},
 		},
 		options: options,
 	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions