Add title and match functions.
Change-Id: Ifd376c2935e22d378e7afa06122642847a237d78
This commit is contained in:
parent
af8a1b9d78
commit
6003cdbae0
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue