add negative offset to printer

Signed-off-by: schou <pschou@users.noreply.github.com>
This commit is contained in:
schou 2021-02-23 21:16:28 -05:00
parent f80b52be69
commit 3bafe17870
2 changed files with 15 additions and 3 deletions

View file

@ -116,8 +116,10 @@ func (node *MatrixSelector) String() string {
// Copy the Vector selector before changing the offset
vecSelector := *node.VectorSelector.(*VectorSelector)
offset := ""
if vecSelector.OriginalOffset != time.Duration(0) {
if vecSelector.OriginalOffset > time.Duration(0) {
offset = fmt.Sprintf(" offset %s", model.Duration(vecSelector.OriginalOffset))
} else if vecSelector.OriginalOffset < time.Duration(0) {
offset = fmt.Sprintf(" offset -%s", model.Duration(-vecSelector.OriginalOffset))
}
at := ""
if vecSelector.Timestamp != nil {
@ -147,8 +149,10 @@ func (node *SubqueryExpr) String() string {
step = model.Duration(node.Step).String()
}
offset := ""
if node.OriginalOffset != time.Duration(0) {
if node.OriginalOffset > time.Duration(0) {
offset = fmt.Sprintf(" offset %s", model.Duration(node.OriginalOffset))
} else if node.OriginalOffset < time.Duration(0) {
offset = fmt.Sprintf(" offset -%s", model.Duration(-node.OriginalOffset))
}
at := ""
if node.Timestamp != nil {
@ -187,8 +191,10 @@ func (node *VectorSelector) String() string {
labelStrings = append(labelStrings, matcher.String())
}
offset := ""
if node.OriginalOffset != time.Duration(0) {
if node.OriginalOffset > time.Duration(0) {
offset = fmt.Sprintf(" offset %s", model.Duration(node.OriginalOffset))
} else if node.OriginalOffset < time.Duration(0) {
offset = fmt.Sprintf(" offset -%s", model.Duration(-node.OriginalOffset))
}
at := ""
if node.Timestamp != nil {

View file

@ -77,12 +77,18 @@ func TestExprString(t *testing.T) {
{
in: `a offset 1m`,
},
{
in: `a offset -7m`,
},
{
in: `a{c="d"}[5m] offset 1m`,
},
{
in: `a[5m] offset 1m`,
},
{
in: `a[12m] offset -3m`,
},
{
in: `a[1h:5m] offset 1m`,
},