Add title and match functions.

Change-Id: Ifd376c2935e22d378e7afa06122642847a237d78
This commit is contained in:
Brian Brazil 2014-06-05 18:44:19 +01:00
parent af8a1b9d78
commit 6003cdbae0
2 changed files with 13 additions and 0 deletions

View File

@ -20,6 +20,7 @@ import (
"math"
"regexp"
"sort"
"strings"
"text/template"
clientmodel "github.com/prometheus/client_golang/model"
@ -92,6 +93,8 @@ func Expand(text string, name string, data interface{}, timestamp clientmodel.Ti
re := regexp.MustCompile(pattern)
return re.ReplaceAllString(text, repl)
},
"match": regexp.MatchString,
"title": strings.Title,
"sortByLabel": func(label string, v queryResult) queryResult {
sorter := queryResultByLabelSorter{v[:], label}
sort.Stable(sorter)

View File

@ -89,6 +89,16 @@ func TestTemplateExpansion(t *testing.T) {
text: "{{ 0.0 | humanize1024 }}:{{ 1.0 | humanize1024 }}:{{ 1048576.0 | humanize1024 }}:{{ .12 | humanize1024}}",
output: "0 :1 :1 Mi:0.12 ",
},
{
// Title.
text: "{{ \"aa bb CC\" | title }}",
output: "Aa Bb CC",
},
{
// Match.
text: "{{ match \"a+\" \"aa\" }} {{ match \"a+\" \"b\" }}",
output: "true false",
},
}
time := clientmodel.Timestamp(0)