Skip to content

Commit a3b5765

Browse files
authored
Add ddb ring pull time config (#5357)
* Add ddb ring pull time config Signed-off-by: Daniel Deluiggi <[email protected]> * Add changelog Signed-off-by: Daniel Deluiggi <[email protected]> --------- Signed-off-by: Daniel Deluiggi <[email protected]> Signed-off-by: Daniel Blando <[email protected]>
1 parent 8c7bc6a commit a3b5765

File tree

6 files changed

+109
-67
lines changed

6 files changed

+109
-67
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* [ENHANCEMENT] Update Go version to 1.20.4. #5299
2121
* [ENHANCEMENT] Log: Avoid expensive log.Valuer evaluation for disallowed levels. #5297
2222
* [ENHANCEMENT] Improving Performance on the API Gzip Handler. #5347
23+
* [ENHANCEMENT] Dynamodb: Add `puller-sync-time` to allow different pull time for ring. #5357
2324
* [ENHANCEMENT] Emit querier `max_concurrent` as a metric. #5362
2425
* [BUGFIX] Ruler: Validate if rule group can be safely converted back to rule group yaml from protobuf message #5265
2526
* [BUGFIX] Querier: Convert gRPC `ResourceExhausted` status code from store gateway to 422 limit error. #5286

docs/blocks-storage/compactor.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ compactor:
217217
# CLI flag: -compactor.ring.dynamodb.ttl-time
218218
[ttl: <duration> | default = 0s]
219219

220+
# Time to refresh local ring with information on dynamodb.
221+
# CLI flag: -compactor.ring.dynamodb.puller-sync-time
222+
[puller_sync_time: <duration> | default = 1m]
223+
220224
# The consul_config configures the consul client.
221225
# The CLI flags prefix for this block config is: compactor.ring
222226
[consul: <consul_config>]

docs/blocks-storage/store-gateway.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ store_gateway:
225225
# CLI flag: -store-gateway.sharding-ring.dynamodb.ttl-time
226226
[ttl: <duration> | default = 0s]
227227

228+
# Time to refresh local ring with information on dynamodb.
229+
# CLI flag: -store-gateway.sharding-ring.dynamodb.puller-sync-time
230+
[puller_sync_time: <duration> | default = 1m]
231+
228232
# The consul_config configures the consul client.
229233
# The CLI flags prefix for this block config is:
230234
# store-gateway.sharding-ring

docs/configuration/config-file-reference.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ sharding_ring:
313313
# CLI flag: -alertmanager.sharding-ring.dynamodb.ttl-time
314314
[ttl: <duration> | default = 0s]
315315
316+
# Time to refresh local ring with information on dynamodb.
317+
# CLI flag: -alertmanager.sharding-ring.dynamodb.puller-sync-time
318+
[puller_sync_time: <duration> | default = 1m]
319+
316320
# The consul_config configures the consul client.
317321
# The CLI flags prefix for this block config is: alertmanager.sharding-ring
318322
[consul: <consul_config>]
@@ -1878,6 +1882,10 @@ sharding_ring:
18781882
# CLI flag: -compactor.ring.dynamodb.ttl-time
18791883
[ttl: <duration> | default = 0s]
18801884
1885+
# Time to refresh local ring with information on dynamodb.
1886+
# CLI flag: -compactor.ring.dynamodb.puller-sync-time
1887+
[puller_sync_time: <duration> | default = 1m]
1888+
18811889
# The consul_config configures the consul client.
18821890
# The CLI flags prefix for this block config is: compactor.ring
18831891
[consul: <consul_config>]
@@ -2117,6 +2125,10 @@ ha_tracker:
21172125
# CLI flag: -distributor.ha-tracker.dynamodb.ttl-time
21182126
[ttl: <duration> | default = 0s]
21192127
2128+
# Time to refresh local ring with information on dynamodb.
2129+
# CLI flag: -distributor.ha-tracker.dynamodb.puller-sync-time
2130+
[puller_sync_time: <duration> | default = 1m]
2131+
21202132
# The consul_config configures the consul client.
21212133
# The CLI flags prefix for this block config is: distributor.ha-tracker
21222134
[consul: <consul_config>]
@@ -2194,6 +2206,10 @@ ring:
21942206
# CLI flag: -distributor.ring.dynamodb.ttl-time
21952207
[ttl: <duration> | default = 0s]
21962208
2209+
# Time to refresh local ring with information on dynamodb.
2210+
# CLI flag: -distributor.ring.dynamodb.puller-sync-time
2211+
[puller_sync_time: <duration> | default = 1m]
2212+
21972213
# The consul_config configures the consul client.
21982214
# The CLI flags prefix for this block config is: distributor.ring
21992215
[consul: <consul_config>]
@@ -2482,6 +2498,10 @@ lifecycler:
24822498
# CLI flag: -dynamodb.ttl-time
24832499
[ttl: <duration> | default = 0s]
24842500
2501+
# Time to refresh local ring with information on dynamodb.
2502+
# CLI flag: -dynamodb.puller-sync-time
2503+
[puller_sync_time: <duration> | default = 1m]
2504+
24852505
# The consul_config configures the consul client.
24862506
[consul: <consul_config>]
24872507
@@ -3853,6 +3873,10 @@ ring:
38533873
# CLI flag: -ruler.ring.dynamodb.ttl-time
38543874
[ttl: <duration> | default = 0s]
38553875
3876+
# Time to refresh local ring with information on dynamodb.
3877+
# CLI flag: -ruler.ring.dynamodb.puller-sync-time
3878+
[puller_sync_time: <duration> | default = 1m]
3879+
38563880
# The consul_config configures the consul client.
38573881
# The CLI flags prefix for this block config is: ruler.ring
38583882
[consul: <consul_config>]
@@ -4712,6 +4736,10 @@ sharding_ring:
47124736
# CLI flag: -store-gateway.sharding-ring.dynamodb.ttl-time
47134737
[ttl: <duration> | default = 0s]
47144738
4739+
# Time to refresh local ring with information on dynamodb.
4740+
# CLI flag: -store-gateway.sharding-ring.dynamodb.puller-sync-time
4741+
[puller_sync_time: <duration> | default = 1m]
4742+
47154743
# The consul_config configures the consul client.
47164744
# The CLI flags prefix for this block config is: store-gateway.sharding-ring
47174745
[consul: <consul_config>]

pkg/ring/kv/dynamodb/client.go

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@ import (
1717

1818
// Config to create a ConsulClient
1919
type Config struct {
20-
Region string `yaml:"region"`
21-
TableName string `yaml:"table_name"`
22-
TTL time.Duration `yaml:"ttl"`
20+
Region string `yaml:"region"`
21+
TableName string `yaml:"table_name"`
22+
TTL time.Duration `yaml:"ttl"`
23+
PullerSyncTime time.Duration `yaml:"puller_sync_time"`
2324
}
2425

2526
type Client struct {
26-
kv dynamoDbClient
27-
codec codec.Codec
28-
ddbMetrics *dynamodbMetrics
29-
logger log.Logger
27+
kv dynamoDbClient
28+
codec codec.Codec
29+
ddbMetrics *dynamodbMetrics
30+
logger log.Logger
31+
pullerSyncTime time.Duration
32+
backoffConfig backoff.Config
3033

3134
staleDataLock sync.RWMutex
3235
staleData map[string]staleData
@@ -37,22 +40,13 @@ type staleData struct {
3740
timestamp time.Time
3841
}
3942

40-
var (
41-
backoffConfig = backoff.Config{
42-
MinBackoff: 1 * time.Second,
43-
MaxBackoff: 1 * time.Minute,
44-
MaxRetries: 0,
45-
}
46-
47-
defaultLoopDelay = 1 * time.Minute
48-
)
49-
5043
// RegisterFlags adds the flags required to config this to the given FlagSet
5144
// If prefix is not an empty string it should end with a period.
5245
func (cfg *Config) RegisterFlags(f *flag.FlagSet, prefix string) {
5346
f.StringVar(&cfg.Region, prefix+"dynamodb.region", "", "Region to access dynamodb.")
5447
f.StringVar(&cfg.TableName, prefix+"dynamodb.table-name", "", "Table name to use on dynamodb.")
5548
f.DurationVar(&cfg.TTL, prefix+"dynamodb.ttl-time", 0, "Time to expire items on dynamodb.")
49+
f.DurationVar(&cfg.PullerSyncTime, prefix+"dynamodb.puller-sync-time", 60*time.Second, "Time to refresh local ring with information on dynamodb.")
5650
}
5751

5852
func NewClient(cfg Config, cc codec.Codec, logger log.Logger, registerer prometheus.Registerer) (*Client, error) {
@@ -63,12 +57,20 @@ func NewClient(cfg Config, cc codec.Codec, logger log.Logger, registerer prometh
6357

6458
ddbMetrics := newDynamoDbMetrics(registerer)
6559

60+
backoffConfig := backoff.Config{
61+
MinBackoff: 1 * time.Second,
62+
MaxBackoff: cfg.PullerSyncTime,
63+
MaxRetries: 0,
64+
}
65+
6666
c := &Client{
67-
kv: dynamodbInstrumentation{kv: dynamoDB, ddbMetrics: ddbMetrics},
68-
codec: cc,
69-
logger: ddbLog(logger),
70-
ddbMetrics: ddbMetrics,
71-
staleData: make(map[string]staleData),
67+
kv: dynamodbInstrumentation{kv: dynamoDB, ddbMetrics: ddbMetrics},
68+
codec: cc,
69+
logger: ddbLog(logger),
70+
ddbMetrics: ddbMetrics,
71+
pullerSyncTime: cfg.PullerSyncTime,
72+
staleData: make(map[string]staleData),
73+
backoffConfig: backoffConfig,
7274
}
7375
level.Info(c.logger).Log("dynamodb kv initialized")
7476
return c, nil
@@ -121,7 +123,7 @@ func (c *Client) Delete(ctx context.Context, key string) error {
121123
}
122124

123125
func (c *Client) CAS(ctx context.Context, key string, f func(in interface{}) (out interface{}, retry bool, err error)) error {
124-
bo := backoff.New(ctx, backoffConfig)
126+
bo := backoff.New(ctx, c.backoffConfig)
125127
for bo.Ongoing() {
126128
resp, _, err := c.kv.Query(ctx, dynamodbKey{primaryKey: key}, false)
127129
if err != nil {
@@ -190,7 +192,7 @@ func (c *Client) CAS(ctx context.Context, key string, f func(in interface{}) (ou
190192
}
191193

192194
func (c *Client) WatchKey(ctx context.Context, key string, f func(interface{}) bool) {
193-
bo := backoff.New(ctx, backoffConfig)
195+
bo := backoff.New(ctx, c.backoffConfig)
194196

195197
for bo.Ongoing() {
196198
out, _, err := c.kv.Query(ctx, dynamodbKey{
@@ -199,12 +201,11 @@ func (c *Client) WatchKey(ctx context.Context, key string, f func(interface{}) b
199201
if err != nil {
200202
level.Error(c.logger).Log("msg", "error WatchKey", "key", key, "err", err)
201203

202-
if bo.NumRetries() > 10 {
204+
if bo.NumRetries() >= 10 {
203205
if staleData := c.getStaleData(key); staleData != nil {
204206
if !f(staleData) {
205207
return
206208
}
207-
bo.Reset()
208209
}
209210
}
210211
bo.Wait()
@@ -226,13 +227,13 @@ func (c *Client) WatchKey(ctx context.Context, key string, f func(interface{}) b
226227
select {
227228
case <-ctx.Done():
228229
return
229-
case <-time.After(defaultLoopDelay):
230+
case <-time.After(c.pullerSyncTime):
230231
}
231232
}
232233
}
233234

234235
func (c *Client) WatchPrefix(ctx context.Context, prefix string, f func(string, interface{}) bool) {
235-
bo := backoff.New(ctx, backoffConfig)
236+
bo := backoff.New(ctx, c.backoffConfig)
236237

237238
for bo.Ongoing() {
238239
out, _, err := c.kv.Query(ctx, dynamodbKey{
@@ -259,7 +260,7 @@ func (c *Client) WatchPrefix(ctx context.Context, prefix string, f func(string,
259260
select {
260261
case <-ctx.Done():
261262
return
262-
case <-time.After(defaultLoopDelay):
263+
case <-time.After(c.pullerSyncTime):
263264
}
264265
}
265266
}

0 commit comments

Comments
 (0)