-
Notifications
You must be signed in to change notification settings - Fork 669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MF-703 - Reliably Publish Event Messages to Redis #1836
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1836 +/- ##
==========================================
+ Coverage 67.12% 67.69% +0.56%
==========================================
Files 118 118
Lines 9438 9434 -4
==========================================
+ Hits 6335 6386 +51
+ Misses 2436 2374 -62
- Partials 667 674 +7
... and 1 file with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
e3cc95a
to
6f0b3c2
Compare
internal/clients/redis/producer.go
Outdated
|
||
type eventStore struct { | ||
client *redis.Client | ||
unpublishedEvents []*redis.XAddArgs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can grow unexpectedly large sizes. I think a different approach is required for memory management. Perhaps a channel or some external queue like nats might serve better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, nats is configured as fire and forget unless we move to Jetstream. I have implemented a channel with a max of 1M capacity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before publishing the memory footprint of the container was 17MB after publishing before resuming Redis it was 49MB
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid that reliable publishing needs a little bit more than what we have. The buffer mechanism is not bad in itself, but what it effectively introduce is - the reordering of events. This topic is very advanced and out of the scope of this PR. What we can do is - provide a mechanism to mark these events "dirty" or "out of order" maybe by adding a field such as event_time
that will represent the time event occurred and will be different from the time the event is published on Redis.
7edae13
to
32d0120
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix tests and test locally.
93525f1
to
b84c8d2
Compare
5e400d3
to
b230fe8
Compare
69320c3
to
970da5b
Compare
@dborovcanin please review this one |
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* Reliably Publish Event Messages to Redis Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Make Redis Producer Safe For Concurrent Use Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Combine Redis Publishing Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Add defer statement Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Use Channel Instead of Array Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Adding `occurred_at` Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Fix Check `occurred_at` Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Remove Unused Const Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Check For Non NIL Error on Publishing Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Add More Tests Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Hanndle When Channel Is Full Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Fix Issue After Rebase Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Fix Tests Signed-off-by: rodneyosodo <blackd0t@protonmail.com> --------- Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
* Reliably Publish Event Messages to Redis Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Make Redis Producer Safe For Concurrent Use Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Combine Redis Publishing Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Add defer statement Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Use Channel Instead of Array Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Adding `occurred_at` Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Fix Check `occurred_at` Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Remove Unused Const Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Check For Non NIL Error on Publishing Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Add More Tests Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Hanndle When Channel Is Full Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Fix Issue After Rebase Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Fix Tests Signed-off-by: rodneyosodo <blackd0t@protonmail.com> --------- Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
What does this do?
I have introduced a mechanism for storing unpublished events and implementing retries. We use memory to save unpublished events when the Redis server is unavailable. Then, we periodically attempt to publish the stored events when the Redis server becomes available again.
100ms
timeout so stop retrying to connect to Redis when it is downWhich issue(s) does this PR fix/relate to?
Resolves #703
List any changes that modify/break current functionality
added
100ms
timeout to check if Redis is reachableHave you included tests for your changes?
No
Did you document any new/modified functionality?
No
Notes
Tested by pausing the
es-redis
container and resuming it after doing some operations using thee2e
tool.