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

Function TestIngesterPerLabelsetLimitExceeded

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

Source from the content-addressed store, hash-verified

257}
258
259func TestIngesterPerLabelsetLimitExceeded(t *testing.T) {
260 limits := defaultLimitsTestConfig()
261 limits.EnableNativeHistograms = true
262 userID := "1"
263 registry := prometheus.NewRegistry()
264
265 limits.LimitsPerLabelSet = []validation.LimitsPerLabelSet{
266 {
267 LabelSet: labels.FromMap(map[string]string{
268 "label1": "value1",
269 }),
270 Limits: validation.LimitsPerLabelSetEntry{
271 MaxSeries: 3,
272 },
273 },
274 {
275 LabelSet: labels.FromMap(map[string]string{
276 "label2": "value2",
277 }),
278 Limits: validation.LimitsPerLabelSetEntry{
279 MaxSeries: 2,
280 },
281 },
282 }
283 tenantLimits := newMockTenantLimits(map[string]*validation.Limits{userID: &limits})
284
285 b, err := json.Marshal(limits)
286 require.NoError(t, err)
287 require.NoError(t, limits.UnmarshalJSON(b))
288
289 dir := t.TempDir()
290 chunksDir := filepath.Join(dir, "chunks")
291 blocksDir := filepath.Join(dir, "blocks")
292 require.NoError(t, os.Mkdir(chunksDir, os.ModePerm))
293 require.NoError(t, os.Mkdir(blocksDir, os.ModePerm))
294
295 ing, err := prepareIngesterWithBlocksStorageAndLimits(t, defaultIngesterTestConfig(t), limits, tenantLimits, blocksDir, registry)
296 require.NoError(t, err)
297 require.NoError(t, services.StartAndAwaitRunning(context.Background(), ing))
298 // Wait until it's ACTIVE
299 test.Poll(t, time.Second, ring.ACTIVE, func() any {
300 return ing.lifecycler.GetState()
301 })
302
303 ctx := user.InjectOrgID(context.Background(), userID)
304 samples := []cortexpb.Sample{{Value: 2, TimestampMs: 10}}
305
306 // Create first series within the limits
307 for _, set := range limits.LimitsPerLabelSet {
308 lbls := []string{labels.MetricName, "metric_name"}
309 set.LabelSet.Range(func(l labels.Label) {
310 lbls = append(lbls, l.Name, l.Value)
311 })
312 for i := 0; i < set.Limits.MaxSeries; i++ {
313 _, err = ing.Push(ctx, cortexpb.ToWriteRequest(
314 []labels.Labels{labels.FromStrings(append(lbls, "extraLabel", fmt.Sprintf("extraValue%v", i))...)}, samples, nil, nil, cortexpb.API))
315 require.NoError(t, err)
316 }

Callers

nothing calls this directly

Calls 15

StartAndAwaitRunningFunction · 0.92
PollFunction · 0.92
ToWriteRequestFunction · 0.92
StopAndAwaitTerminatedFunction · 0.92
defaultLimitsTestConfigFunction · 0.85
JoinMethod · 0.80
updateActiveSeriesMethod · 0.80
getTSDBMethod · 0.80
newMockTenantLimitsFunction · 0.70

Tested by

no test coverage detected