Skip to content

Commit e319a66

Browse files
authored
Added registered timestamp to instances in the ring (#3248)
* Added registered timestamp to instances in the ring Signed-off-by: Marco Pracucci <[email protected]> * Added CHANGELOG entry Signed-off-by: Marco Pracucci <[email protected]> * Addressed review comments Signed-off-by: Marco Pracucci <[email protected]> * Updated comment Signed-off-by: Marco Pracucci <[email protected]>
1 parent 148da15 commit e319a66

19 files changed

+500
-247
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
* [ENHANCEMENT] Blocksconvert – Scanner: support for scanning specific date-range only. #3222
6060
* [ENHANCEMENT] Blocksconvert – Scanner: metrics for tracking progress. #3222
6161
* [ENHANCEMENT] Blocksconvert – Builder: retry block upload before giving up. #3245
62+
* [ENHANCEMENT] Hash ring: added instance registered timestamp to the ring. #3248
6263
* [BUGFIX] No-longer-needed ingester operations for queries triggered by queriers and rulers are now canceled. #3178
6364
* [BUGFIX] Ruler: directories in the configured `rules-path` will be removed on startup and shutdown in order to ensure they don't persist between runs. #3195
6465
* [BUGFIX] Handle hash-collisions in the query path. #3192

pkg/distributor/distributor_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -962,11 +962,12 @@ func prepare(t *testing.T, cfg prepConfig) ([]*Distributor, []mockIngester, *rin
962962
for i := range ingesters {
963963
addr := fmt.Sprintf("%d", i)
964964
ingesterDescs[addr] = ring.IngesterDesc{
965-
Addr: addr,
966-
Zone: "",
967-
State: ring.ACTIVE,
968-
Timestamp: time.Now().Unix(),
969-
Tokens: []uint32{uint32((math.MaxUint32 / cfg.numIngesters) * i)},
965+
Addr: addr,
966+
Zone: "",
967+
State: ring.ACTIVE,
968+
Timestamp: time.Now().Unix(),
969+
RegisteredTimestamp: time.Now().Unix(),
970+
Tokens: []uint32{uint32((math.MaxUint32 / cfg.numIngesters) * i)},
970971
}
971972
ingestersByAddr[addr] = &ingesters[i]
972973
}

pkg/querier/blocks_store_replicated_set_test.go

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func TestBlocksStoreReplicationSet_GetClientsFor(t *testing.T) {
3838
block4Hash := cortex_tsdb.HashBlockID(block4)
3939

4040
userID := "user-A"
41+
registeredAt := time.Now()
4142

4243
tests := map[string]struct {
4344
shardingStrategy string
@@ -56,7 +57,7 @@ func TestBlocksStoreReplicationSet_GetClientsFor(t *testing.T) {
5657
shardingStrategy: storegateway.ShardingStrategyDefault,
5758
replicationFactor: 1,
5859
setup: func(d *ring.Desc) {
59-
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE)
60+
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE, registeredAt)
6061
},
6162
queryBlocks: []ulid.ULID{block1, block2},
6263
expectedClients: map[string][]ulid.ULID{
@@ -67,7 +68,7 @@ func TestBlocksStoreReplicationSet_GetClientsFor(t *testing.T) {
6768
shardingStrategy: storegateway.ShardingStrategyDefault,
6869
replicationFactor: 1,
6970
setup: func(d *ring.Desc) {
70-
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE)
71+
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE, registeredAt)
7172
},
7273
queryBlocks: []ulid.ULID{block1, block2},
7374
exclude: map[ulid.ULID][]string{
@@ -79,7 +80,7 @@ func TestBlocksStoreReplicationSet_GetClientsFor(t *testing.T) {
7980
shardingStrategy: storegateway.ShardingStrategyDefault,
8081
replicationFactor: 1,
8182
setup: func(d *ring.Desc) {
82-
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE)
83+
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE, registeredAt)
8384
},
8485
queryBlocks: []ulid.ULID{block1, block2},
8586
exclude: map[ulid.ULID][]string{
@@ -93,7 +94,7 @@ func TestBlocksStoreReplicationSet_GetClientsFor(t *testing.T) {
9394
shardingStrategy: storegateway.ShardingStrategyDefault,
9495
replicationFactor: 2,
9596
setup: func(d *ring.Desc) {
96-
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE)
97+
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE, registeredAt)
9798
},
9899
queryBlocks: []ulid.ULID{block1, block2},
99100
expectedClients: map[string][]ulid.ULID{
@@ -104,10 +105,10 @@ func TestBlocksStoreReplicationSet_GetClientsFor(t *testing.T) {
104105
shardingStrategy: storegateway.ShardingStrategyDefault,
105106
replicationFactor: 1,
106107
setup: func(d *ring.Desc) {
107-
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE)
108-
d.AddIngester("instance-2", "127.0.0.2", "", []uint32{block2Hash + 1}, ring.ACTIVE)
109-
d.AddIngester("instance-3", "127.0.0.3", "", []uint32{block3Hash + 1}, ring.ACTIVE)
110-
d.AddIngester("instance-4", "127.0.0.4", "", []uint32{block4Hash + 1}, ring.ACTIVE)
108+
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE, registeredAt)
109+
d.AddIngester("instance-2", "127.0.0.2", "", []uint32{block2Hash + 1}, ring.ACTIVE, registeredAt)
110+
d.AddIngester("instance-3", "127.0.0.3", "", []uint32{block3Hash + 1}, ring.ACTIVE, registeredAt)
111+
d.AddIngester("instance-4", "127.0.0.4", "", []uint32{block4Hash + 1}, ring.ACTIVE, registeredAt)
111112
},
112113
queryBlocks: []ulid.ULID{block1, block3, block4},
113114
expectedClients: map[string][]ulid.ULID{
@@ -120,10 +121,10 @@ func TestBlocksStoreReplicationSet_GetClientsFor(t *testing.T) {
120121
shardingStrategy: storegateway.ShardingStrategyDefault,
121122
replicationFactor: 1,
122123
setup: func(d *ring.Desc) {
123-
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE)
124-
d.AddIngester("instance-2", "127.0.0.2", "", []uint32{block2Hash + 1}, ring.ACTIVE)
125-
d.AddIngester("instance-3", "127.0.0.3", "", []uint32{block3Hash + 1}, ring.ACTIVE)
126-
d.AddIngester("instance-4", "127.0.0.4", "", []uint32{block4Hash + 1}, ring.ACTIVE)
124+
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE, registeredAt)
125+
d.AddIngester("instance-2", "127.0.0.2", "", []uint32{block2Hash + 1}, ring.ACTIVE, registeredAt)
126+
d.AddIngester("instance-3", "127.0.0.3", "", []uint32{block3Hash + 1}, ring.ACTIVE, registeredAt)
127+
d.AddIngester("instance-4", "127.0.0.4", "", []uint32{block4Hash + 1}, ring.ACTIVE, registeredAt)
127128
},
128129
queryBlocks: []ulid.ULID{block1, block3, block4},
129130
exclude: map[ulid.ULID][]string{
@@ -135,10 +136,10 @@ func TestBlocksStoreReplicationSet_GetClientsFor(t *testing.T) {
135136
shardingStrategy: storegateway.ShardingStrategyDefault,
136137
replicationFactor: 2,
137138
setup: func(d *ring.Desc) {
138-
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE)
139-
d.AddIngester("instance-2", "127.0.0.2", "", []uint32{block2Hash + 1}, ring.ACTIVE)
140-
d.AddIngester("instance-3", "127.0.0.3", "", []uint32{block3Hash + 1}, ring.ACTIVE)
141-
d.AddIngester("instance-4", "127.0.0.4", "", []uint32{block4Hash + 1}, ring.ACTIVE)
139+
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE, registeredAt)
140+
d.AddIngester("instance-2", "127.0.0.2", "", []uint32{block2Hash + 1}, ring.ACTIVE, registeredAt)
141+
d.AddIngester("instance-3", "127.0.0.3", "", []uint32{block3Hash + 1}, ring.ACTIVE, registeredAt)
142+
d.AddIngester("instance-4", "127.0.0.4", "", []uint32{block4Hash + 1}, ring.ACTIVE, registeredAt)
142143
},
143144
queryBlocks: []ulid.ULID{block1, block3, block4},
144145
expectedClients: map[string][]ulid.ULID{
@@ -151,8 +152,8 @@ func TestBlocksStoreReplicationSet_GetClientsFor(t *testing.T) {
151152
shardingStrategy: storegateway.ShardingStrategyDefault,
152153
replicationFactor: 2,
153154
setup: func(d *ring.Desc) {
154-
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE)
155-
d.AddIngester("instance-2", "127.0.0.2", "", []uint32{block3Hash + 1}, ring.ACTIVE)
155+
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE, registeredAt)
156+
d.AddIngester("instance-2", "127.0.0.2", "", []uint32{block3Hash + 1}, ring.ACTIVE, registeredAt)
156157
},
157158
queryBlocks: []ulid.ULID{block1, block2, block3, block4},
158159
expectedClients: map[string][]ulid.ULID{
@@ -164,10 +165,10 @@ func TestBlocksStoreReplicationSet_GetClientsFor(t *testing.T) {
164165
shardingStrategy: storegateway.ShardingStrategyDefault,
165166
replicationFactor: 2,
166167
setup: func(d *ring.Desc) {
167-
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE)
168-
d.AddIngester("instance-2", "127.0.0.2", "", []uint32{block2Hash + 1}, ring.ACTIVE)
169-
d.AddIngester("instance-3", "127.0.0.3", "", []uint32{block3Hash + 1}, ring.ACTIVE)
170-
d.AddIngester("instance-4", "127.0.0.4", "", []uint32{block4Hash + 1}, ring.ACTIVE)
168+
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE, registeredAt)
169+
d.AddIngester("instance-2", "127.0.0.2", "", []uint32{block2Hash + 1}, ring.ACTIVE, registeredAt)
170+
d.AddIngester("instance-3", "127.0.0.3", "", []uint32{block3Hash + 1}, ring.ACTIVE, registeredAt)
171+
d.AddIngester("instance-4", "127.0.0.4", "", []uint32{block4Hash + 1}, ring.ACTIVE, registeredAt)
171172
},
172173
queryBlocks: []ulid.ULID{block1, block3, block4},
173174
exclude: map[ulid.ULID][]string{
@@ -187,7 +188,7 @@ func TestBlocksStoreReplicationSet_GetClientsFor(t *testing.T) {
187188
tenantShardSize: 1,
188189
replicationFactor: 1,
189190
setup: func(d *ring.Desc) {
190-
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE)
191+
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE, registeredAt)
191192
},
192193
queryBlocks: []ulid.ULID{block1, block2},
193194
expectedClients: map[string][]ulid.ULID{
@@ -199,7 +200,7 @@ func TestBlocksStoreReplicationSet_GetClientsFor(t *testing.T) {
199200
tenantShardSize: 1,
200201
replicationFactor: 1,
201202
setup: func(d *ring.Desc) {
202-
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE)
203+
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE, registeredAt)
203204
},
204205
queryBlocks: []ulid.ULID{block1, block2},
205206
exclude: map[ulid.ULID][]string{
@@ -212,7 +213,7 @@ func TestBlocksStoreReplicationSet_GetClientsFor(t *testing.T) {
212213
tenantShardSize: 2,
213214
replicationFactor: 2,
214215
setup: func(d *ring.Desc) {
215-
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE)
216+
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE, registeredAt)
216217
},
217218
queryBlocks: []ulid.ULID{block1, block2},
218219
expectedClients: map[string][]ulid.ULID{
@@ -224,10 +225,10 @@ func TestBlocksStoreReplicationSet_GetClientsFor(t *testing.T) {
224225
tenantShardSize: 1,
225226
replicationFactor: 1,
226227
setup: func(d *ring.Desc) {
227-
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE)
228-
d.AddIngester("instance-2", "127.0.0.2", "", []uint32{block2Hash + 1}, ring.ACTIVE)
229-
d.AddIngester("instance-3", "127.0.0.3", "", []uint32{block3Hash + 1}, ring.ACTIVE)
230-
d.AddIngester("instance-4", "127.0.0.4", "", []uint32{block4Hash + 1}, ring.ACTIVE)
228+
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE, registeredAt)
229+
d.AddIngester("instance-2", "127.0.0.2", "", []uint32{block2Hash + 1}, ring.ACTIVE, registeredAt)
230+
d.AddIngester("instance-3", "127.0.0.3", "", []uint32{block3Hash + 1}, ring.ACTIVE, registeredAt)
231+
d.AddIngester("instance-4", "127.0.0.4", "", []uint32{block4Hash + 1}, ring.ACTIVE, registeredAt)
231232
},
232233
queryBlocks: []ulid.ULID{block1, block2, block4},
233234
expectedClients: map[string][]ulid.ULID{
@@ -239,10 +240,10 @@ func TestBlocksStoreReplicationSet_GetClientsFor(t *testing.T) {
239240
tenantShardSize: 2,
240241
replicationFactor: 1,
241242
setup: func(d *ring.Desc) {
242-
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE)
243-
d.AddIngester("instance-2", "127.0.0.2", "", []uint32{block2Hash + 1}, ring.ACTIVE)
244-
d.AddIngester("instance-3", "127.0.0.3", "", []uint32{block3Hash + 1}, ring.ACTIVE)
245-
d.AddIngester("instance-4", "127.0.0.4", "", []uint32{block4Hash + 1}, ring.ACTIVE)
243+
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE, registeredAt)
244+
d.AddIngester("instance-2", "127.0.0.2", "", []uint32{block2Hash + 1}, ring.ACTIVE, registeredAt)
245+
d.AddIngester("instance-3", "127.0.0.3", "", []uint32{block3Hash + 1}, ring.ACTIVE, registeredAt)
246+
d.AddIngester("instance-4", "127.0.0.4", "", []uint32{block4Hash + 1}, ring.ACTIVE, registeredAt)
246247
},
247248
queryBlocks: []ulid.ULID{block1, block2, block4},
248249
expectedClients: map[string][]ulid.ULID{
@@ -255,10 +256,10 @@ func TestBlocksStoreReplicationSet_GetClientsFor(t *testing.T) {
255256
tenantShardSize: 4,
256257
replicationFactor: 1,
257258
setup: func(d *ring.Desc) {
258-
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE)
259-
d.AddIngester("instance-2", "127.0.0.2", "", []uint32{block2Hash + 1}, ring.ACTIVE)
260-
d.AddIngester("instance-3", "127.0.0.3", "", []uint32{block3Hash + 1}, ring.ACTIVE)
261-
d.AddIngester("instance-4", "127.0.0.4", "", []uint32{block4Hash + 1}, ring.ACTIVE)
259+
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE, registeredAt)
260+
d.AddIngester("instance-2", "127.0.0.2", "", []uint32{block2Hash + 1}, ring.ACTIVE, registeredAt)
261+
d.AddIngester("instance-3", "127.0.0.3", "", []uint32{block3Hash + 1}, ring.ACTIVE, registeredAt)
262+
d.AddIngester("instance-4", "127.0.0.4", "", []uint32{block4Hash + 1}, ring.ACTIVE, registeredAt)
262263
},
263264
queryBlocks: []ulid.ULID{block1, block2, block4},
264265
expectedClients: map[string][]ulid.ULID{
@@ -272,10 +273,10 @@ func TestBlocksStoreReplicationSet_GetClientsFor(t *testing.T) {
272273
tenantShardSize: 2,
273274
replicationFactor: 2,
274275
setup: func(d *ring.Desc) {
275-
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE)
276-
d.AddIngester("instance-2", "127.0.0.2", "", []uint32{block2Hash + 1}, ring.ACTIVE)
277-
d.AddIngester("instance-3", "127.0.0.3", "", []uint32{block3Hash + 1}, ring.ACTIVE)
278-
d.AddIngester("instance-4", "127.0.0.4", "", []uint32{block4Hash + 1}, ring.ACTIVE)
276+
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE, registeredAt)
277+
d.AddIngester("instance-2", "127.0.0.2", "", []uint32{block2Hash + 1}, ring.ACTIVE, registeredAt)
278+
d.AddIngester("instance-3", "127.0.0.3", "", []uint32{block3Hash + 1}, ring.ACTIVE, registeredAt)
279+
d.AddIngester("instance-4", "127.0.0.4", "", []uint32{block4Hash + 1}, ring.ACTIVE, registeredAt)
279280
},
280281
queryBlocks: []ulid.ULID{block1, block2},
281282
exclude: map[ulid.ULID][]string{
@@ -291,10 +292,10 @@ func TestBlocksStoreReplicationSet_GetClientsFor(t *testing.T) {
291292
tenantShardSize: 2,
292293
replicationFactor: 2,
293294
setup: func(d *ring.Desc) {
294-
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE)
295-
d.AddIngester("instance-2", "127.0.0.2", "", []uint32{block2Hash + 1}, ring.ACTIVE)
296-
d.AddIngester("instance-3", "127.0.0.3", "", []uint32{block3Hash + 1}, ring.ACTIVE)
297-
d.AddIngester("instance-4", "127.0.0.4", "", []uint32{block4Hash + 1}, ring.ACTIVE)
295+
d.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1}, ring.ACTIVE, registeredAt)
296+
d.AddIngester("instance-2", "127.0.0.2", "", []uint32{block2Hash + 1}, ring.ACTIVE, registeredAt)
297+
d.AddIngester("instance-3", "127.0.0.3", "", []uint32{block3Hash + 1}, ring.ACTIVE, registeredAt)
298+
d.AddIngester("instance-4", "127.0.0.4", "", []uint32{block4Hash + 1}, ring.ACTIVE, registeredAt)
298299
},
299300
queryBlocks: []ulid.ULID{block1, block2},
300301
exclude: map[ulid.ULID][]string{

pkg/ring/basic_lifecycler.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ func (l *BasicLifecycler) GetTokens() Tokens {
133133
return l.currInstanceDesc.GetTokens()
134134
}
135135

136+
// GetRegisteredAt returns the timestamp when the instance has been registered to the ring
137+
// or a zero value if the lifecycler hasn't been started yet or was already registered and its
138+
// timestamp is unknown.
139+
func (l *BasicLifecycler) GetRegisteredAt() time.Time {
140+
l.currState.RLock()
141+
defer l.currState.RUnlock()
142+
143+
return l.currInstanceDesc.GetRegisteredAt()
144+
}
145+
136146
// IsRegistered returns whether the instance is currently registered within the ring.
137147
func (l *BasicLifecycler) IsRegistered() bool {
138148
l.currState.RLock()
@@ -237,7 +247,7 @@ func (l *BasicLifecycler) registerInstance(ctx context.Context) error {
237247
var exists bool
238248
instanceDesc, exists = ringDesc.Ingesters[l.cfg.ID]
239249
if exists {
240-
level.Info(l.logger).Log("msg", "instance found in the ring", "instance", l.cfg.ID, "ring", l.ringName, "state", instanceDesc.GetState(), "tokens", len(instanceDesc.GetTokens()))
250+
level.Info(l.logger).Log("msg", "instance found in the ring", "instance", l.cfg.ID, "ring", l.ringName, "state", instanceDesc.GetState(), "tokens", len(instanceDesc.GetTokens()), "registered_at", instanceDesc.GetRegisteredAt().String())
241251
} else {
242252
level.Info(l.logger).Log("msg", "instance not found in the ring", "instance", l.cfg.ID, "ring", l.ringName)
243253
}
@@ -248,15 +258,25 @@ func (l *BasicLifecycler) registerInstance(ctx context.Context) error {
248258
// Ensure tokens are sorted.
249259
sort.Sort(tokens)
250260

261+
// If the instance didn't already exist, then we can safely set the registered timestamp to "now",
262+
// otherwise we have to honor the previous value (even if it was zero, because means it was unknown
263+
// but it's definitely not "now").
264+
var registeredAt time.Time
265+
if exists {
266+
registeredAt = instanceDesc.GetRegisteredAt()
267+
} else {
268+
registeredAt = time.Now()
269+
}
270+
251271
if !exists {
252-
instanceDesc = ringDesc.AddIngester(l.cfg.ID, l.cfg.Addr, l.cfg.Zone, tokens, state)
272+
instanceDesc = ringDesc.AddIngester(l.cfg.ID, l.cfg.Addr, l.cfg.Zone, tokens, state, registeredAt)
253273
return ringDesc, true, nil
254274
}
255275

256276
// Always overwrite the instance in the ring (even if already exists) because some properties
257277
// may have changed (stated, tokens, zone, address) and even if they didn't the heartbeat at
258278
// least did.
259-
instanceDesc = ringDesc.AddIngester(l.cfg.ID, l.cfg.Addr, l.cfg.Zone, tokens, state)
279+
instanceDesc = ringDesc.AddIngester(l.cfg.ID, l.cfg.Addr, l.cfg.Zone, tokens, state, registeredAt)
260280
return ringDesc, true, nil
261281
})
262282

@@ -378,7 +398,7 @@ func (l *BasicLifecycler) updateInstance(ctx context.Context, update func(*Desc,
378398
// or the instance has been forgotten. In this case, we do re-insert it.
379399
if !ok {
380400
level.Warn(l.logger).Log("msg", "instance missing in the ring, adding it back", "ring", l.ringName)
381-
instanceDesc = ringDesc.AddIngester(l.cfg.ID, l.cfg.Addr, l.cfg.Zone, l.GetTokens(), l.GetState())
401+
instanceDesc = ringDesc.AddIngester(l.cfg.ID, l.cfg.Addr, l.cfg.Zone, l.GetTokens(), l.GetState(), l.GetRegisteredAt())
382402
}
383403

384404
prevTimestamp := instanceDesc.Timestamp

pkg/ring/basic_lifecycler_delegates.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,12 @@ func (d *TokensPersistencyDelegate) OnRingInstanceRegister(lifecycler *BasicLife
7979
// case the instance exist in the ring (which is OK because the lifecycler
8080
// will correctly reconcile this case too).
8181
return d.next.OnRingInstanceRegister(lifecycler, ringDesc, true, lifecycler.GetInstanceID(), IngesterDesc{
82-
Addr: lifecycler.GetInstanceAddr(),
83-
Timestamp: time.Now().Unix(),
84-
State: d.loadState,
85-
Tokens: tokensFromFile,
86-
Zone: lifecycler.GetInstanceZone(),
82+
Addr: lifecycler.GetInstanceAddr(),
83+
Timestamp: time.Now().Unix(),
84+
RegisteredTimestamp: lifecycler.GetRegisteredAt().Unix(),
85+
State: d.loadState,
86+
Tokens: tokensFromFile,
87+
Zone: lifecycler.GetInstanceZone(),
8788
})
8889
}
8990

0 commit comments

Comments
 (0)