From b9fa5978b0fd7ff087ba826f4deaca26d9b15cff Mon Sep 17 00:00:00 2001 From: Vladimir Varankin Date: Wed, 13 Nov 2024 09:36:13 +0100 Subject: [PATCH] vendor: cherry-pick prometheus/prometheus#15242 (#9889) Signed-off-by: Vladimir Varankin --- go.mod | 2 +- go.sum | 4 ++-- .../prometheus/tsdb/index/postings.go | 23 +++++++++++++++++++ vendor/modules.txt | 4 ++-- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 1fb24ed3505..0dfc65bda87 100644 --- a/go.mod +++ b/go.mod @@ -279,7 +279,7 @@ require ( ) // Using a fork of Prometheus with Mimir-specific changes. -replace github.com/prometheus/prometheus => github.com/grafana/mimir-prometheus v0.0.0-20241009132338-f7ed04967d38 +replace github.com/prometheus/prometheus => github.com/grafana/mimir-prometheus v0.0.0-20241113080331-8bca08eae66d // client_golang v1.20.3 has some data races in histogram exemplars. // Stick to v1.19.1 until they are fixed. diff --git a/go.sum b/go.sum index c5a8cf125ea..23e70b8eaaf 100644 --- a/go.sum +++ b/go.sum @@ -1265,8 +1265,8 @@ github.com/grafana/gomemcache v0.0.0-20240229205252-cd6a66d6fb56 h1:X8IKQ0wu40wp github.com/grafana/gomemcache v0.0.0-20240229205252-cd6a66d6fb56/go.mod h1:PGk3RjYHpxMM8HFPhKKo+vve3DdlPUELZLSDEFehPuU= github.com/grafana/memberlist v0.3.1-0.20220714140823-09ffed8adbbe h1:yIXAAbLswn7VNWBIvM71O2QsgfgW9fRXZNR0DXe6pDU= github.com/grafana/memberlist v0.3.1-0.20220714140823-09ffed8adbbe/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE= -github.com/grafana/mimir-prometheus v0.0.0-20241009132338-f7ed04967d38 h1:XeyYMfE7MFnrUd5J+evBFAA05L8jenFKhd23Ecef/cU= -github.com/grafana/mimir-prometheus v0.0.0-20241009132338-f7ed04967d38/go.mod h1:oyDm7JaLUh+QGuGkC7iXC8IyTUq5rlh1ba2CRm9DlVg= +github.com/grafana/mimir-prometheus v0.0.0-20241113080331-8bca08eae66d h1:YqzMvY3suPR01Y4G7NomfEf7VOTJq8dVGBHCMoES4k4= +github.com/grafana/mimir-prometheus v0.0.0-20241113080331-8bca08eae66d/go.mod h1:oyDm7JaLUh+QGuGkC7iXC8IyTUq5rlh1ba2CRm9DlVg= github.com/grafana/opentracing-contrib-go-stdlib v0.0.0-20230509071955-f410e79da956 h1:em1oddjXL8c1tL0iFdtVtPloq2hRPen2MJQKoAWpxu0= github.com/grafana/opentracing-contrib-go-stdlib v0.0.0-20230509071955-f410e79da956/go.mod h1:qtI1ogk+2JhVPIXVc6q+NHziSmy2W5GbdQZFUHADCBU= github.com/grafana/prometheus-alertmanager v0.25.1-0.20240906122908-60521fae6a42 h1:01cldIKyxTrraTYroDWNBItBWWs9Bh07I4rSOakLilo= diff --git a/vendor/github.com/prometheus/prometheus/tsdb/index/postings.go b/vendor/github.com/prometheus/prometheus/tsdb/index/postings.go index 1b36b0b153f..a8fdb98bc0d 100644 --- a/vendor/github.com/prometheus/prometheus/tsdb/index/postings.go +++ b/vendor/github.com/prometheus/prometheus/tsdb/index/postings.go @@ -24,6 +24,7 @@ import ( "sort" "strings" "sync" + "time" "github.com/bboreham/go-loser" @@ -312,8 +313,30 @@ func (p *MemPostings) Delete(deleted map[storage.SeriesRef]struct{}, affected ma } } + i := 0 for l := range affected { + i++ process(l) + + // From time to time we want some readers to go through and read their postings. + // It takes around 50ms to process a 1K series batch, and 120ms to process a 10K series batch (local benchmarks on an M3). + // Note that a read query will most likely want to read multiple postings lists, say 5, 10 or 20 (depending on the number of matchers) + // And that read query will most likely evaluate only one of those matchers before we unpause here, so we want to pause often. + if i%512 == 0 { + p.mtx.Unlock() + // While it's tempting to just do a `time.Sleep(time.Millisecond)` here, + // it wouldn't ensure use that readers actually were able to get the read lock, + // because if there are writes waiting on same mutex, readers won't be able to get it. + // So we just grab one RLock ourselves. + p.mtx.RLock() + // We shouldn't wait here, because we would be blocking a potential write for no reason. + // Note that if there's a writer waiting for us to unlock, no reader will be able to get the read lock. + p.mtx.RUnlock() //nolint:staticcheck // SA2001: this is an intentionally empty critical section. + // Now we can wait a little bit just to increase the chance of a reader getting the lock. + // If we were deleting 100M series here, pausing every 512 with 1ms sleeps would be an extra of 200s, which is negligible. + time.Sleep(time.Millisecond) + p.mtx.Lock() + } } process(allPostingsKey) } diff --git a/vendor/modules.txt b/vendor/modules.txt index a25b4bf8ab3..1104952b8cb 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1001,7 +1001,7 @@ github.com/prometheus/exporter-toolkit/web github.com/prometheus/procfs github.com/prometheus/procfs/internal/fs github.com/prometheus/procfs/internal/util -# github.com/prometheus/prometheus v1.99.0 => github.com/grafana/mimir-prometheus v0.0.0-20241009132338-f7ed04967d38 +# github.com/prometheus/prometheus v1.99.0 => github.com/grafana/mimir-prometheus v0.0.0-20241113080331-8bca08eae66d ## explicit; go 1.22.0 github.com/prometheus/prometheus/config github.com/prometheus/prometheus/discovery @@ -1653,7 +1653,7 @@ sigs.k8s.io/kustomize/kyaml/yaml/walk sigs.k8s.io/yaml sigs.k8s.io/yaml/goyaml.v2 sigs.k8s.io/yaml/goyaml.v3 -# github.com/prometheus/prometheus => github.com/grafana/mimir-prometheus v0.0.0-20241009132338-f7ed04967d38 +# github.com/prometheus/prometheus => github.com/grafana/mimir-prometheus v0.0.0-20241113080331-8bca08eae66d # github.com/prometheus/client_golang => github.com/prometheus/client_golang v1.19.1 # github.com/hashicorp/memberlist => github.com/grafana/memberlist v0.3.1-0.20220714140823-09ffed8adbbe # gopkg.in/yaml.v3 => github.com/colega/go-yaml-yaml v0.0.0-20220720105220-255a8d16d094