mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 13:44:05 -08:00
test: move most PromQL tests into separate test package
So that they can import promqltest which imports promql. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
4a72607c4a
commit
0dbfd20b69
|
@ -11,7 +11,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package promql
|
package promql_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -23,13 +23,14 @@ import (
|
||||||
|
|
||||||
"github.com/prometheus/prometheus/model/histogram"
|
"github.com/prometheus/prometheus/model/histogram"
|
||||||
"github.com/prometheus/prometheus/model/labels"
|
"github.com/prometheus/prometheus/model/labels"
|
||||||
|
"github.com/prometheus/prometheus/promql"
|
||||||
"github.com/prometheus/prometheus/promql/parser"
|
"github.com/prometheus/prometheus/promql/parser"
|
||||||
"github.com/prometheus/prometheus/storage"
|
"github.com/prometheus/prometheus/storage"
|
||||||
"github.com/prometheus/prometheus/tsdb/tsdbutil"
|
"github.com/prometheus/prometheus/tsdb/tsdbutil"
|
||||||
"github.com/prometheus/prometheus/util/teststorage"
|
"github.com/prometheus/prometheus/util/teststorage"
|
||||||
)
|
)
|
||||||
|
|
||||||
func setupRangeQueryTestData(stor *teststorage.TestStorage, _ *Engine, interval, numIntervals int) error {
|
func setupRangeQueryTestData(stor *teststorage.TestStorage, _ *promql.Engine, interval, numIntervals int) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
metrics := []labels.Labels{}
|
metrics := []labels.Labels{}
|
||||||
|
@ -249,13 +250,13 @@ func BenchmarkRangeQuery(b *testing.B) {
|
||||||
stor := teststorage.New(b)
|
stor := teststorage.New(b)
|
||||||
stor.DB.DisableCompactions() // Don't want auto-compaction disrupting timings.
|
stor.DB.DisableCompactions() // Don't want auto-compaction disrupting timings.
|
||||||
defer stor.Close()
|
defer stor.Close()
|
||||||
opts := EngineOpts{
|
opts := promql.EngineOpts{
|
||||||
Logger: nil,
|
Logger: nil,
|
||||||
Reg: nil,
|
Reg: nil,
|
||||||
MaxSamples: 50000000,
|
MaxSamples: 50000000,
|
||||||
Timeout: 100 * time.Second,
|
Timeout: 100 * time.Second,
|
||||||
}
|
}
|
||||||
engine := NewEngine(opts)
|
engine := promql.NewEngine(opts)
|
||||||
|
|
||||||
const interval = 10000 // 10s interval.
|
const interval = 10000 // 10s interval.
|
||||||
// A day of data plus 10k steps.
|
// A day of data plus 10k steps.
|
||||||
|
@ -324,7 +325,7 @@ func BenchmarkNativeHistograms(b *testing.B) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
opts := EngineOpts{
|
opts := promql.EngineOpts{
|
||||||
Logger: nil,
|
Logger: nil,
|
||||||
Reg: nil,
|
Reg: nil,
|
||||||
MaxSamples: 50000000,
|
MaxSamples: 50000000,
|
||||||
|
@ -338,7 +339,7 @@ func BenchmarkNativeHistograms(b *testing.B) {
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
b.Run(tc.name, func(b *testing.B) {
|
b.Run(tc.name, func(b *testing.B) {
|
||||||
ng := NewEngine(opts)
|
ng := promql.NewEngine(opts)
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
qry, err := ng.NewRangeQuery(context.Background(), testStorage, nil, tc.query, start, end, step)
|
qry, err := ng.NewRangeQuery(context.Background(), testStorage, nil, tc.query, start, end, step)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -11,7 +11,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package promql
|
package promql_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -22,6 +22,7 @@ import (
|
||||||
|
|
||||||
"github.com/prometheus/prometheus/model/labels"
|
"github.com/prometheus/prometheus/model/labels"
|
||||||
"github.com/prometheus/prometheus/model/timestamp"
|
"github.com/prometheus/prometheus/model/timestamp"
|
||||||
|
"github.com/prometheus/prometheus/promql"
|
||||||
"github.com/prometheus/prometheus/promql/parser"
|
"github.com/prometheus/prometheus/promql/parser"
|
||||||
"github.com/prometheus/prometheus/util/teststorage"
|
"github.com/prometheus/prometheus/util/teststorage"
|
||||||
)
|
)
|
||||||
|
@ -32,13 +33,13 @@ func TestDeriv(t *testing.T) {
|
||||||
// so we test it by hand.
|
// so we test it by hand.
|
||||||
storage := teststorage.New(t)
|
storage := teststorage.New(t)
|
||||||
defer storage.Close()
|
defer storage.Close()
|
||||||
opts := EngineOpts{
|
opts := promql.EngineOpts{
|
||||||
Logger: nil,
|
Logger: nil,
|
||||||
Reg: nil,
|
Reg: nil,
|
||||||
MaxSamples: 10000,
|
MaxSamples: 10000,
|
||||||
Timeout: 10 * time.Second,
|
Timeout: 10 * time.Second,
|
||||||
}
|
}
|
||||||
engine := NewEngine(opts)
|
engine := promql.NewEngine(opts)
|
||||||
|
|
||||||
a := storage.Appender(context.Background())
|
a := storage.Appender(context.Background())
|
||||||
|
|
||||||
|
@ -69,13 +70,13 @@ func TestDeriv(t *testing.T) {
|
||||||
|
|
||||||
func TestFunctionList(t *testing.T) {
|
func TestFunctionList(t *testing.T) {
|
||||||
// Test that Functions and parser.Functions list the same functions.
|
// Test that Functions and parser.Functions list the same functions.
|
||||||
for i := range FunctionCalls {
|
for i := range promql.FunctionCalls {
|
||||||
_, ok := parser.Functions[i]
|
_, ok := parser.Functions[i]
|
||||||
require.True(t, ok, "function %s exists in promql package, but not in parser package", i)
|
require.True(t, ok, "function %s exists in promql package, but not in parser package", i)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range parser.Functions {
|
for i := range parser.Functions {
|
||||||
_, ok := FunctionCalls[i]
|
_, ok := promql.FunctionCalls[i]
|
||||||
require.True(t, ok, "function %s exists in parser package, but not in promql package", i)
|
require.True(t, ok, "function %s exists in parser package, but not in promql package", i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package promql
|
package promql_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -22,11 +22,12 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
|
|
||||||
|
"github.com/prometheus/prometheus/promql"
|
||||||
"github.com/prometheus/prometheus/promql/promqltest"
|
"github.com/prometheus/prometheus/promql/promqltest"
|
||||||
"github.com/prometheus/prometheus/util/teststorage"
|
"github.com/prometheus/prometheus/util/teststorage"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newTestEngine() *Engine {
|
func newTestEngine() *promql.Engine {
|
||||||
return promqltest.NewTestEngine(false, 0, promqltest.DefaultMaxSamplesPerQuery)
|
return promqltest.NewTestEngine(false, 0, promqltest.DefaultMaxSamplesPerQuery)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,13 +39,13 @@ func TestEvaluations(t *testing.T) {
|
||||||
func TestConcurrentRangeQueries(t *testing.T) {
|
func TestConcurrentRangeQueries(t *testing.T) {
|
||||||
stor := teststorage.New(t)
|
stor := teststorage.New(t)
|
||||||
defer stor.Close()
|
defer stor.Close()
|
||||||
opts := EngineOpts{
|
opts := promql.EngineOpts{
|
||||||
Logger: nil,
|
Logger: nil,
|
||||||
Reg: nil,
|
Reg: nil,
|
||||||
MaxSamples: 50000000,
|
MaxSamples: 50000000,
|
||||||
Timeout: 100 * time.Second,
|
Timeout: 100 * time.Second,
|
||||||
}
|
}
|
||||||
engine := NewEngine(opts)
|
engine := promql.NewEngine(opts)
|
||||||
|
|
||||||
const interval = 10000 // 10s interval.
|
const interval = 10000 // 10s interval.
|
||||||
// A day of data plus 10k steps.
|
// A day of data plus 10k steps.
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package promql
|
package promql_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -19,39 +19,40 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/prometheus/prometheus/model/labels"
|
"github.com/prometheus/prometheus/model/labels"
|
||||||
|
"github.com/prometheus/prometheus/promql"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestVector_ContainsSameLabelset(t *testing.T) {
|
func TestVector_ContainsSameLabelset(t *testing.T) {
|
||||||
for name, tc := range map[string]struct {
|
for name, tc := range map[string]struct {
|
||||||
vector Vector
|
vector promql.Vector
|
||||||
expected bool
|
expected bool
|
||||||
}{
|
}{
|
||||||
"empty vector": {
|
"empty vector": {
|
||||||
vector: Vector{},
|
vector: promql.Vector{},
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
"vector with one series": {
|
"vector with one series": {
|
||||||
vector: Vector{
|
vector: promql.Vector{
|
||||||
{Metric: labels.FromStrings("lbl", "a")},
|
{Metric: labels.FromStrings("lbl", "a")},
|
||||||
},
|
},
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
"vector with two different series": {
|
"vector with two different series": {
|
||||||
vector: Vector{
|
vector: promql.Vector{
|
||||||
{Metric: labels.FromStrings("lbl", "a")},
|
{Metric: labels.FromStrings("lbl", "a")},
|
||||||
{Metric: labels.FromStrings("lbl", "b")},
|
{Metric: labels.FromStrings("lbl", "b")},
|
||||||
},
|
},
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
"vector with two equal series": {
|
"vector with two equal series": {
|
||||||
vector: Vector{
|
vector: promql.Vector{
|
||||||
{Metric: labels.FromStrings("lbl", "a")},
|
{Metric: labels.FromStrings("lbl", "a")},
|
||||||
{Metric: labels.FromStrings("lbl", "a")},
|
{Metric: labels.FromStrings("lbl", "a")},
|
||||||
},
|
},
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
"vector with three series, two equal": {
|
"vector with three series, two equal": {
|
||||||
vector: Vector{
|
vector: promql.Vector{
|
||||||
{Metric: labels.FromStrings("lbl", "a")},
|
{Metric: labels.FromStrings("lbl", "a")},
|
||||||
{Metric: labels.FromStrings("lbl", "b")},
|
{Metric: labels.FromStrings("lbl", "b")},
|
||||||
{Metric: labels.FromStrings("lbl", "a")},
|
{Metric: labels.FromStrings("lbl", "a")},
|
||||||
|
@ -67,35 +68,35 @@ func TestVector_ContainsSameLabelset(t *testing.T) {
|
||||||
|
|
||||||
func TestMatrix_ContainsSameLabelset(t *testing.T) {
|
func TestMatrix_ContainsSameLabelset(t *testing.T) {
|
||||||
for name, tc := range map[string]struct {
|
for name, tc := range map[string]struct {
|
||||||
matrix Matrix
|
matrix promql.Matrix
|
||||||
expected bool
|
expected bool
|
||||||
}{
|
}{
|
||||||
"empty matrix": {
|
"empty matrix": {
|
||||||
matrix: Matrix{},
|
matrix: promql.Matrix{},
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
"matrix with one series": {
|
"matrix with one series": {
|
||||||
matrix: Matrix{
|
matrix: promql.Matrix{
|
||||||
{Metric: labels.FromStrings("lbl", "a")},
|
{Metric: labels.FromStrings("lbl", "a")},
|
||||||
},
|
},
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
"matrix with two different series": {
|
"matrix with two different series": {
|
||||||
matrix: Matrix{
|
matrix: promql.Matrix{
|
||||||
{Metric: labels.FromStrings("lbl", "a")},
|
{Metric: labels.FromStrings("lbl", "a")},
|
||||||
{Metric: labels.FromStrings("lbl", "b")},
|
{Metric: labels.FromStrings("lbl", "b")},
|
||||||
},
|
},
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
"matrix with two equal series": {
|
"matrix with two equal series": {
|
||||||
matrix: Matrix{
|
matrix: promql.Matrix{
|
||||||
{Metric: labels.FromStrings("lbl", "a")},
|
{Metric: labels.FromStrings("lbl", "a")},
|
||||||
{Metric: labels.FromStrings("lbl", "a")},
|
{Metric: labels.FromStrings("lbl", "a")},
|
||||||
},
|
},
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
"matrix with three series, two equal": {
|
"matrix with three series, two equal": {
|
||||||
matrix: Matrix{
|
matrix: promql.Matrix{
|
||||||
{Metric: labels.FromStrings("lbl", "a")},
|
{Metric: labels.FromStrings("lbl", "a")},
|
||||||
{Metric: labels.FromStrings("lbl", "b")},
|
{Metric: labels.FromStrings("lbl", "b")},
|
||||||
{Metric: labels.FromStrings("lbl", "a")},
|
{Metric: labels.FromStrings("lbl", "a")},
|
||||||
|
|
Loading…
Reference in a new issue