2024-10-30 15:22:06 +01:00
|
|
|
package tests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math/rand/v2"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/apptest"
|
|
|
|
)
|
|
|
|
|
2024-11-07 12:58:37 +01:00
|
|
|
func TestClusterMultilevelSelect(t *testing.T) {
|
2024-10-30 15:22:06 +01:00
|
|
|
tc := apptest.NewTestCase(t)
|
2024-11-08 14:49:00 +01:00
|
|
|
defer tc.Stop()
|
2024-10-30 15:22:06 +01:00
|
|
|
|
|
|
|
// Set up the following multi-level cluster configuration:
|
|
|
|
//
|
|
|
|
// vmselect (L2) -> vmselect (L1) -> vmstorage <- vminsert
|
|
|
|
//
|
|
|
|
// vmisert writes data into vmstorage.
|
|
|
|
// vmselect (L2) reads that data via vmselect (L1).
|
|
|
|
|
2024-11-08 14:49:00 +01:00
|
|
|
vmstorage := tc.MustStartVmstorage("vmstorage", []string{
|
2024-10-30 15:22:06 +01:00
|
|
|
"-storageDataPath=" + tc.Dir() + "/vmstorage",
|
2024-11-08 14:49:00 +01:00
|
|
|
})
|
|
|
|
vminsert := tc.MustStartVminsert("vminsert", []string{
|
2024-10-30 15:22:06 +01:00
|
|
|
"-storageNode=" + vmstorage.VminsertAddr(),
|
2024-11-08 14:49:00 +01:00
|
|
|
})
|
|
|
|
vmselectL1 := tc.MustStartVmselect("vmselect-level1", []string{
|
2024-10-30 15:22:06 +01:00
|
|
|
"-storageNode=" + vmstorage.VmselectAddr(),
|
2024-11-08 14:49:00 +01:00
|
|
|
})
|
|
|
|
vmselectL2 := tc.MustStartVmselect("vmselect-level2", []string{
|
2024-10-30 15:22:06 +01:00
|
|
|
"-storageNode=" + vmselectL1.ClusternativeListenAddr(),
|
2024-11-08 14:49:00 +01:00
|
|
|
})
|
2024-10-30 15:22:06 +01:00
|
|
|
|
|
|
|
// Insert 1000 unique time series.Wait for 2 seconds to let vmstorage
|
|
|
|
// flush pending items so they become searchable.
|
|
|
|
|
|
|
|
const numMetrics = 1000
|
|
|
|
records := make([]string, numMetrics)
|
|
|
|
for i := range numMetrics {
|
|
|
|
records[i] = fmt.Sprintf("metric_%d %d", i, rand.IntN(1000))
|
|
|
|
}
|
2024-11-07 12:58:37 +01:00
|
|
|
vminsert.PrometheusAPIV1ImportPrometheus(t, records, apptest.QueryOpts{Tenant: "0"})
|
2024-10-30 15:22:06 +01:00
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
|
|
|
|
// Retrieve all time series and verify that vmselect (L1) serves the complete
|
|
|
|
// set of time series.
|
|
|
|
|
2024-11-07 12:58:37 +01:00
|
|
|
seriesL1 := vmselectL1.PrometheusAPIV1Series(t, `{__name__=~".*"}`, apptest.QueryOpts{Tenant: "0"})
|
2024-10-30 15:22:06 +01:00
|
|
|
if got, want := len(seriesL1.Data), numMetrics; got != want {
|
|
|
|
t.Fatalf("unexpected level-1 series count: got %d, want %d", got, want)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieve all time series and verify that vmselect (L2) serves the complete
|
|
|
|
// set of time series.
|
|
|
|
|
2024-11-07 12:58:37 +01:00
|
|
|
seriesL2 := vmselectL2.PrometheusAPIV1Series(t, `{__name__=~".*"}`, apptest.QueryOpts{Tenant: "0"})
|
2024-10-30 15:22:06 +01:00
|
|
|
if got, want := len(seriesL2.Data), numMetrics; got != want {
|
|
|
|
t.Fatalf("unexpected level-2 series count: got %d, want %d", got, want)
|
|
|
|
}
|
|
|
|
}
|