MCPcopy Index your code
hub / github.com/prometheus/prometheus / TestQueryStatistics

Function TestQueryStatistics

promql/engine_test.go:775–1857  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

773}
774
775func TestQueryStatistics(t *testing.T) {
776 storage := promqltest.LoadedStorage(t, `
777load 10s
778 metricWith1SampleEvery10Seconds 1+1x100
779 metricWith3SampleEvery10Seconds{a="1",b="1"} 1+1x100
780 metricWith3SampleEvery10Seconds{a="2",b="2"} 1+1x100
781 metricWith3SampleEvery10Seconds{a="3",b="2"} 1+1x100
782 metricWith1HistogramEvery10Seconds {{schema:1 count:5 sum:20 buckets:[1 2 1 1]}}+{{schema:1 count:10 sum:5 buckets:[1 2 3 4]}}x100
783`)
784
785 type testCase struct {
786 Query string
787 SkipMaxCheck bool
788 TotalSamples int64
789 TotalSamplesPerStep stats.TotalSamplesPerStep
790 SamplesRead int64 // Samples read (delta for range-vector).
791 SamplesReadPerStep stats.TotalSamplesPerStep // Per-step samples read.
792 PeakSamples int
793 Start time.Time
794 End time.Time
795 Interval time.Duration
796 }
797 cases := []testCase{
798 {
799 Query: `"literal string"`,
800 SkipMaxCheck: true, // This can't fail from a max samples limit.
801 Start: time.Unix(21, 0),
802 TotalSamples: 0,
803 TotalSamplesPerStep: stats.TotalSamplesPerStep{
804 21000: 0,
805 },
806 SamplesRead: 0,
807 SamplesReadPerStep: stats.TotalSamplesPerStep{
808 21000: 0,
809 },
810 },
811 {
812 Query: "1",
813 Start: time.Unix(21, 0),
814 TotalSamples: 0,
815 PeakSamples: 1,
816 TotalSamplesPerStep: stats.TotalSamplesPerStep{
817 21000: 0,
818 },
819 SamplesRead: 0,
820 SamplesReadPerStep: stats.TotalSamplesPerStep{
821 21000: 0,
822 },
823 },
824 {
825 Query: "metricWith1SampleEvery10Seconds",
826 Start: time.Unix(21, 0),
827 PeakSamples: 1,
828 TotalSamples: 1, // 1 sample / 10 seconds
829 TotalSamplesPerStep: stats.TotalSamplesPerStep{
830 21000: 1,
831 },
832 SamplesRead: 1,

Callers

nothing calls this directly

Calls 11

ExecMethod · 0.95
StatsMethod · 0.95
LoadedStorageFunction · 0.92
NewPrometheusQueryOptsFunction · 0.92
NewTestEngineFunction · 0.92
ErrTooManySamplesTypeAlias · 0.92
SamplesReadPerStepMapMethod · 0.80
NewInstantQueryMethod · 0.65
NewRangeQueryMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…