2021-10-29 08:25:05 -07:00
|
|
|
// Copyright 2021 The Prometheus Authors
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package agent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"strconv"
|
|
|
|
"sync"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/go-kit/log"
|
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
dto "github.com/prometheus/client_model/go"
|
2021-10-22 01:19:38 -07:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2021-11-08 06:23:17 -08:00
|
|
|
"github.com/prometheus/prometheus/model/labels"
|
2021-10-29 08:25:05 -07:00
|
|
|
"github.com/prometheus/prometheus/storage/remote"
|
|
|
|
"github.com/prometheus/prometheus/tsdb/record"
|
|
|
|
"github.com/prometheus/prometheus/tsdb/tsdbutil"
|
|
|
|
"github.com/prometheus/prometheus/tsdb/wal"
|
2021-11-11 08:45:25 -08:00
|
|
|
"github.com/prometheus/prometheus/util/testutil"
|
2021-10-29 08:25:05 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestUnsupported(t *testing.T) {
|
2021-11-10 06:35:54 -08:00
|
|
|
promAgentDir := t.TempDir()
|
2021-10-29 08:25:05 -07:00
|
|
|
|
|
|
|
opts := DefaultOptions()
|
|
|
|
logger := log.NewNopLogger()
|
|
|
|
|
2021-11-10 02:46:01 -08:00
|
|
|
s, err := Open(logger, prometheus.NewRegistry(), nil, promAgentDir, opts)
|
2021-11-10 06:35:54 -08:00
|
|
|
require.NoError(t, err)
|
|
|
|
defer func() {
|
|
|
|
require.NoError(t, s.Close())
|
|
|
|
}()
|
2021-10-29 08:25:05 -07:00
|
|
|
|
|
|
|
t.Run("Querier", func(t *testing.T) {
|
|
|
|
_, err := s.Querier(context.TODO(), 0, 0)
|
|
|
|
require.Equal(t, err, ErrUnsupported)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("ChunkQuerier", func(t *testing.T) {
|
|
|
|
_, err := s.ChunkQuerier(context.TODO(), 0, 0)
|
|
|
|
require.Equal(t, err, ErrUnsupported)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("ExemplarQuerier", func(t *testing.T) {
|
|
|
|
_, err := s.ExemplarQuerier(context.TODO())
|
|
|
|
require.Equal(t, err, ErrUnsupported)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommit(t *testing.T) {
|
|
|
|
const (
|
|
|
|
numDatapoints = 1000
|
|
|
|
numSeries = 8
|
|
|
|
)
|
|
|
|
|
2021-11-10 06:35:54 -08:00
|
|
|
promAgentDir := t.TempDir()
|
2021-10-29 08:25:05 -07:00
|
|
|
|
|
|
|
lbls := labelsForTest(t.Name(), numSeries)
|
|
|
|
opts := DefaultOptions()
|
|
|
|
logger := log.NewNopLogger()
|
|
|
|
reg := prometheus.NewRegistry()
|
|
|
|
remoteStorage := remote.NewStorage(log.With(logger, "component", "remote"), reg, startTime, promAgentDir, time.Second*30, nil)
|
2021-11-10 06:35:54 -08:00
|
|
|
defer func(rs *remote.Storage) {
|
|
|
|
require.NoError(t, rs.Close())
|
|
|
|
}(remoteStorage)
|
2021-10-29 08:25:05 -07:00
|
|
|
|
|
|
|
s, err := Open(logger, reg, remoteStorage, promAgentDir, opts)
|
2021-11-10 06:35:54 -08:00
|
|
|
require.NoError(t, err)
|
2021-10-29 08:25:05 -07:00
|
|
|
|
|
|
|
a := s.Appender(context.TODO())
|
|
|
|
|
|
|
|
for _, l := range lbls {
|
|
|
|
lset := labels.New(l...)
|
|
|
|
|
|
|
|
for i := 0; i < numDatapoints; i++ {
|
|
|
|
sample := tsdbutil.GenerateSamples(0, 1)
|
|
|
|
_, err := a.Append(0, lset, sample[0].T(), sample[0].V())
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-11 08:45:25 -08:00
|
|
|
require.NoError(t, a.Commit())
|
|
|
|
require.NoError(t, s.Close())
|
|
|
|
|
2021-10-29 08:25:05 -07:00
|
|
|
// Read records from WAL and check for expected count of series and samples.
|
|
|
|
walSeriesCount := 0
|
|
|
|
walSamplesCount := 0
|
|
|
|
|
|
|
|
reg = prometheus.NewRegistry()
|
|
|
|
remoteStorage = remote.NewStorage(log.With(logger, "component", "remote"), reg, startTime, promAgentDir, time.Second*30, nil)
|
2021-11-10 06:35:54 -08:00
|
|
|
defer func() {
|
|
|
|
require.NoError(t, remoteStorage.Close())
|
|
|
|
}()
|
2021-10-29 08:25:05 -07:00
|
|
|
|
2021-11-10 06:35:54 -08:00
|
|
|
s1, err := Open(logger, nil, remoteStorage, promAgentDir, opts)
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer func() {
|
|
|
|
require.NoError(t, s1.Close())
|
|
|
|
}()
|
2021-10-29 08:25:05 -07:00
|
|
|
|
|
|
|
var dec record.Decoder
|
|
|
|
|
|
|
|
if err == nil {
|
2021-11-10 06:35:54 -08:00
|
|
|
sr, err := wal.NewSegmentsReader(s1.wal.Dir())
|
2021-10-29 08:25:05 -07:00
|
|
|
require.NoError(t, err)
|
2021-11-10 06:35:54 -08:00
|
|
|
defer func() {
|
|
|
|
require.NoError(t, sr.Close())
|
|
|
|
}()
|
2021-10-29 08:25:05 -07:00
|
|
|
|
|
|
|
r := wal.NewReader(sr)
|
|
|
|
seriesPool := sync.Pool{
|
|
|
|
New: func() interface{} {
|
|
|
|
return []record.RefSeries{}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
samplesPool := sync.Pool{
|
|
|
|
New: func() interface{} {
|
|
|
|
return []record.RefSample{}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for r.Next() {
|
|
|
|
rec := r.Record()
|
|
|
|
switch dec.Type(rec) {
|
|
|
|
case record.Series:
|
|
|
|
series := seriesPool.Get().([]record.RefSeries)[:0]
|
|
|
|
series, _ = dec.Series(rec, series)
|
|
|
|
walSeriesCount += len(series)
|
|
|
|
case record.Samples:
|
|
|
|
samples := samplesPool.Get().([]record.RefSample)[:0]
|
|
|
|
samples, _ = dec.Samples(rec, samples)
|
|
|
|
walSamplesCount += len(samples)
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieved series count from WAL should match the count of series been added to the WAL.
|
|
|
|
require.Equal(t, walSeriesCount, numSeries)
|
|
|
|
|
|
|
|
// Retrieved samples count from WAL should match the count of samples been added to the WAL.
|
|
|
|
require.Equal(t, walSamplesCount, numSeries*numDatapoints)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRollback(t *testing.T) {
|
|
|
|
const (
|
|
|
|
numDatapoints = 1000
|
|
|
|
numSeries = 8
|
|
|
|
)
|
|
|
|
|
2021-11-10 06:35:54 -08:00
|
|
|
promAgentDir := t.TempDir()
|
2021-10-29 08:25:05 -07:00
|
|
|
|
|
|
|
lbls := labelsForTest(t.Name(), numSeries)
|
|
|
|
opts := DefaultOptions()
|
|
|
|
logger := log.NewNopLogger()
|
|
|
|
reg := prometheus.NewRegistry()
|
|
|
|
remoteStorage := remote.NewStorage(log.With(logger, "component", "remote"), reg, startTime, promAgentDir, time.Second*30, nil)
|
2021-11-10 06:35:54 -08:00
|
|
|
defer func(rs *remote.Storage) {
|
|
|
|
require.NoError(t, rs.Close())
|
|
|
|
}(remoteStorage)
|
2021-10-29 08:25:05 -07:00
|
|
|
|
|
|
|
s, err := Open(logger, reg, remoteStorage, promAgentDir, opts)
|
2021-11-10 06:35:54 -08:00
|
|
|
require.NoError(t, err)
|
2021-10-29 08:25:05 -07:00
|
|
|
|
|
|
|
a := s.Appender(context.TODO())
|
|
|
|
|
|
|
|
for _, l := range lbls {
|
|
|
|
lset := labels.New(l...)
|
|
|
|
|
|
|
|
for i := 0; i < numDatapoints; i++ {
|
|
|
|
sample := tsdbutil.GenerateSamples(0, 1)
|
|
|
|
_, err := a.Append(0, lset, sample[0].T(), sample[0].V())
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
require.NoError(t, a.Rollback())
|
2021-11-11 08:45:25 -08:00
|
|
|
require.NoError(t, s.Close())
|
2021-10-29 08:25:05 -07:00
|
|
|
|
|
|
|
// Read records from WAL and check for expected count of series and samples.
|
|
|
|
walSeriesCount := 0
|
|
|
|
walSamplesCount := 0
|
|
|
|
|
|
|
|
reg = prometheus.NewRegistry()
|
|
|
|
remoteStorage = remote.NewStorage(log.With(logger, "component", "remote"), reg, startTime, promAgentDir, time.Second*30, nil)
|
2021-11-10 06:35:54 -08:00
|
|
|
defer func() {
|
|
|
|
require.NoError(t, remoteStorage.Close())
|
|
|
|
}()
|
2021-10-29 08:25:05 -07:00
|
|
|
|
2021-11-10 06:35:54 -08:00
|
|
|
s1, err := Open(logger, nil, remoteStorage, promAgentDir, opts)
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer func() {
|
|
|
|
require.NoError(t, s1.Close())
|
|
|
|
}()
|
2021-10-29 08:25:05 -07:00
|
|
|
|
|
|
|
var dec record.Decoder
|
|
|
|
|
|
|
|
if err == nil {
|
2021-11-10 06:35:54 -08:00
|
|
|
sr, err := wal.NewSegmentsReader(s1.wal.Dir())
|
2021-10-29 08:25:05 -07:00
|
|
|
require.NoError(t, err)
|
2021-11-10 06:35:54 -08:00
|
|
|
defer func() {
|
|
|
|
require.NoError(t, sr.Close())
|
|
|
|
}()
|
2021-10-29 08:25:05 -07:00
|
|
|
|
|
|
|
r := wal.NewReader(sr)
|
|
|
|
seriesPool := sync.Pool{
|
|
|
|
New: func() interface{} {
|
|
|
|
return []record.RefSeries{}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
samplesPool := sync.Pool{
|
|
|
|
New: func() interface{} {
|
|
|
|
return []record.RefSample{}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for r.Next() {
|
|
|
|
rec := r.Record()
|
|
|
|
switch dec.Type(rec) {
|
|
|
|
case record.Series:
|
|
|
|
series := seriesPool.Get().([]record.RefSeries)[:0]
|
|
|
|
series, _ = dec.Series(rec, series)
|
|
|
|
walSeriesCount += len(series)
|
|
|
|
case record.Samples:
|
|
|
|
samples := samplesPool.Get().([]record.RefSample)[:0]
|
|
|
|
samples, _ = dec.Samples(rec, samples)
|
|
|
|
walSamplesCount += len(samples)
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieved series count from WAL should be zero.
|
|
|
|
require.Equal(t, walSeriesCount, 0)
|
|
|
|
|
|
|
|
// Retrieved samples count from WAL should be zero.
|
|
|
|
require.Equal(t, walSamplesCount, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFullTruncateWAL(t *testing.T) {
|
|
|
|
const (
|
|
|
|
numDatapoints = 1000
|
|
|
|
numSeries = 800
|
|
|
|
lastTs = 500
|
|
|
|
)
|
|
|
|
|
2021-11-10 06:35:54 -08:00
|
|
|
promAgentDir := t.TempDir()
|
2021-10-29 08:25:05 -07:00
|
|
|
|
|
|
|
lbls := labelsForTest(t.Name(), numSeries)
|
|
|
|
opts := DefaultOptions()
|
|
|
|
opts.TruncateFrequency = time.Minute * 2
|
|
|
|
logger := log.NewNopLogger()
|
|
|
|
reg := prometheus.NewRegistry()
|
|
|
|
remoteStorage := remote.NewStorage(log.With(logger, "component", "remote"), reg, startTime, promAgentDir, time.Second*30, nil)
|
2021-11-10 06:35:54 -08:00
|
|
|
defer func() {
|
|
|
|
require.NoError(t, remoteStorage.Close())
|
|
|
|
}()
|
2021-10-29 08:25:05 -07:00
|
|
|
|
|
|
|
s, err := Open(logger, reg, remoteStorage, promAgentDir, opts)
|
2021-11-10 06:35:54 -08:00
|
|
|
require.NoError(t, err)
|
|
|
|
defer func() {
|
|
|
|
require.NoError(t, s.Close())
|
|
|
|
}()
|
2021-10-29 08:25:05 -07:00
|
|
|
|
|
|
|
a := s.Appender(context.TODO())
|
|
|
|
|
|
|
|
for _, l := range lbls {
|
|
|
|
lset := labels.New(l...)
|
|
|
|
|
|
|
|
for i := 0; i < numDatapoints; i++ {
|
|
|
|
_, err := a.Append(0, lset, int64(lastTs), 0)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
require.NoError(t, a.Commit())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Truncate WAL with mint to GC all the samples.
|
|
|
|
s.truncate(lastTs + 1)
|
|
|
|
|
|
|
|
m := gatherFamily(t, reg, "prometheus_agent_deleted_series")
|
|
|
|
require.Equal(t, float64(numSeries), m.Metric[0].Gauge.GetValue(), "agent wal truncate mismatch of deleted series count")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPartialTruncateWAL(t *testing.T) {
|
|
|
|
const (
|
|
|
|
numDatapoints = 1000
|
|
|
|
numSeries = 800
|
|
|
|
)
|
|
|
|
|
2021-11-10 06:35:54 -08:00
|
|
|
promAgentDir := t.TempDir()
|
2021-10-29 08:25:05 -07:00
|
|
|
|
|
|
|
opts := DefaultOptions()
|
|
|
|
opts.TruncateFrequency = time.Minute * 2
|
|
|
|
logger := log.NewNopLogger()
|
|
|
|
reg := prometheus.NewRegistry()
|
|
|
|
remoteStorage := remote.NewStorage(log.With(logger, "component", "remote"), reg, startTime, promAgentDir, time.Second*30, nil)
|
2021-11-10 06:35:54 -08:00
|
|
|
defer func() {
|
|
|
|
require.NoError(t, remoteStorage.Close())
|
|
|
|
}()
|
2021-10-29 08:25:05 -07:00
|
|
|
|
|
|
|
s, err := Open(logger, reg, remoteStorage, promAgentDir, opts)
|
2021-11-10 06:35:54 -08:00
|
|
|
require.NoError(t, err)
|
|
|
|
defer func() {
|
|
|
|
require.NoError(t, s.Close())
|
|
|
|
}()
|
2021-10-29 08:25:05 -07:00
|
|
|
|
|
|
|
a := s.Appender(context.TODO())
|
|
|
|
|
|
|
|
var lastTs int64
|
|
|
|
|
|
|
|
// Create first batch of 800 series with 1000 data-points with a fixed lastTs as 500.
|
|
|
|
lastTs = 500
|
|
|
|
lbls := labelsForTest(t.Name()+"batch-1", numSeries)
|
|
|
|
for _, l := range lbls {
|
|
|
|
lset := labels.New(l...)
|
|
|
|
|
|
|
|
for i := 0; i < numDatapoints; i++ {
|
|
|
|
_, err := a.Append(0, lset, lastTs, 0)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
require.NoError(t, a.Commit())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create second batch of 800 series with 1000 data-points with a fixed lastTs as 600.
|
|
|
|
lastTs = 600
|
|
|
|
|
|
|
|
lbls = labelsForTest(t.Name()+"batch-2", numSeries)
|
|
|
|
for _, l := range lbls {
|
|
|
|
lset := labels.New(l...)
|
|
|
|
|
|
|
|
for i := 0; i < numDatapoints; i++ {
|
|
|
|
_, err := a.Append(0, lset, lastTs, 0)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
require.NoError(t, a.Commit())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Truncate WAL with mint to GC only the first batch of 800 series and retaining 2nd batch of 800 series.
|
|
|
|
s.truncate(lastTs - 1)
|
|
|
|
|
|
|
|
m := gatherFamily(t, reg, "prometheus_agent_deleted_series")
|
|
|
|
require.Equal(t, m.Metric[0].Gauge.GetValue(), float64(numSeries), "agent wal truncate mismatch of deleted series count")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestWALReplay(t *testing.T) {
|
|
|
|
const (
|
|
|
|
numDatapoints = 1000
|
|
|
|
numSeries = 8
|
|
|
|
lastTs = 500
|
|
|
|
)
|
|
|
|
|
2021-11-10 06:35:54 -08:00
|
|
|
promAgentDir := t.TempDir()
|
2021-10-29 08:25:05 -07:00
|
|
|
|
|
|
|
lbls := labelsForTest(t.Name(), numSeries)
|
|
|
|
opts := DefaultOptions()
|
|
|
|
|
|
|
|
logger := log.NewNopLogger()
|
|
|
|
reg := prometheus.NewRegistry()
|
|
|
|
remoteStorage := remote.NewStorage(log.With(logger, "component", "remote"), reg, startTime, promAgentDir, time.Second*30, nil)
|
2021-11-10 06:35:54 -08:00
|
|
|
defer func() {
|
|
|
|
require.NoError(t, remoteStorage.Close())
|
|
|
|
}()
|
2021-10-29 08:25:05 -07:00
|
|
|
|
|
|
|
s, err := Open(logger, reg, remoteStorage, promAgentDir, opts)
|
2021-11-10 06:35:54 -08:00
|
|
|
require.NoError(t, err)
|
2021-10-29 08:25:05 -07:00
|
|
|
|
|
|
|
a := s.Appender(context.TODO())
|
|
|
|
|
|
|
|
for _, l := range lbls {
|
|
|
|
lset := labels.New(l...)
|
|
|
|
|
|
|
|
for i := 0; i < numDatapoints; i++ {
|
|
|
|
_, err := a.Append(0, lset, lastTs, 0)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
require.NoError(t, a.Commit())
|
2021-11-10 06:35:54 -08:00
|
|
|
require.NoError(t, s.Close())
|
|
|
|
|
2021-10-29 08:25:05 -07:00
|
|
|
restartOpts := DefaultOptions()
|
|
|
|
restartLogger := log.NewNopLogger()
|
|
|
|
restartReg := prometheus.NewRegistry()
|
|
|
|
|
2021-11-11 08:45:25 -08:00
|
|
|
// Open a new DB with the same WAL to check that series from the previous DB
|
|
|
|
// get replayed.
|
|
|
|
replayDB, err := Open(restartLogger, restartReg, nil, promAgentDir, restartOpts)
|
2021-11-10 06:35:54 -08:00
|
|
|
require.NoError(t, err)
|
2021-11-11 08:45:25 -08:00
|
|
|
defer func() {
|
|
|
|
require.NoError(t, replayDB.Close())
|
|
|
|
}()
|
2021-10-29 08:25:05 -07:00
|
|
|
|
|
|
|
// Check if all the series are retrieved back from the WAL.
|
|
|
|
m := gatherFamily(t, restartReg, "prometheus_agent_active_series")
|
|
|
|
require.Equal(t, float64(numSeries), m.Metric[0].Gauge.GetValue(), "agent wal replay mismatch of active series count")
|
|
|
|
|
|
|
|
// Check if lastTs of the samples retrieved from the WAL is retained.
|
2021-11-11 08:45:25 -08:00
|
|
|
metrics := replayDB.series.series
|
2021-10-29 08:25:05 -07:00
|
|
|
for i := 0; i < len(metrics); i++ {
|
|
|
|
mp := metrics[i]
|
|
|
|
for _, v := range mp {
|
|
|
|
require.Equal(t, v.lastTs, int64(lastTs))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-11 08:45:25 -08:00
|
|
|
func TestLockfile(t *testing.T) {
|
|
|
|
tsdbutil.TestDirLockerUsage(t, func(t *testing.T, data string, createLock bool) (*tsdbutil.DirLocker, testutil.Closer) {
|
|
|
|
logger := log.NewNopLogger()
|
|
|
|
reg := prometheus.NewRegistry()
|
|
|
|
rs := remote.NewStorage(logger, reg, startTime, data, time.Second*30, nil)
|
|
|
|
t.Cleanup(func() {
|
|
|
|
require.NoError(t, rs.Close())
|
|
|
|
})
|
|
|
|
|
|
|
|
opts := DefaultOptions()
|
|
|
|
opts.NoLockfile = !createLock
|
|
|
|
|
|
|
|
// Create the DB. This should create lockfile and its metrics.
|
|
|
|
db, err := Open(logger, nil, rs, data, opts)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
return db.locker, testutil.NewCallbackCloser(func() {
|
|
|
|
require.NoError(t, db.Close())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-10-29 08:25:05 -07:00
|
|
|
func startTime() (int64, error) {
|
|
|
|
return time.Now().Unix() * 1000, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create series for tests.
|
|
|
|
func labelsForTest(lName string, seriesCount int) []labels.Labels {
|
|
|
|
var series []labels.Labels
|
|
|
|
|
|
|
|
for i := 0; i < seriesCount; i++ {
|
|
|
|
lset := labels.Labels{
|
|
|
|
{Name: "a", Value: lName},
|
|
|
|
{Name: "job", Value: "prometheus"},
|
|
|
|
{Name: "instance", Value: "localhost" + strconv.Itoa(i)},
|
|
|
|
}
|
|
|
|
series = append(series, lset)
|
|
|
|
}
|
|
|
|
|
|
|
|
return series
|
|
|
|
}
|
|
|
|
|
|
|
|
func gatherFamily(t *testing.T, reg prometheus.Gatherer, familyName string) *dto.MetricFamily {
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
families, err := reg.Gather()
|
|
|
|
require.NoError(t, err, "failed to gather metrics")
|
|
|
|
|
|
|
|
for _, f := range families {
|
|
|
|
if f.GetName() == familyName {
|
|
|
|
return f
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Fatalf("could not find family %s", familyName)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|