Skip to content

Commit e9d038c

Browse files
authored
Fix race on the LabelSet Counter (#6409)
* Configure labelset limits on the TestPushRace Signed-off-by: alanprot <[email protected]> * Fix race Signed-off-by: alanprot <[email protected]> * Changelog Signed-off-by: alanprot <[email protected]> --------- Signed-off-by: alanprot <[email protected]> Signed-off-by: Alan Protasio <[email protected]>
1 parent 5d2dac0 commit e9d038c

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

Diff for: CHANGELOG.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@
4545
* [ENHANCEMENT] Distributor: Expose `cortex_label_size_bytes` native histogram metric. #6372
4646
* [ENHANCEMENT] Add new option `-server.grpc_server-num-stream-workers` to configure the number of worker goroutines that should be used to process incoming streams. #6386
4747
* [ENHANCEMENT] Distributor: Return HTTP 5XX instead of HTTP 4XX when instance limits are hit. #6358
48-
* [ENHANCEMENT] Ingester: Add a new `-distributor.num-push-workers` flag to use a goroutine worker pool when sending data from distributor to ingesters. #6406
49-
* [ENHANCEMENT] Distributor: Create a goroutine worker pool to send data from distributors to ingesters.
48+
* [ENHANCEMENT] Ingester: Make sure unregistered ingester joining the ring after WAL replay. #6277
5049
* [BUGFIX] Runtime-config: Handle absolute file paths when working directory is not / #6224
5150
* [BUGFIX] Ruler: Allow rule evaluation to complete during shutdown. #6326
52-
* [BUGFIX] Ring: update ring with new ip address when instance is lost, rejoins, but heartbeat is disabled #6271
53-
* [BUGFIX] ingester: Fix regression on usage of cortex_ingester_queried_chunks #6398
51+
* [BUGFIX] Ring: update ring with new ip address when instance is lost, rejoins, but heartbeat is disabled. #6271
52+
* [BUGFIX] Ingester: Fix regression on usage of cortex_ingester_queried_chunks. #6398
53+
* [ENHANCEMENT] Distributor: Add a new `-distributor.num-push-workers` flag to use a goroutine worker pool when sending data from distributor to ingesters. #6406
54+
* [BUGFIX] Ingester: Fix possible race condition when `active series per LabelSet` is configured. #6409
5455

5556
## 1.18.1 2024-10-14
5657

Diff for: pkg/ingester/ingester_test.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -407,14 +407,26 @@ func TestIngesterPerLabelsetLimitExceeded(t *testing.T) {
407407

408408
func TestPushRace(t *testing.T) {
409409
cfg := defaultIngesterTestConfig(t)
410+
l := defaultLimitsTestConfig()
410411
cfg.LabelsStringInterningEnabled = true
411412
cfg.LifecyclerConfig.JoinAfter = 0
413+
414+
l.LimitsPerLabelSet = []validation.LimitsPerLabelSet{
415+
{
416+
LabelSet: labels.FromMap(map[string]string{
417+
labels.MetricName: "foo",
418+
}),
419+
Limits: validation.LimitsPerLabelSetEntry{
420+
MaxSeries: 10e10,
421+
},
422+
},
423+
}
424+
412425
dir := t.TempDir()
413426
blocksDir := filepath.Join(dir, "blocks")
414-
415427
require.NoError(t, os.Mkdir(blocksDir, os.ModePerm))
416428

417-
ing, err := prepareIngesterWithBlocksStorageAndLimits(t, cfg, defaultLimitsTestConfig(), nil, blocksDir, prometheus.NewRegistry(), true)
429+
ing, err := prepareIngesterWithBlocksStorageAndLimits(t, cfg, l, nil, blocksDir, prometheus.NewRegistry(), true)
418430
require.NoError(t, err)
419431
defer services.StopAndAwaitTerminated(context.Background(), ing) //nolint:errcheck
420432
require.NoError(t, services.StartAndAwaitRunning(context.Background(), ing))

Diff for: pkg/ingester/user_state.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (m *labelSetCounter) canAddSeriesForLabelSet(ctx context.Context, u *userTS
118118
s := m.shards[util.HashFP(model.Fingerprint(set.Hash))%numMetricCounterShards]
119119
s.RLock()
120120
if r, ok := s.valuesCounter[set.Hash]; ok {
121-
s.RUnlock()
121+
defer s.RUnlock()
122122
return r.count, nil
123123
}
124124
s.RUnlock()

0 commit comments

Comments
 (0)