MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestIngester_UpdateLabelSetMetrics

Function TestIngester_UpdateLabelSetMetrics

pkg/ingester/ingester_test.go:7266–7345  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7264}
7265
7266func TestIngester_UpdateLabelSetMetrics(t *testing.T) {
7267 cfg := defaultIngesterTestConfig(t)
7268 cfg.BlocksStorageConfig.TSDB.BlockRanges = []time.Duration{2 * time.Hour}
7269 reg := prometheus.NewRegistry()
7270 limits := defaultLimitsTestConfig()
7271 limits.EnableNativeHistograms = true
7272 userID := "1"
7273 ctx := user.InjectOrgID(context.Background(), userID)
7274
7275 limits.LimitsPerLabelSet = []validation.LimitsPerLabelSet{
7276 {
7277 LabelSet: labels.FromMap(map[string]string{
7278 "foo": "bar",
7279 }),
7280 Limits: validation.LimitsPerLabelSetEntry{
7281 MaxSeries: 1,
7282 },
7283 },
7284 {
7285 LabelSet: labels.EmptyLabels(),
7286 },
7287 }
7288 tenantLimits := newMockTenantLimits(map[string]*validation.Limits{userID: &limits})
7289
7290 dir := t.TempDir()
7291 chunksDir := filepath.Join(dir, "chunks")
7292 blocksDir := filepath.Join(dir, "blocks")
7293 require.NoError(t, os.Mkdir(chunksDir, os.ModePerm))
7294 require.NoError(t, os.Mkdir(blocksDir, os.ModePerm))
7295
7296 i, err := prepareIngesterWithBlocksStorageAndLimits(t, cfg, limits, tenantLimits, blocksDir, reg)
7297 require.NoError(t, err)
7298 require.NoError(t, services.StartAndAwaitRunning(context.Background(), i))
7299 defer services.StopAndAwaitTerminated(context.Background(), i) //nolint:errcheck
7300
7301 // Wait until it's ACTIVE
7302 test.Poll(t, time.Second, ring.ACTIVE, func() any {
7303 return i.lifecycler.GetState()
7304 })
7305 // Add user ID.
7306 wreq := &cortexpb.WriteRequest{
7307 Timeseries: []cortexpb.PreallocTimeseries{
7308 {TimeSeries: &cortexpb.TimeSeries{
7309 Labels: cortexpb.FromLabelsToLabelAdapters(labels.FromMap(map[string]string{model.MetricNameLabel: "test", "foo": "bar"})),
7310 Samples: []cortexpb.Sample{{Value: 0, TimestampMs: 1}},
7311 }},
7312 },
7313 }
7314 _, err = i.Push(ctx, wreq)
7315 require.NoError(t, err)
7316
7317 // Push one more series will trigger throttle by label set.
7318 wreq = &cortexpb.WriteRequest{
7319 Timeseries: []cortexpb.PreallocTimeseries{
7320 {TimeSeries: &cortexpb.TimeSeries{
7321 Labels: cortexpb.FromLabelsToLabelAdapters(labels.FromMap(map[string]string{model.MetricNameLabel: "test2", "foo": "bar"})),
7322 Samples: []cortexpb.Sample{{Value: 0, TimestampMs: 0}},
7323 }},

Callers

nothing calls this directly

Calls 14

StartAndAwaitRunningFunction · 0.92
StopAndAwaitTerminatedFunction · 0.92
PollFunction · 0.92
defaultLimitsTestConfigFunction · 0.85
JoinMethod · 0.80
closeAllTSDBMethod · 0.80
newMockTenantLimitsFunction · 0.70
PushMethod · 0.65
GetStateMethod · 0.45

Tested by

no test coverage detected