-
Notifications
You must be signed in to change notification settings - Fork 550
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into krajo/wip-rw2
- Loading branch information
Showing
38 changed files
with
1,607 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
# This file can be used to set overrides or other runtime config. | ||
overrides: | ||
anonymous: | ||
active_series_custom_trackers: | ||
base_mimir_write: '{job="mimir-read-write-mode/mimir-write"}' | ||
base_mimir_read: '{job="mimir-read-write-mode/mimir-read"}' | ||
active_series_additional_custom_trackers: | ||
additional_mimir_backend: '{job="mimir-read-write-mode/mimir-backend"}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
pkg/frontend/querymiddleware/astmapper/prom2_range_compat.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
package astmapper | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/prometheus/prometheus/promql/parser" | ||
) | ||
|
||
// NewProm2RangeCompat creates a new ASTMapper which modifies the range of subqueries | ||
// with identical ranges and steps (which used to returns results in Prometheus 2 since | ||
// range selectors were left closed right closed) to be compatible with Prometheus 3 | ||
// range selectors which are left open right closed. | ||
func NewProm2RangeCompat(ctx context.Context) ASTMapper { | ||
compat := &prom2RangeCompat{ctx: ctx} | ||
return NewASTExprMapper(compat) | ||
} | ||
|
||
type prom2RangeCompat struct { | ||
ctx context.Context | ||
} | ||
|
||
func (c prom2RangeCompat) MapExpr(expr parser.Expr) (mapped parser.Expr, finished bool, err error) { | ||
if err := c.ctx.Err(); err != nil { | ||
return nil, false, err | ||
} | ||
|
||
e, ok := expr.(*parser.SubqueryExpr) | ||
if !ok { | ||
return expr, false, nil | ||
} | ||
|
||
// Due to range selectors being left open right closed in Prometheus 3, subqueries with identical | ||
// range and step will only select a single datapoint which breaks functions that need multiple | ||
// points (rate, increase). Adjust the range here slightly to ensure that multiple data points | ||
// are returned to match the Prometheus 2 behavior. | ||
if e.Range == e.Step { | ||
e.Range = e.Range + time.Millisecond | ||
} | ||
|
||
return e, false, nil | ||
} |
64 changes: 64 additions & 0 deletions
64
pkg/frontend/querymiddleware/astmapper/prom2_range_compat_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
package astmapper | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/prometheus/prometheus/promql/parser" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestProm2RangeCompat_Cancellation(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
cancel() | ||
|
||
query, _ := parser.ParseExpr(`up{foo="bar"}`) | ||
mapper := NewProm2RangeCompat(ctx) | ||
_, err := mapper.Map(query) | ||
|
||
require.ErrorIs(t, err, context.Canceled) | ||
} | ||
|
||
func TestProm2RangeCompat_Queries(t *testing.T) { | ||
type testCase struct { | ||
query string | ||
expectedQuery string | ||
} | ||
|
||
testCases := []testCase{ | ||
{ | ||
query: `sum(rate(some_series{job="foo"}[1m]))`, | ||
expectedQuery: `sum(rate(some_series{job="foo"}[1m]))`, | ||
}, | ||
{ | ||
query: `sum(rate(some_series{job="foo"}[1m:1m]))`, | ||
expectedQuery: `sum(rate(some_series{job="foo"}[1m1ms:1m]))`, | ||
}, | ||
{ | ||
query: `sum(rate(some_series{job="foo"}[1h]))`, | ||
expectedQuery: `sum(rate(some_series{job="foo"}[1h]))`, | ||
}, | ||
{ | ||
query: `sum(rate(some_series{job="foo"}[1h:1h]))`, | ||
expectedQuery: `sum(rate(some_series{job="foo"}[1h1ms:1h]))`, | ||
}, | ||
{ | ||
query: `sum(rate(some_series{job="foo"}[1h:1h])) / sum(rate(other_series{job="foo"}[1m:1m]))`, | ||
expectedQuery: `sum(rate(some_series{job="foo"}[1h1ms:1h])) / sum(rate(other_series{job="foo"}[1m1ms:1m]))`, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.query, func(t *testing.T) { | ||
query, err := parser.ParseExpr(tc.query) | ||
require.NoError(t, err) | ||
|
||
mapper := NewProm2RangeCompat(context.Background()) | ||
mapped, err := mapper.Map(query) | ||
require.NoError(t, err) | ||
require.Equal(t, tc.expectedQuery, mapped.String()) | ||
}) | ||
} | ||
} |
Oops, something went wrong.