mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-24 05:04:05 -08:00
test: add promqltest package references
To packages outside of promql. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
e7c77f7b40
commit
8fd96241ab
|
@ -56,8 +56,8 @@ import (
|
||||||
"github.com/prometheus/prometheus/model/rulefmt"
|
"github.com/prometheus/prometheus/model/rulefmt"
|
||||||
"github.com/prometheus/prometheus/notifier"
|
"github.com/prometheus/prometheus/notifier"
|
||||||
_ "github.com/prometheus/prometheus/plugins" // Register plugins.
|
_ "github.com/prometheus/prometheus/plugins" // Register plugins.
|
||||||
"github.com/prometheus/prometheus/promql"
|
|
||||||
"github.com/prometheus/prometheus/promql/parser"
|
"github.com/prometheus/prometheus/promql/parser"
|
||||||
|
"github.com/prometheus/prometheus/promql/promqltest"
|
||||||
"github.com/prometheus/prometheus/scrape"
|
"github.com/prometheus/prometheus/scrape"
|
||||||
"github.com/prometheus/prometheus/util/documentcli"
|
"github.com/prometheus/prometheus/util/documentcli"
|
||||||
)
|
)
|
||||||
|
@ -377,7 +377,7 @@ func main() {
|
||||||
|
|
||||||
case testRulesCmd.FullCommand():
|
case testRulesCmd.FullCommand():
|
||||||
os.Exit(RulesUnitTest(
|
os.Exit(RulesUnitTest(
|
||||||
promql.LazyLoaderOpts{
|
promqltest.LazyLoaderOpts{
|
||||||
EnableAtModifier: true,
|
EnableAtModifier: true,
|
||||||
EnableNegativeOffset: true,
|
EnableNegativeOffset: true,
|
||||||
},
|
},
|
||||||
|
|
|
@ -26,7 +26,7 @@ import (
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/prometheus/prometheus/promql"
|
"github.com/prometheus/prometheus/promql/promqltest"
|
||||||
"github.com/prometheus/prometheus/tsdb"
|
"github.com/prometheus/prometheus/tsdb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ func normalizeNewLine(b []byte) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTSDBDump(t *testing.T) {
|
func TestTSDBDump(t *testing.T) {
|
||||||
storage := promql.LoadedStorage(t, `
|
storage := promqltest.LoadedStorage(t, `
|
||||||
load 1m
|
load 1m
|
||||||
metric{foo="bar", baz="abc"} 1 2 3 4 5
|
metric{foo="bar", baz="abc"} 1 2 3 4 5
|
||||||
heavy_metric{foo="bar"} 5 4 3 2 1
|
heavy_metric{foo="bar"} 5 4 3 2 1
|
||||||
|
@ -158,7 +158,7 @@ func TestTSDBDump(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTSDBDumpOpenMetrics(t *testing.T) {
|
func TestTSDBDumpOpenMetrics(t *testing.T) {
|
||||||
storage := promql.LoadedStorage(t, `
|
storage := promqltest.LoadedStorage(t, `
|
||||||
load 1m
|
load 1m
|
||||||
my_counter{foo="bar", baz="abc"} 1 2 3 4 5
|
my_counter{foo="bar", baz="abc"} 1 2 3 4 5
|
||||||
my_gauge{bar="foo", abc="baz"} 9 8 0 4 7
|
my_gauge{bar="foo", abc="baz"} 9 8 0 4 7
|
||||||
|
|
|
@ -36,13 +36,14 @@ import (
|
||||||
"github.com/prometheus/prometheus/model/labels"
|
"github.com/prometheus/prometheus/model/labels"
|
||||||
"github.com/prometheus/prometheus/promql"
|
"github.com/prometheus/prometheus/promql"
|
||||||
"github.com/prometheus/prometheus/promql/parser"
|
"github.com/prometheus/prometheus/promql/parser"
|
||||||
|
"github.com/prometheus/prometheus/promql/promqltest"
|
||||||
"github.com/prometheus/prometheus/rules"
|
"github.com/prometheus/prometheus/rules"
|
||||||
"github.com/prometheus/prometheus/storage"
|
"github.com/prometheus/prometheus/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RulesUnitTest does unit testing of rules based on the unit testing files provided.
|
// RulesUnitTest does unit testing of rules based on the unit testing files provided.
|
||||||
// More info about the file format can be found in the docs.
|
// More info about the file format can be found in the docs.
|
||||||
func RulesUnitTest(queryOpts promql.LazyLoaderOpts, runStrings []string, diffFlag bool, files ...string) int {
|
func RulesUnitTest(queryOpts promqltest.LazyLoaderOpts, runStrings []string, diffFlag bool, files ...string) int {
|
||||||
failed := false
|
failed := false
|
||||||
|
|
||||||
var run *regexp.Regexp
|
var run *regexp.Regexp
|
||||||
|
@ -69,7 +70,7 @@ func RulesUnitTest(queryOpts promql.LazyLoaderOpts, runStrings []string, diffFla
|
||||||
return successExitCode
|
return successExitCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func ruleUnitTest(filename string, queryOpts promql.LazyLoaderOpts, run *regexp.Regexp, diffFlag bool) []error {
|
func ruleUnitTest(filename string, queryOpts promqltest.LazyLoaderOpts, run *regexp.Regexp, diffFlag bool) []error {
|
||||||
fmt.Println("Unit Testing: ", filename)
|
fmt.Println("Unit Testing: ", filename)
|
||||||
|
|
||||||
b, err := os.ReadFile(filename)
|
b, err := os.ReadFile(filename)
|
||||||
|
@ -175,9 +176,9 @@ type testGroup struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// test performs the unit tests.
|
// test performs the unit tests.
|
||||||
func (tg *testGroup) test(evalInterval time.Duration, groupOrderMap map[string]int, queryOpts promql.LazyLoaderOpts, diffFlag bool, ruleFiles ...string) (outErr []error) {
|
func (tg *testGroup) test(evalInterval time.Duration, groupOrderMap map[string]int, queryOpts promqltest.LazyLoaderOpts, diffFlag bool, ruleFiles ...string) (outErr []error) {
|
||||||
// Setup testing suite.
|
// Setup testing suite.
|
||||||
suite, err := promql.NewLazyLoader(tg.seriesLoadingString(), queryOpts)
|
suite, err := promqltest.NewLazyLoader(tg.seriesLoadingString(), queryOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []error{err}
|
return []error{err}
|
||||||
}
|
}
|
||||||
|
@ -413,7 +414,7 @@ Outer:
|
||||||
gotSamples = append(gotSamples, parsedSample{
|
gotSamples = append(gotSamples, parsedSample{
|
||||||
Labels: s.Metric.Copy(),
|
Labels: s.Metric.Copy(),
|
||||||
Value: s.F,
|
Value: s.F,
|
||||||
Histogram: promql.HistogramTestExpression(s.H),
|
Histogram: promqltest.HistogramTestExpression(s.H),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,7 +444,7 @@ Outer:
|
||||||
expSamples = append(expSamples, parsedSample{
|
expSamples = append(expSamples, parsedSample{
|
||||||
Labels: lb,
|
Labels: lb,
|
||||||
Value: s.Value,
|
Value: s.Value,
|
||||||
Histogram: promql.HistogramTestExpression(hist),
|
Histogram: promqltest.HistogramTestExpression(hist),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/prometheus/prometheus/promql"
|
"github.com/prometheus/prometheus/promql/promqltest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRulesUnitTest(t *testing.T) {
|
func TestRulesUnitTest(t *testing.T) {
|
||||||
|
@ -28,7 +28,7 @@ func TestRulesUnitTest(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
args args
|
args args
|
||||||
queryOpts promql.LazyLoaderOpts
|
queryOpts promqltest.LazyLoaderOpts
|
||||||
want int
|
want int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
@ -92,7 +92,7 @@ func TestRulesUnitTest(t *testing.T) {
|
||||||
args: args{
|
args: args{
|
||||||
files: []string{"./testdata/at-modifier-test.yml"},
|
files: []string{"./testdata/at-modifier-test.yml"},
|
||||||
},
|
},
|
||||||
queryOpts: promql.LazyLoaderOpts{
|
queryOpts: promqltest.LazyLoaderOpts{
|
||||||
EnableAtModifier: true,
|
EnableAtModifier: true,
|
||||||
},
|
},
|
||||||
want: 0,
|
want: 0,
|
||||||
|
@ -109,7 +109,7 @@ func TestRulesUnitTest(t *testing.T) {
|
||||||
args: args{
|
args: args{
|
||||||
files: []string{"./testdata/negative-offset-test.yml"},
|
files: []string{"./testdata/negative-offset-test.yml"},
|
||||||
},
|
},
|
||||||
queryOpts: promql.LazyLoaderOpts{
|
queryOpts: promqltest.LazyLoaderOpts{
|
||||||
EnableNegativeOffset: true,
|
EnableNegativeOffset: true,
|
||||||
},
|
},
|
||||||
want: 0,
|
want: 0,
|
||||||
|
@ -119,7 +119,7 @@ func TestRulesUnitTest(t *testing.T) {
|
||||||
args: args{
|
args: args{
|
||||||
files: []string{"./testdata/no-test-group-interval.yml"},
|
files: []string{"./testdata/no-test-group-interval.yml"},
|
||||||
},
|
},
|
||||||
queryOpts: promql.LazyLoaderOpts{
|
queryOpts: promqltest.LazyLoaderOpts{
|
||||||
EnableNegativeOffset: true,
|
EnableNegativeOffset: true,
|
||||||
},
|
},
|
||||||
want: 0,
|
want: 0,
|
||||||
|
@ -142,7 +142,7 @@ func TestRulesUnitTestRun(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
args args
|
args args
|
||||||
queryOpts promql.LazyLoaderOpts
|
queryOpts promqltest.LazyLoaderOpts
|
||||||
want int
|
want int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
|
|
@ -30,6 +30,7 @@ import (
|
||||||
"github.com/prometheus/prometheus/notifier"
|
"github.com/prometheus/prometheus/notifier"
|
||||||
"github.com/prometheus/prometheus/promql"
|
"github.com/prometheus/prometheus/promql"
|
||||||
"github.com/prometheus/prometheus/promql/parser"
|
"github.com/prometheus/prometheus/promql/parser"
|
||||||
|
"github.com/prometheus/prometheus/promql/promqltest"
|
||||||
"github.com/prometheus/prometheus/storage"
|
"github.com/prometheus/prometheus/storage"
|
||||||
"github.com/prometheus/prometheus/util/teststorage"
|
"github.com/prometheus/prometheus/util/teststorage"
|
||||||
"github.com/prometheus/prometheus/util/testutil"
|
"github.com/prometheus/prometheus/util/testutil"
|
||||||
|
@ -148,7 +149,7 @@ func TestAlertingRuleTemplateWithHistogram(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAlertingRuleLabelsUpdate(t *testing.T) {
|
func TestAlertingRuleLabelsUpdate(t *testing.T) {
|
||||||
storage := promql.LoadedStorage(t, `
|
storage := promqltest.LoadedStorage(t, `
|
||||||
load 1m
|
load 1m
|
||||||
http_requests{job="app-server", instance="0"} 75 85 70 70 stale
|
http_requests{job="app-server", instance="0"} 75 85 70 70 stale
|
||||||
`)
|
`)
|
||||||
|
@ -252,7 +253,7 @@ func TestAlertingRuleLabelsUpdate(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAlertingRuleExternalLabelsInTemplate(t *testing.T) {
|
func TestAlertingRuleExternalLabelsInTemplate(t *testing.T) {
|
||||||
storage := promql.LoadedStorage(t, `
|
storage := promqltest.LoadedStorage(t, `
|
||||||
load 1m
|
load 1m
|
||||||
http_requests{job="app-server", instance="0"} 75 85 70 70
|
http_requests{job="app-server", instance="0"} 75 85 70 70
|
||||||
`)
|
`)
|
||||||
|
@ -345,7 +346,7 @@ func TestAlertingRuleExternalLabelsInTemplate(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAlertingRuleExternalURLInTemplate(t *testing.T) {
|
func TestAlertingRuleExternalURLInTemplate(t *testing.T) {
|
||||||
storage := promql.LoadedStorage(t, `
|
storage := promqltest.LoadedStorage(t, `
|
||||||
load 1m
|
load 1m
|
||||||
http_requests{job="app-server", instance="0"} 75 85 70 70
|
http_requests{job="app-server", instance="0"} 75 85 70 70
|
||||||
`)
|
`)
|
||||||
|
@ -438,7 +439,7 @@ func TestAlertingRuleExternalURLInTemplate(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAlertingRuleEmptyLabelFromTemplate(t *testing.T) {
|
func TestAlertingRuleEmptyLabelFromTemplate(t *testing.T) {
|
||||||
storage := promql.LoadedStorage(t, `
|
storage := promqltest.LoadedStorage(t, `
|
||||||
load 1m
|
load 1m
|
||||||
http_requests{job="app-server", instance="0"} 75 85 70 70
|
http_requests{job="app-server", instance="0"} 75 85 70 70
|
||||||
`)
|
`)
|
||||||
|
@ -492,7 +493,7 @@ func TestAlertingRuleEmptyLabelFromTemplate(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAlertingRuleQueryInTemplate(t *testing.T) {
|
func TestAlertingRuleQueryInTemplate(t *testing.T) {
|
||||||
storage := promql.LoadedStorage(t, `
|
storage := promqltest.LoadedStorage(t, `
|
||||||
load 1m
|
load 1m
|
||||||
http_requests{job="app-server", instance="0"} 70 85 70 70
|
http_requests{job="app-server", instance="0"} 70 85 70 70
|
||||||
`)
|
`)
|
||||||
|
@ -601,7 +602,7 @@ func TestAlertingRuleDuplicate(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAlertingRuleLimit(t *testing.T) {
|
func TestAlertingRuleLimit(t *testing.T) {
|
||||||
storage := promql.LoadedStorage(t, `
|
storage := promqltest.LoadedStorage(t, `
|
||||||
load 1m
|
load 1m
|
||||||
metric{label="1"} 1
|
metric{label="1"} 1
|
||||||
metric{label="2"} 1
|
metric{label="2"} 1
|
||||||
|
@ -783,7 +784,7 @@ func TestSendAlertsDontAffectActiveAlerts(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestKeepFiringFor(t *testing.T) {
|
func TestKeepFiringFor(t *testing.T) {
|
||||||
storage := promql.LoadedStorage(t, `
|
storage := promqltest.LoadedStorage(t, `
|
||||||
load 1m
|
load 1m
|
||||||
http_requests{job="app-server", instance="0"} 75 85 70 70 10x5
|
http_requests{job="app-server", instance="0"} 75 85 70 70 10x5
|
||||||
`)
|
`)
|
||||||
|
@ -893,7 +894,7 @@ func TestKeepFiringFor(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPendingAndKeepFiringFor(t *testing.T) {
|
func TestPendingAndKeepFiringFor(t *testing.T) {
|
||||||
storage := promql.LoadedStorage(t, `
|
storage := promqltest.LoadedStorage(t, `
|
||||||
load 1m
|
load 1m
|
||||||
http_requests{job="app-server", instance="0"} 75 10x10
|
http_requests{job="app-server", instance="0"} 75 10x10
|
||||||
`)
|
`)
|
||||||
|
|
|
@ -38,6 +38,7 @@ import (
|
||||||
"github.com/prometheus/prometheus/model/value"
|
"github.com/prometheus/prometheus/model/value"
|
||||||
"github.com/prometheus/prometheus/promql"
|
"github.com/prometheus/prometheus/promql"
|
||||||
"github.com/prometheus/prometheus/promql/parser"
|
"github.com/prometheus/prometheus/promql/parser"
|
||||||
|
"github.com/prometheus/prometheus/promql/promqltest"
|
||||||
"github.com/prometheus/prometheus/storage"
|
"github.com/prometheus/prometheus/storage"
|
||||||
"github.com/prometheus/prometheus/tsdb/chunkenc"
|
"github.com/prometheus/prometheus/tsdb/chunkenc"
|
||||||
"github.com/prometheus/prometheus/tsdb/tsdbutil"
|
"github.com/prometheus/prometheus/tsdb/tsdbutil"
|
||||||
|
@ -50,7 +51,7 @@ func TestMain(m *testing.M) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAlertingRule(t *testing.T) {
|
func TestAlertingRule(t *testing.T) {
|
||||||
storage := promql.LoadedStorage(t, `
|
storage := promqltest.LoadedStorage(t, `
|
||||||
load 5m
|
load 5m
|
||||||
http_requests{job="app-server", instance="0", group="canary", severity="overwrite-me"} 75 85 95 105 105 95 85
|
http_requests{job="app-server", instance="0", group="canary", severity="overwrite-me"} 75 85 95 105 105 95 85
|
||||||
http_requests{job="app-server", instance="1", group="canary", severity="overwrite-me"} 80 90 100 110 120 130 140
|
http_requests{job="app-server", instance="1", group="canary", severity="overwrite-me"} 80 90 100 110 120 130 140
|
||||||
|
@ -190,7 +191,7 @@ func TestAlertingRule(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestForStateAddSamples(t *testing.T) {
|
func TestForStateAddSamples(t *testing.T) {
|
||||||
storage := promql.LoadedStorage(t, `
|
storage := promqltest.LoadedStorage(t, `
|
||||||
load 5m
|
load 5m
|
||||||
http_requests{job="app-server", instance="0", group="canary", severity="overwrite-me"} 75 85 95 105 105 95 85
|
http_requests{job="app-server", instance="0", group="canary", severity="overwrite-me"} 75 85 95 105 105 95 85
|
||||||
http_requests{job="app-server", instance="1", group="canary", severity="overwrite-me"} 80 90 100 110 120 130 140
|
http_requests{job="app-server", instance="1", group="canary", severity="overwrite-me"} 80 90 100 110 120 130 140
|
||||||
|
@ -347,7 +348,7 @@ func sortAlerts(items []*Alert) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestForStateRestore(t *testing.T) {
|
func TestForStateRestore(t *testing.T) {
|
||||||
storage := promql.LoadedStorage(t, `
|
storage := promqltest.LoadedStorage(t, `
|
||||||
load 5m
|
load 5m
|
||||||
http_requests{job="app-server", instance="0", group="canary", severity="overwrite-me"} 75 85 50 0 0 25 0 0 40 0 120
|
http_requests{job="app-server", instance="0", group="canary", severity="overwrite-me"} 75 85 50 0 0 25 0 0 40 0 120
|
||||||
http_requests{job="app-server", instance="1", group="canary", severity="overwrite-me"} 125 90 60 0 0 25 0 0 40 0 130
|
http_requests{job="app-server", instance="1", group="canary", severity="overwrite-me"} 125 90 60 0 0 25 0 0 40 0 130
|
||||||
|
@ -1229,7 +1230,7 @@ func TestRuleHealthUpdates(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRuleGroupEvalIterationFunc(t *testing.T) {
|
func TestRuleGroupEvalIterationFunc(t *testing.T) {
|
||||||
storage := promql.LoadedStorage(t, `
|
storage := promqltest.LoadedStorage(t, `
|
||||||
load 5m
|
load 5m
|
||||||
http_requests{instance="0"} 75 85 50 0 0 25 0 0 40 0 120
|
http_requests{instance="0"} 75 85 50 0 0 25 0 0 40 0 120
|
||||||
`)
|
`)
|
||||||
|
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"github.com/prometheus/prometheus/model/timestamp"
|
"github.com/prometheus/prometheus/model/timestamp"
|
||||||
"github.com/prometheus/prometheus/promql"
|
"github.com/prometheus/prometheus/promql"
|
||||||
"github.com/prometheus/prometheus/promql/parser"
|
"github.com/prometheus/prometheus/promql/parser"
|
||||||
|
"github.com/prometheus/prometheus/promql/promqltest"
|
||||||
"github.com/prometheus/prometheus/util/teststorage"
|
"github.com/prometheus/prometheus/util/teststorage"
|
||||||
"github.com/prometheus/prometheus/util/testutil"
|
"github.com/prometheus/prometheus/util/testutil"
|
||||||
)
|
)
|
||||||
|
@ -111,7 +112,7 @@ var ruleEvalTestScenarios = []struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func setUpRuleEvalTest(t require.TestingT) *teststorage.TestStorage {
|
func setUpRuleEvalTest(t require.TestingT) *teststorage.TestStorage {
|
||||||
return promql.LoadedStorage(t, `
|
return promqltest.LoadedStorage(t, `
|
||||||
load 1m
|
load 1m
|
||||||
metric{label_a="1",label_b="3"} 1
|
metric{label_a="1",label_b="3"} 1
|
||||||
metric{label_a="2",label_b="4"} 10
|
metric{label_a="2",label_b="4"} 10
|
||||||
|
@ -178,7 +179,7 @@ func TestRuleEvalDuplicate(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRecordingRuleLimit(t *testing.T) {
|
func TestRecordingRuleLimit(t *testing.T) {
|
||||||
storage := promql.LoadedStorage(t, `
|
storage := promqltest.LoadedStorage(t, `
|
||||||
load 1m
|
load 1m
|
||||||
metric{label="1"} 1
|
metric{label="1"} 1
|
||||||
metric{label="2"} 1
|
metric{label="2"} 1
|
||||||
|
|
|
@ -30,14 +30,14 @@ import (
|
||||||
"github.com/prometheus/prometheus/config"
|
"github.com/prometheus/prometheus/config"
|
||||||
"github.com/prometheus/prometheus/model/labels"
|
"github.com/prometheus/prometheus/model/labels"
|
||||||
"github.com/prometheus/prometheus/prompb"
|
"github.com/prometheus/prometheus/prompb"
|
||||||
"github.com/prometheus/prometheus/promql"
|
"github.com/prometheus/prometheus/promql/promqltest"
|
||||||
"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 TestSampledReadEndpoint(t *testing.T) {
|
func TestSampledReadEndpoint(t *testing.T) {
|
||||||
store := promql.LoadedStorage(t, `
|
store := promqltest.LoadedStorage(t, `
|
||||||
load 1m
|
load 1m
|
||||||
test_metric1{foo="bar",baz="qux"} 1
|
test_metric1{foo="bar",baz="qux"} 1
|
||||||
`)
|
`)
|
||||||
|
@ -132,7 +132,7 @@ func TestSampledReadEndpoint(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStreamReadEndpoint(b *testing.B) {
|
func BenchmarkStreamReadEndpoint(b *testing.B) {
|
||||||
store := promql.LoadedStorage(b, `
|
store := promqltest.LoadedStorage(b, `
|
||||||
load 1m
|
load 1m
|
||||||
test_metric1{foo="bar1",baz="qux"} 0+100x119
|
test_metric1{foo="bar1",baz="qux"} 0+100x119
|
||||||
test_metric1{foo="bar2",baz="qux"} 0+100x120
|
test_metric1{foo="bar2",baz="qux"} 0+100x120
|
||||||
|
@ -200,7 +200,7 @@ func TestStreamReadEndpoint(t *testing.T) {
|
||||||
// Second with 121 float samples, We expect 1 frame with 2 chunks.
|
// Second with 121 float samples, We expect 1 frame with 2 chunks.
|
||||||
// Third with 241 float samples. We expect 1 frame with 2 chunks, and 1 frame with 1 chunk for the same series due to bytes limit.
|
// Third with 241 float samples. We expect 1 frame with 2 chunks, and 1 frame with 1 chunk for the same series due to bytes limit.
|
||||||
// Fourth with 25 histogram samples. We expect 1 frame with 1 chunk.
|
// Fourth with 25 histogram samples. We expect 1 frame with 1 chunk.
|
||||||
store := promql.LoadedStorage(t, `
|
store := promqltest.LoadedStorage(t, `
|
||||||
load 1m
|
load 1m
|
||||||
test_metric1{foo="bar1",baz="qux"} 0+100x119
|
test_metric1{foo="bar1",baz="qux"} 0+100x119
|
||||||
test_metric1{foo="bar2",baz="qux"} 0+100x120
|
test_metric1{foo="bar2",baz="qux"} 0+100x120
|
||||||
|
|
|
@ -49,6 +49,7 @@ import (
|
||||||
"github.com/prometheus/prometheus/model/timestamp"
|
"github.com/prometheus/prometheus/model/timestamp"
|
||||||
"github.com/prometheus/prometheus/promql"
|
"github.com/prometheus/prometheus/promql"
|
||||||
"github.com/prometheus/prometheus/promql/parser"
|
"github.com/prometheus/prometheus/promql/parser"
|
||||||
|
"github.com/prometheus/prometheus/promql/promqltest"
|
||||||
"github.com/prometheus/prometheus/rules"
|
"github.com/prometheus/prometheus/rules"
|
||||||
"github.com/prometheus/prometheus/scrape"
|
"github.com/prometheus/prometheus/scrape"
|
||||||
"github.com/prometheus/prometheus/storage"
|
"github.com/prometheus/prometheus/storage"
|
||||||
|
@ -338,7 +339,7 @@ var sampleFlagMap = map[string]string{
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEndpoints(t *testing.T) {
|
func TestEndpoints(t *testing.T) {
|
||||||
storage := promql.LoadedStorage(t, `
|
storage := promqltest.LoadedStorage(t, `
|
||||||
load 1m
|
load 1m
|
||||||
test_metric1{foo="bar"} 0+100x100
|
test_metric1{foo="bar"} 0+100x100
|
||||||
test_metric1{foo="boo"} 1+0x100
|
test_metric1{foo="boo"} 1+0x100
|
||||||
|
@ -502,7 +503,7 @@ func (b byLabels) Less(i, j int) bool { return labels.Compare(b[i], b[j]) < 0 }
|
||||||
func TestGetSeries(t *testing.T) {
|
func TestGetSeries(t *testing.T) {
|
||||||
// TestEndpoints doesn't have enough label names to test api.labelNames
|
// TestEndpoints doesn't have enough label names to test api.labelNames
|
||||||
// endpoint properly. Hence we test it separately.
|
// endpoint properly. Hence we test it separately.
|
||||||
storage := promql.LoadedStorage(t, `
|
storage := promqltest.LoadedStorage(t, `
|
||||||
load 1m
|
load 1m
|
||||||
test_metric1{foo1="bar", baz="abc"} 0+100x100
|
test_metric1{foo1="bar", baz="abc"} 0+100x100
|
||||||
test_metric1{foo2="boo"} 1+0x100
|
test_metric1{foo2="boo"} 1+0x100
|
||||||
|
@ -606,7 +607,7 @@ func TestGetSeries(t *testing.T) {
|
||||||
|
|
||||||
func TestQueryExemplars(t *testing.T) {
|
func TestQueryExemplars(t *testing.T) {
|
||||||
start := time.Unix(0, 0)
|
start := time.Unix(0, 0)
|
||||||
storage := promql.LoadedStorage(t, `
|
storage := promqltest.LoadedStorage(t, `
|
||||||
load 1m
|
load 1m
|
||||||
test_metric1{foo="bar"} 0+100x100
|
test_metric1{foo="bar"} 0+100x100
|
||||||
test_metric1{foo="boo"} 1+0x100
|
test_metric1{foo="boo"} 1+0x100
|
||||||
|
@ -725,7 +726,7 @@ func TestQueryExemplars(t *testing.T) {
|
||||||
func TestLabelNames(t *testing.T) {
|
func TestLabelNames(t *testing.T) {
|
||||||
// TestEndpoints doesn't have enough label names to test api.labelNames
|
// TestEndpoints doesn't have enough label names to test api.labelNames
|
||||||
// endpoint properly. Hence we test it separately.
|
// endpoint properly. Hence we test it separately.
|
||||||
storage := promql.LoadedStorage(t, `
|
storage := promqltest.LoadedStorage(t, `
|
||||||
load 1m
|
load 1m
|
||||||
test_metric1{foo1="bar", baz="abc"} 0+100x100
|
test_metric1{foo1="bar", baz="abc"} 0+100x100
|
||||||
test_metric1{foo2="boo"} 1+0x100
|
test_metric1{foo2="boo"} 1+0x100
|
||||||
|
@ -3835,7 +3836,7 @@ func TestExtractQueryOpts(t *testing.T) {
|
||||||
|
|
||||||
// Test query timeout parameter.
|
// Test query timeout parameter.
|
||||||
func TestQueryTimeout(t *testing.T) {
|
func TestQueryTimeout(t *testing.T) {
|
||||||
storage := promql.LoadedStorage(t, `
|
storage := promqltest.LoadedStorage(t, `
|
||||||
load 1m
|
load 1m
|
||||||
test_metric1{foo="bar"} 0+100x100
|
test_metric1{foo="bar"} 0+100x100
|
||||||
`)
|
`)
|
||||||
|
|
|
@ -34,6 +34,7 @@ import (
|
||||||
"github.com/prometheus/prometheus/model/labels"
|
"github.com/prometheus/prometheus/model/labels"
|
||||||
"github.com/prometheus/prometheus/model/textparse"
|
"github.com/prometheus/prometheus/model/textparse"
|
||||||
"github.com/prometheus/prometheus/promql"
|
"github.com/prometheus/prometheus/promql"
|
||||||
|
"github.com/prometheus/prometheus/promql/promqltest"
|
||||||
"github.com/prometheus/prometheus/storage"
|
"github.com/prometheus/prometheus/storage"
|
||||||
"github.com/prometheus/prometheus/tsdb"
|
"github.com/prometheus/prometheus/tsdb"
|
||||||
"github.com/prometheus/prometheus/util/teststorage"
|
"github.com/prometheus/prometheus/util/teststorage"
|
||||||
|
@ -201,7 +202,7 @@ test_metric_without_labels{instance="baz"} 1001 6000000
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFederation(t *testing.T) {
|
func TestFederation(t *testing.T) {
|
||||||
storage := promql.LoadedStorage(t, `
|
storage := promqltest.LoadedStorage(t, `
|
||||||
load 1m
|
load 1m
|
||||||
test_metric1{foo="bar",instance="i"} 0+100x100
|
test_metric1{foo="bar",instance="i"} 0+100x100
|
||||||
test_metric1{foo="boo",instance="i"} 1+0x100
|
test_metric1{foo="boo",instance="i"} 1+0x100
|
||||||
|
|
Loading…
Reference in a new issue