mirror of
https://github.com/prometheus/prometheus.git
synced 2025-12-04 09:01:02 +01:00
Merge pull request #17354 from prometheus/fix-smoothed-anchored-formatting
Fix formatting of range vector selectors with smoothed/anchored modifier
This commit is contained in:
commit
a3e404755b
@ -229,7 +229,6 @@ func (node *Call) ShortString() string {
|
||||
}
|
||||
|
||||
func (node *MatrixSelector) atOffset() (string, string) {
|
||||
// Copy the Vector selector before changing the offset
|
||||
vecSelector := node.VectorSelector.(*VectorSelector)
|
||||
offset := ""
|
||||
switch {
|
||||
@ -254,20 +253,21 @@ func (node *MatrixSelector) atOffset() (string, string) {
|
||||
|
||||
func (node *MatrixSelector) String() string {
|
||||
at, offset := node.atOffset()
|
||||
// Copy the Vector selector before changing the offset
|
||||
// Copy the Vector selector so we can modify it to not print @, offset, and other modifiers twice.
|
||||
vecSelector := *node.VectorSelector.(*VectorSelector)
|
||||
// Do not print the @ and offset twice.
|
||||
offsetVal, offsetExprVal, atVal, preproc := vecSelector.OriginalOffset, vecSelector.OriginalOffsetExpr, vecSelector.Timestamp, vecSelector.StartOrEnd
|
||||
anchored, smoothed := vecSelector.Anchored, vecSelector.Smoothed
|
||||
vecSelector.OriginalOffset = 0
|
||||
vecSelector.OriginalOffsetExpr = nil
|
||||
vecSelector.Timestamp = nil
|
||||
vecSelector.StartOrEnd = 0
|
||||
vecSelector.Anchored = false
|
||||
vecSelector.Smoothed = false
|
||||
|
||||
extendedAttribute := ""
|
||||
switch {
|
||||
case vecSelector.Anchored:
|
||||
case anchored:
|
||||
extendedAttribute = " anchored"
|
||||
case vecSelector.Smoothed:
|
||||
case smoothed:
|
||||
extendedAttribute = " smoothed"
|
||||
}
|
||||
rangeStr := model.Duration(node.Range).String()
|
||||
@ -276,8 +276,6 @@ func (node *MatrixSelector) String() string {
|
||||
}
|
||||
str := fmt.Sprintf("%s[%s]%s%s%s", vecSelector.String(), rangeStr, extendedAttribute, at, offset)
|
||||
|
||||
vecSelector.OriginalOffset, vecSelector.OriginalOffsetExpr, vecSelector.Timestamp, vecSelector.StartOrEnd = offsetVal, offsetExprVal, atVal, preproc
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
|
||||
@ -115,6 +115,36 @@ func TestExprString(t *testing.T) {
|
||||
{
|
||||
in: `a[1h:5m] offset 1m`,
|
||||
},
|
||||
{
|
||||
in: `a anchored`,
|
||||
},
|
||||
{
|
||||
in: `a[5m] anchored`,
|
||||
},
|
||||
{
|
||||
in: `a{b="c"}[5m] anchored`,
|
||||
},
|
||||
{
|
||||
in: `a{b="c"}[5m] anchored offset 1m`,
|
||||
},
|
||||
{
|
||||
in: `a{b="c"}[5m] anchored @ start() offset 1m`,
|
||||
},
|
||||
{
|
||||
in: `a smoothed`,
|
||||
},
|
||||
{
|
||||
in: `a[5m] smoothed`,
|
||||
},
|
||||
{
|
||||
in: `a{b="c"}[5m] smoothed`,
|
||||
},
|
||||
{
|
||||
in: `a{b="c"}[5m] smoothed offset 1m`,
|
||||
},
|
||||
{
|
||||
in: `a{b="c"}[5m] smoothed @ start() offset 1m`,
|
||||
},
|
||||
{
|
||||
in: `{__name__="a"}`,
|
||||
},
|
||||
@ -222,6 +252,11 @@ func TestExprString(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
EnableExtendedRangeSelectors = true
|
||||
t.Cleanup(func() {
|
||||
EnableExtendedRangeSelectors = false
|
||||
})
|
||||
|
||||
for _, test := range inputs {
|
||||
t.Run(test.in, func(t *testing.T) {
|
||||
expr, err := ParseExpr(test.in)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user