(t *testing.T)
| 257 | } |
| 258 | |
| 259 | func 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 | } |
nothing calls this directly
no test coverage detected