Print offsets in promql.

This commit is contained in:
Brian Brazil 2015-11-15 09:26:38 +00:00
parent 7a6a0630d1
commit a287264989
2 changed files with 21 additions and 3 deletions

View file

@ -17,6 +17,7 @@ import (
"fmt"
"sort"
"strings"
"time"
"github.com/prometheus/common/model"
@ -174,7 +175,11 @@ func (node *MatrixSelector) String() string {
Name: node.Name,
LabelMatchers: node.LabelMatchers,
}
return fmt.Sprintf("%s[%s]", vecSelector.String(), strutil.DurationToString(node.Range))
offset := ""
if node.Offset != time.Duration(0) {
offset = fmt.Sprintf(" OFFSET %s", strutil.DurationToString(node.Offset))
}
return fmt.Sprintf("%s[%s]%s", vecSelector.String(), strutil.DurationToString(node.Range), offset)
}
func (node *NumberLiteral) String() string {
@ -202,10 +207,14 @@ func (node *VectorSelector) String() string {
}
labelStrings = append(labelStrings, matcher.String())
}
offset := ""
if node.Offset != time.Duration(0) {
offset = fmt.Sprintf(" OFFSET %s", strutil.DurationToString(node.Offset))
}
if len(labelStrings) == 0 {
return node.Name
return fmt.Sprintf("%s%s", node.Name, offset)
}
sort.Strings(labelStrings)
return fmt.Sprintf("%s{%s}", node.Name, strings.Join(labelStrings, ","))
return fmt.Sprintf("%s{%s}%s", node.Name, strings.Join(labelStrings, ","), offset)
}

View file

@ -33,6 +33,15 @@ func TestExprString(t *testing.T) {
{
in: `up > BOOL 0`,
},
{
in: `a OFFSET 1m`,
},
{
in: `a{c="d"}[5m] OFFSET 1m`,
},
{
in: `a[5m] OFFSET 1m`,
},
}
for _, test := range inputs {