fix(shard-distributor): separate watch event processing from the cache refresh#7670
Conversation
service/sharddistributor/store/etcd/executorstore/shardcache/namespaceshardcache_test.go
Outdated
Show resolved
Hide resolved
153ac81 to
1b9b18d
Compare
| e, err := newNamespaceShardToExecutor(testPrefix, testNamespace, mockClient, stopCh, logger, clock.NewRealTimeSource()) | ||
| require.NoError(t, err) | ||
|
|
||
| triggerChan := make(chan struct{}) |
There was a problem hiding this comment.
shouldn't it also be buffered here? Otherwise you won't get anything written unless someone is blocked on reading from it.
service/sharddistributor/store/etcd/executorstore/shardcache/namespaceshardcache_test.go
Outdated
Show resolved
Hide resolved
d2c509c to
530b74a
Compare
| ctrl := gomock.NewController(t) | ||
| defer ctrl.Finish() | ||
|
|
||
| logger := testlogger.New(t) | ||
| mockClient := etcdclient.NewMockClient(ctrl) | ||
| timeSource := clock.NewMockedTimeSource() | ||
| stopCh := make(chan struct{}) | ||
| testPrefix := "/test-prefix" | ||
| testNamespace := "test-namespace" | ||
| executorID := "executor-1" | ||
|
|
||
| watchChan := make(chan clientv3.WatchResponse) | ||
| mockClient.EXPECT(). | ||
| Watch(gomock.Any(), gomock.Any(), gomock.Any()). | ||
| Return(watchChan) |
There was a problem hiding this comment.
nit: I wonder if big portion of this could be extracted
530b74a to
f750dd3
Compare
| select { | ||
| case triggerCh <- struct{}{}: | ||
| default: | ||
| n.logger.Info("Cache is being refreshed, skipping trigger") |
There was a problem hiding this comment.
I suggest we have a metric here instead of a log, so we can monitor how often this happens.
There was a problem hiding this comment.
I think it's a good idea to have this metric; Perhaps, it's aligned with etcd watch metrics, which we wanted to introduce. Right now, etcd/executorstore doesn't have a metric client and metric scope, so it requires additional non-related changes. I think it can be extracted to another PR.
@gazi-yestemirova what do you think? Is it aligned with your task Add metrics for etcd watch events?
Code Review ✅ Approved 3 resolved / 3 findingsClean, well-structured refactoring that correctly decouples watch event processing from cache refresh using a producer-consumer pattern with a buffered channel. The non-blocking send with event coalescing is the right approach for preventing etcd backpressure, and the new tests provide good coverage of both the blocking behavior and end-to-end refresh triggering. ✅ 3 resolved✅ Edge Case:
|
| Auto-apply | Compact |
|
|
Was this helpful? React with 👍 / 👎 | Gitar
What changed?
watchfunction is separated from a call ofrefreshCachefunctionWhy?
How did you test it?
Potential risks
N/A
Release notes
N/A
Documentation Changes
N/A
Reviewer Validation
PR Description Quality (check these before reviewing code):
go testinvocation)