Browse Source

Add title and match functions.

Change-Id: Ifd376c2935e22d378e7afa06122642847a237d78
pull/413/head
Brian Brazil 11 years ago committed by Bjoern Rabenstein
parent
commit
cd3592aebc
  1. 3
      templates/templates.go
  2. 10
      templates/templates_test.go

3
templates/templates.go

@ -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)

10
templates/templates_test.go

@ -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…
Cancel
Save