Skip to content

Commit e0812e2

Browse files
saswatamcodefpetkovskijnyi
authored
Cut patch release v0.37.1 (#7952)
* Merge pull request #7674 from didukh86/query_frontend_tls_redis_fix Query-frontend: Fix connection to Redis cluster with TLS. Signed-off-by: Saswata Mukherjee <[email protected]> * Capnp: Use segment from existing message (#7945) * Capnp: Use segment from existing message Signed-off-by: Filip Petkovski <[email protected]> * Downgrade capnproto Signed-off-by: Filip Petkovski <[email protected]> --------- Signed-off-by: Filip Petkovski <[email protected]> Signed-off-by: Saswata Mukherjee <[email protected]> * [Receive] Fix race condition when adding multiple new tenants at once (#7941) * [Receive] fix race condition Signed-off-by: Yi Jin <[email protected]> * add a change log Signed-off-by: Yi Jin <[email protected]> * memorize tsdb local clients without race condition Signed-off-by: Yi Jin <[email protected]> * fix data race in testing with some concurrent safe helper functions Signed-off-by: Yi Jin <[email protected]> * address comments Signed-off-by: Yi Jin <[email protected]> --------- Signed-off-by: Yi Jin <[email protected]> Signed-off-by: Saswata Mukherjee <[email protected]> * Cut patch release v0.37.1 Signed-off-by: Saswata Mukherjee <[email protected]> * Update promql-engine for subquery fix (#7953) Signed-off-by: Saswata Mukherjee <[email protected]> * Sidecar: Ensure limit param is positive for compatibility with older Prometheus (#7954) Signed-off-by: Saswata Mukherjee <[email protected]> * Update changelog Signed-off-by: Saswata Mukherjee <[email protected]> * Fix changelog Signed-off-by: Saswata Mukherjee <[email protected]> --------- Signed-off-by: Saswata Mukherjee <[email protected]> Signed-off-by: Filip Petkovski <[email protected]> Signed-off-by: Yi Jin <[email protected]> Co-authored-by: Filip Petkovski <[email protected]> Co-authored-by: Yi Jin <[email protected]>
1 parent 889d527 commit e0812e2

File tree

12 files changed

+182
-132
lines changed

12 files changed

+182
-132
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ NOTE: As semantic versioning states all 0.y.z releases can contain breaking chan
88

99
We use *breaking :warning:* to mark changes that are not backward compatible (relates only to v0.y.z releases.)
1010

11+
## [v0.37.1](https://github.com/thanos-io/thanos/tree/release-0.37) - 03.12.2024
12+
13+
### Fixed
14+
15+
- [#7674](https://github.com/thanos-io/thanos/pull/7674) Query-frontend: Fix connection to Redis cluster with TLS.
16+
- [#7945](https://github.com/thanos-io/thanos/pull/7945) Receive: Capnproto - use segment from existing message.
17+
- [#7941](https://github.com/thanos-io/thanos/pull/7941) Receive: Fix race condition when adding multiple new tenants, see [issue-7892](https://github.com/thanos-io/thanos/issues/7892).
18+
- [#7954](https://github.com/thanos-io/thanos/pull/7954) Sidecar: Ensure limit param is positive for compatibility with older Prometheus.
19+
- [#7953](https://github.com/thanos-io/thanos/pull/7953) Query: Update promql-engine for subquery avg fix.
20+
21+
### Added
22+
23+
### Changed
24+
25+
### Removed
26+
1127
## [v0.37.0](https://github.com/thanos-io/thanos/tree/release-0.37) - 25.11.2024
1228

1329
### Fixed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.37.0
1+
0.37.1

docs/sharding.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Queries against store gateway which are touching large number of blocks (no matt
1818

1919
# Relabelling
2020

21-
Similar to [promtail](https://grafana.com/docs/loki/latest/send-data/promtail/configuration/#relabel_configs) this config follows native [Prometheus relabel-config](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config) syntax.
21+
Similar to [promtail](https://grafana.com/docs/loki/latest/clients/promtail/configuration/#relabel_configs) this config follows native [Prometheus relabel-config](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config) syntax.
2222

2323
Currently, thanos only supports the following relabel actions:
2424

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ require (
6262
github.com/sony/gobreaker v0.5.0
6363
github.com/stretchr/testify v1.9.0
6464
github.com/thanos-io/objstore v0.0.0-20241111205755-d1dd89d41f97
65-
github.com/thanos-io/promql-engine v0.0.0-20241106100125-097e6e9f425a
65+
github.com/thanos-io/promql-engine v0.0.0-20241203103240-2f49f80c7c68
6666
github.com/uber/jaeger-client-go v2.30.0+incompatible
6767
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
6868
github.com/vimeo/galaxycache v0.0.0-20210323154928-b7e5d71c067a
@@ -112,7 +112,7 @@ require (
112112
)
113113

114114
require (
115-
capnproto.org/go/capnp/v3 v3.0.1-alpha.2.0.20240830165715-46ccd63a72af
115+
capnproto.org/go/capnp/v3 v3.0.0-alpha.30
116116
github.com/cortexproject/promqlsmith v0.0.0-20240506042652-6cfdd9739a5e
117117
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1
118118
github.com/hashicorp/golang-lru/v2 v2.0.7
@@ -133,7 +133,6 @@ require (
133133
github.com/HdrHistogram/hdrhistogram-go v1.1.2 // indirect
134134
github.com/bboreham/go-loser v0.0.0-20230920113527-fcc2c21820a3 // indirect
135135
github.com/cilium/ebpf v0.11.0 // indirect
136-
github.com/colega/zeropool v0.0.0-20230505084239-6fb4a4f75381 // indirect
137136
github.com/containerd/cgroups/v3 v3.0.3 // indirect
138137
github.com/docker/go-units v0.5.0 // indirect
139138
github.com/elastic/go-licenser v0.3.1 // indirect
@@ -167,6 +166,7 @@ require (
167166
k8s.io/client-go v0.31.0 // indirect
168167
k8s.io/klog/v2 v2.130.1 // indirect
169168
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
169+
zenhack.net/go/util v0.0.0-20230414204917-531d38494cf5 // indirect
170170
)
171171

172172
require (

go.sum

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
capnproto.org/go/capnp/v3 v3.0.1-alpha.2.0.20240830165715-46ccd63a72af h1:A5wxH0ZidOtYYUGjhtBaRuB87M73bGfc06uWB8sHpg0=
2-
capnproto.org/go/capnp/v3 v3.0.1-alpha.2.0.20240830165715-46ccd63a72af/go.mod h1:2vT5D2dtG8sJGEoEKU17e+j7shdaYp1Myl8X03B3hmc=
1+
capnproto.org/go/capnp/v3 v3.0.0-alpha.30 h1:iABQan/YiHFCgSXym5aNj27osapnEgAk4WaWYqb4sQM=
2+
capnproto.org/go/capnp/v3 v3.0.0-alpha.30/go.mod h1:+ysMHvOh1EWNOyorxJWs1omhRFiDoKxKkWQACp54jKM=
33
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
44
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
55
cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU=
@@ -1500,8 +1500,6 @@ github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa/go.mod h1:x/1Gn8zydmfq
15001500
github.com/cncf/xds/go v0.0.0-20240423153145-555b57ec207b h1:ga8SEFjZ60pxLcmhnThWgvH2wg8376yUJmPhEH4H3kw=
15011501
github.com/cncf/xds/go v0.0.0-20240423153145-555b57ec207b/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8=
15021502
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
1503-
github.com/colega/zeropool v0.0.0-20230505084239-6fb4a4f75381 h1:d5EKgQfRQvO97jnISfR89AiCCCJMwMFoSxUiU0OGCRU=
1504-
github.com/colega/zeropool v0.0.0-20230505084239-6fb4a4f75381/go.mod h1:OU76gHeRo8xrzGJU3F3I1CqX1ekM8dfJw0+wPeMwnp0=
15051503
github.com/containerd/cgroups/v3 v3.0.3 h1:S5ByHZ/h9PMe5IOQoN7E+nMc2UcLEM/V48DGDJ9kip0=
15061504
github.com/containerd/cgroups/v3 v3.0.3/go.mod h1:8HBe7V3aWGLFPd/k03swSIsGjZhHI2WzJmticMgVuz0=
15071505
github.com/coreos/go-systemd/v22 v22.4.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
@@ -2106,8 +2104,8 @@ github.com/ovh/go-ovh v1.6.0 h1:ixLOwxQdzYDx296sXcgS35TOPEahJkpjMGtzPadCjQI=
21062104
github.com/ovh/go-ovh v1.6.0/go.mod h1:cTVDnl94z4tl8pP1uZ/8jlVxntjSIf09bNcQ5TJSC7c=
21072105
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2DcNVpwGmV9E1BkGknEliJkfwQj0=
21082106
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y=
2109-
github.com/philhofer/fwd v1.1.2 h1:bnDivRJ1EWPjUIRXV5KfORO897HTbpFAQddBdE8t7Gw=
2110-
github.com/philhofer/fwd v1.1.2/go.mod h1:qkPdfjR2SIEbspLqpe1tO4n5yICnr2DY7mqEx2tUTP0=
2107+
github.com/philhofer/fwd v1.1.1 h1:GdGcTjf5RNAxwS4QLsiMzJYj5KEvPJD3Abr261yRQXQ=
2108+
github.com/philhofer/fwd v1.1.1/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
21112109
github.com/phpdave11/gofpdf v1.4.2/go.mod h1:zpO6xFn9yxo3YLyMvW8HcKWVdbNqgIfOOp2dXMnm1mY=
21122110
github.com/phpdave11/gofpdi v1.0.12/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
21132111
github.com/phpdave11/gofpdi v1.0.13/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
@@ -2259,14 +2257,12 @@ github.com/thanos-community/galaxycache v0.0.0-20211122094458-3a32041a1f1e h1:f1
22592257
github.com/thanos-community/galaxycache v0.0.0-20211122094458-3a32041a1f1e/go.mod h1:jXcofnrSln/cLI6/dhlBxPQZEEQHVPCcFaH75M+nSzM=
22602258
github.com/thanos-io/objstore v0.0.0-20241111205755-d1dd89d41f97 h1:VjG0mwhN1DkncwDHFvrpd12/2TLfgYNRmEQA48ikp+0=
22612259
github.com/thanos-io/objstore v0.0.0-20241111205755-d1dd89d41f97/go.mod h1:vyzFrBXgP+fGNG2FopEGWOO/zrIuoy7zt3LpLeezRsw=
2262-
github.com/thanos-io/promql-engine v0.0.0-20241106100125-097e6e9f425a h1:BhWU58VHOxkxQEMByih9fM2WwuwCGtk5AulIcSRSr0A=
2263-
github.com/thanos-io/promql-engine v0.0.0-20241106100125-097e6e9f425a/go.mod h1:wx0JlRZtsB2S10JYUgeg5GqLfMxw31SzArP+28yyE00=
2260+
github.com/thanos-io/promql-engine v0.0.0-20241203103240-2f49f80c7c68 h1:cChM/FbpXeYmrSmXO1/MmmSlONviLVxWAWCB0/g4JrY=
2261+
github.com/thanos-io/promql-engine v0.0.0-20241203103240-2f49f80c7c68/go.mod h1:wx0JlRZtsB2S10JYUgeg5GqLfMxw31SzArP+28yyE00=
22642262
github.com/themihai/gomemcache v0.0.0-20180902122335-24332e2d58ab h1:7ZR3hmisBWw77ZpO1/o86g+JV3VKlk3d48jopJxzTjU=
22652263
github.com/themihai/gomemcache v0.0.0-20180902122335-24332e2d58ab/go.mod h1:eheTFp954zcWZXCU8d0AT76ftsQOTo4DTqkN/h3k1MY=
2266-
github.com/tinylib/msgp v1.1.9 h1:SHf3yoO2sGA0veCJeCBYLHuttAVFHGm2RHgNodW7wQU=
2267-
github.com/tinylib/msgp v1.1.9/go.mod h1:BCXGB54lDD8qUEPmiG0cQQUANC4IUQyB2ItS2UDlO/k=
2268-
github.com/tj/assert v0.0.3 h1:Df/BlaZ20mq6kuai7f5z2TvPFiwC3xaWJSDQNiIS3Rk=
2269-
github.com/tj/assert v0.0.3/go.mod h1:Ne6X72Q+TB1AteidzQncjw9PabbMp4PBMZ1k+vd1Pvk=
2264+
github.com/tinylib/msgp v1.1.5 h1:2gXmtWueD2HefZHQe1QOy9HVzmFrLOVvsXwXBQ0ayy0=
2265+
github.com/tinylib/msgp v1.1.5/go.mod h1:eQsjooMTnV42mHu917E26IogZ2930nFyBQdofk10Udg=
22702266
github.com/tklauser/go-sysconf v0.3.4/go.mod h1:Cl2c8ZRWfHD5IrfHo9VN+FX9kCFjIOyVklgXycLB6ek=
22712267
github.com/tklauser/go-sysconf v0.3.10 h1:IJ1AZGZRWbY8T5Vfk04D9WOA5WSejdflXxP03OUqALw=
22722268
github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk=
@@ -3337,3 +3333,5 @@ sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+s
33373333
sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08=
33383334
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
33393335
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
3336+
zenhack.net/go/util v0.0.0-20230414204917-531d38494cf5 h1:yksDCGMVzyn3vlyf0GZ3huiF5FFaMGQpQ3UJvR0EoGA=
3337+
zenhack.net/go/util v0.0.0-20230414204917-531d38494cf5/go.mod h1:1LtNdPAs8WH+BTcQiZAOo2MIKD/5jyK/u7sZ9ZPe5SE=

pkg/promclient/promclient.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,9 @@ func (c *Client) SeriesInGRPC(ctx context.Context, base *url.URL, matchers []*la
787787
q.Add("match[]", storepb.PromMatchersToString(matchers...))
788788
q.Add("start", formatTime(timestamp.Time(startTime)))
789789
q.Add("end", formatTime(timestamp.Time(endTime)))
790-
q.Add("limit", strconv.Itoa(limit))
790+
if limit > 0 {
791+
q.Add("limit", strconv.Itoa(limit))
792+
}
791793
u.RawQuery = q.Encode()
792794

793795
var m struct {
@@ -809,7 +811,9 @@ func (c *Client) LabelNamesInGRPC(ctx context.Context, base *url.URL, matchers [
809811
}
810812
q.Add("start", formatTime(timestamp.Time(startTime)))
811813
q.Add("end", formatTime(timestamp.Time(endTime)))
812-
q.Add("limit", strconv.Itoa(limit))
814+
if limit > 0 {
815+
q.Add("limit", strconv.Itoa(limit))
816+
}
813817
u.RawQuery = q.Encode()
814818

815819
var m struct {
@@ -830,7 +834,9 @@ func (c *Client) LabelValuesInGRPC(ctx context.Context, base *url.URL, label str
830834
}
831835
q.Add("start", formatTime(timestamp.Time(startTime)))
832836
q.Add("end", formatTime(timestamp.Time(endTime)))
833-
q.Add("limit", strconv.Itoa(limit))
837+
if limit > 0 {
838+
q.Add("limit", strconv.Itoa(limit))
839+
}
834840
u.RawQuery = q.Encode()
835841

836842
var m struct {
@@ -898,7 +904,6 @@ func (c *Client) MetricMetadataInGRPC(ctx context.Context, base *url.URL, metric
898904
if metric != "" {
899905
q.Add("metric", metric)
900906
}
901-
// We only set limit when it is >= 0.
902907
if limit >= 0 {
903908
q.Add("limit", strconv.Itoa(limit))
904909
}

pkg/queryfrontend/config.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,15 @@ func NewCacheConfig(logger log.Logger, confContentYaml []byte) (*cortexcache.Con
162162
}
163163
return &cortexcache.Config{
164164
Redis: cortexcache.RedisConfig{
165-
Endpoint: config.Redis.Addr,
166-
Timeout: config.Redis.ReadTimeout,
167-
MasterName: config.Redis.MasterName,
168-
Expiration: config.Expiration,
169-
DB: config.Redis.DB,
170-
Password: flagext.Secret{Value: config.Redis.Password},
171-
Username: config.Redis.Username,
165+
Endpoint: config.Redis.Addr,
166+
Timeout: config.Redis.ReadTimeout,
167+
MasterName: config.Redis.MasterName,
168+
Expiration: config.Expiration,
169+
DB: config.Redis.DB,
170+
Password: flagext.Secret{Value: config.Redis.Password},
171+
Username: config.Redis.Username,
172+
EnableTLS: config.Redis.TLSEnabled,
173+
InsecureSkipVerify: config.Redis.TLSConfig.InsecureSkipVerify,
172174
},
173175
Background: cortexcache.BackgroundConfig{
174176
WriteBackBuffer: config.Redis.MaxSetMultiConcurrency * config.Redis.SetMultiBatchSize,

pkg/receive/multitsdb.go

Lines changed: 66 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,8 @@ type MultiTSDB struct {
6262
hashFunc metadata.HashFunc
6363
hashringConfigs []HashringConfig
6464

65-
tsdbClients []store.Client
66-
tsdbClientsNeedUpdate bool
67-
68-
exemplarClients map[string]*exemplars.TSDB
69-
exemplarClientsNeedUpdate bool
65+
tsdbClients []store.Client
66+
exemplarClients map[string]*exemplars.TSDB
7067

7168
metricNameFilterEnabled bool
7269
}
@@ -100,19 +97,19 @@ func NewMultiTSDB(
10097
}
10198

10299
mt := &MultiTSDB{
103-
dataDir: dataDir,
104-
logger: log.With(l, "component", "multi-tsdb"),
105-
reg: reg,
106-
tsdbOpts: tsdbOpts,
107-
mtx: &sync.RWMutex{},
108-
tenants: map[string]*tenant{},
109-
labels: labels,
110-
tsdbClientsNeedUpdate: true,
111-
exemplarClientsNeedUpdate: true,
112-
tenantLabelName: tenantLabelName,
113-
bucket: bucket,
114-
allowOutOfOrderUpload: allowOutOfOrderUpload,
115-
hashFunc: hashFunc,
100+
dataDir: dataDir,
101+
logger: log.With(l, "component", "multi-tsdb"),
102+
reg: reg,
103+
tsdbOpts: tsdbOpts,
104+
mtx: &sync.RWMutex{},
105+
tenants: map[string]*tenant{},
106+
labels: labels,
107+
tsdbClients: make([]store.Client, 0),
108+
exemplarClients: map[string]*exemplars.TSDB{},
109+
tenantLabelName: tenantLabelName,
110+
bucket: bucket,
111+
allowOutOfOrderUpload: allowOutOfOrderUpload,
112+
hashFunc: hashFunc,
116113
}
117114

118115
for _, option := range options {
@@ -122,6 +119,49 @@ func NewMultiTSDB(
122119
return mt
123120
}
124121

122+
// testGetTenant returns the tenant with the given tenantID for testing purposes.
123+
func (t *MultiTSDB) testGetTenant(tenantID string) *tenant {
124+
t.mtx.RLock()
125+
defer t.mtx.RUnlock()
126+
return t.tenants[tenantID]
127+
}
128+
129+
func (t *MultiTSDB) updateTSDBClients() {
130+
t.tsdbClients = t.tsdbClients[:0]
131+
for _, tenant := range t.tenants {
132+
client := tenant.client()
133+
if client != nil {
134+
t.tsdbClients = append(t.tsdbClients, client)
135+
}
136+
}
137+
}
138+
139+
func (t *MultiTSDB) addTenantUnlocked(tenantID string, newTenant *tenant) {
140+
t.tenants[tenantID] = newTenant
141+
t.updateTSDBClients()
142+
if newTenant.exemplars() != nil {
143+
t.exemplarClients[tenantID] = newTenant.exemplars()
144+
}
145+
}
146+
147+
func (t *MultiTSDB) addTenantLocked(tenantID string, newTenant *tenant) {
148+
t.mtx.Lock()
149+
defer t.mtx.Unlock()
150+
t.addTenantUnlocked(tenantID, newTenant)
151+
}
152+
153+
func (t *MultiTSDB) removeTenantUnlocked(tenantID string) {
154+
delete(t.tenants, tenantID)
155+
delete(t.exemplarClients, tenantID)
156+
t.updateTSDBClients()
157+
}
158+
159+
func (t *MultiTSDB) removeTenantLocked(tenantID string) {
160+
t.mtx.Lock()
161+
defer t.mtx.Unlock()
162+
t.removeTenantUnlocked(tenantID)
163+
}
164+
125165
type localClient struct {
126166
store *store.TSDBStore
127167

@@ -416,9 +456,7 @@ func (t *MultiTSDB) Prune(ctx context.Context) error {
416456
}
417457

418458
level.Info(t.logger).Log("msg", "Pruned tenant", "tenant", tenantID)
419-
delete(t.tenants, tenantID)
420-
t.tsdbClientsNeedUpdate = true
421-
t.exemplarClientsNeedUpdate = true
459+
t.removeTenantUnlocked(tenantID)
422460
}
423461

424462
return merr.Err()
@@ -578,58 +616,17 @@ func (t *MultiTSDB) RemoveLockFilesIfAny() error {
578616
return merr.Err()
579617
}
580618

619+
// TSDBLocalClients should be used as read-only.
581620
func (t *MultiTSDB) TSDBLocalClients() []store.Client {
582621
t.mtx.RLock()
583-
if !t.tsdbClientsNeedUpdate {
584-
t.mtx.RUnlock()
585-
return t.tsdbClients
586-
}
587-
588-
t.mtx.RUnlock()
589-
t.mtx.Lock()
590-
defer t.mtx.Unlock()
591-
if !t.tsdbClientsNeedUpdate {
592-
return t.tsdbClients
593-
}
594-
595-
res := make([]store.Client, 0, len(t.tenants))
596-
for _, tenant := range t.tenants {
597-
client := tenant.client()
598-
if client != nil {
599-
res = append(res, client)
600-
}
601-
}
602-
603-
t.tsdbClientsNeedUpdate = false
604-
t.tsdbClients = res
605-
622+
defer t.mtx.RUnlock()
606623
return t.tsdbClients
607624
}
608625

626+
// TSDBExemplars should be used as read-only.
609627
func (t *MultiTSDB) TSDBExemplars() map[string]*exemplars.TSDB {
610628
t.mtx.RLock()
611-
if !t.exemplarClientsNeedUpdate {
612-
t.mtx.RUnlock()
613-
return t.exemplarClients
614-
}
615-
t.mtx.RUnlock()
616-
t.mtx.Lock()
617-
defer t.mtx.Unlock()
618-
619-
if !t.exemplarClientsNeedUpdate {
620-
return t.exemplarClients
621-
}
622-
623-
res := make(map[string]*exemplars.TSDB, len(t.tenants))
624-
for k, tenant := range t.tenants {
625-
e := tenant.exemplars()
626-
if e != nil {
627-
res[k] = e
628-
}
629-
}
630-
631-
t.exemplarClientsNeedUpdate = false
632-
t.exemplarClients = res
629+
defer t.mtx.RUnlock()
633630
return t.exemplarClients
634631
}
635632

@@ -705,11 +702,7 @@ func (t *MultiTSDB) startTSDB(logger log.Logger, tenantID string, tenant *tenant
705702
nil,
706703
)
707704
if err != nil {
708-
t.mtx.Lock()
709-
delete(t.tenants, tenantID)
710-
t.tsdbClientsNeedUpdate = true
711-
t.exemplarClientsNeedUpdate = true
712-
t.mtx.Unlock()
705+
t.removeTenantLocked(tenantID)
713706
return err
714707
}
715708
var ship *shipper.Shipper
@@ -732,6 +725,7 @@ func (t *MultiTSDB) startTSDB(logger log.Logger, tenantID string, tenant *tenant
732725
options = append(options, store.WithCuckooMetricNameStoreFilter())
733726
}
734727
tenant.set(store.NewTSDBStore(logger, s, component.Receive, lset, options...), s, ship, exemplars.NewTSDB(s, lset))
728+
t.addTenantLocked(tenantID, tenant) // need to update the client list once store is ready & client != nil
735729
level.Info(logger).Log("msg", "TSDB is now ready")
736730
return nil
737731
}
@@ -760,9 +754,7 @@ func (t *MultiTSDB) getOrLoadTenant(tenantID string, blockingStart bool) (*tenan
760754
}
761755

762756
tenant = newTenant()
763-
t.tenants[tenantID] = tenant
764-
t.tsdbClientsNeedUpdate = true
765-
t.exemplarClientsNeedUpdate = true
757+
t.addTenantUnlocked(tenantID, tenant)
766758
t.mtx.Unlock()
767759

768760
logger := log.With(t.logger, "tenant", tenantID)

0 commit comments

Comments
 (0)