Skip to content
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

feat(redis): add redis implementation of KvBufferStore #62

Merged
merged 9 commits into from
Nov 17, 2023

Conversation

dtfiedler
Copy link
Collaborator

This implementation is farily straightforward. We will add a redis container to the docker-compose and set is as the default KvBufferStore for header and transaction cache data once we validate it works as expected.

Copy link

codecov bot commented Nov 8, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (425a434) 56.46% compared to head (c16b23a) 56.56%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop      #62      +/-   ##
===========================================
+ Coverage    56.46%   56.56%   +0.10%     
===========================================
  Files           18       18              
  Lines         5152     5164      +12     
  Branches       244      244              
===========================================
+ Hits          2909     2921      +12     
  Misses        2241     2241              
  Partials         2        2              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

docker-compose.yaml Outdated Show resolved Hide resolved
Comment on lines +58 to +63
depends_on:
- redis
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't use this for other services, so may remove

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, I think we should keep it here. It's more important for redis since the service will maintain a persistent connection to it. Might not hurt to add it for the other services too tbh.

Comment on lines +58 to +63
depends_on:
- redis
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, I think we should keep it here. It's more important for redis since the service will maintain a persistent connection to it. Might not hurt to add it for the other services too tbh.

private client: RedisClientType;
private log: winston.Logger;

constructor({ log, redisUrl }: { log: winston.Logger; redisUrl: string }) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add support for passing in a TTL here. I think we'll both want to bound the size of the cache in Redis and expire values with some reasonable TTL (maybe 8 hours).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

url: redisUrl,
});
this.client.on('error', (err) => {
this.log.error(`Redis error: ${err}`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a Prometheus metric for this too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will add - do you think it's worth adding metrics for cache hits/misses?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added aa0ab6b

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial connection error is good to have, but not exactly what I was intending. I was wanting one in the on('error'... handler. Still fine to keep the connect error counter too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apologies - complete misread on my part. added in 2dcf902

@dtfiedler dtfiedler marked this pull request as ready for review November 15, 2023 16:29
Copy link
Collaborator

@djwhitt djwhitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a couple comments about the metrics and Redis configuration. After those are resolved I think this will be ready to merge.

url: redisUrl,
});
this.client.on('error', (err) => {
this.log.error(`Redis error: ${err}`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial connection error is good to have, but not exactly what I was intending. I was wanting one in the on('error'... handler. Still fine to keep the connect error counter too.

docker-compose.yaml Outdated Show resolved Hide resolved
Copy link
Collaborator

@djwhitt djwhitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Nice work!

dtfiedler added 8 commits November 17, 2023 07:05
This implementation is farily straightforward. We will add a `redis` container to the `docker-compose` and set is as the default `KvBufferStore` for header and transaction cache data once we validate it works as expected.
…ferStore`

Promising through initial testing. Makes the `core` service dependent on `redis` container starting properly and mounts redis data to local volume. We may not want to default the `REDIS_CACHE_URL` but set to localhost for now.
Changing to set the default `KvBufferStore` to redis in the docker-compose and `fs` in the app. We cannot guranatee redis is running if the app is run as standalone, but can ensure `redis` is up and running in the `docker-compose`. Also updates the redis volume to use the proper default `data/` path where `rdb` files get saved. We may want to consider setting the `appendonly` flag when starting `redis`.
We can add an alert on this if redis is unable to connect to the provided url
…2GiB

The actual intent was to track errors on redis, not just connection issues. Added another counter for the errors, and kept the connection counter since it is useful to monitor. Setting the max memory by default to 2GiB in the docker compose to constrain unintended memmory usage in the container, but added an `REDIS_MAX_MEMORY` if they would like to set it to something else.
It was incorrectly set causing the container not to start.
There was an extra character in the default value for
REDIS_CACHE_TTL_SECONDS.
@djwhitt djwhitt merged commit 0fd341b into develop Nov 17, 2023
4 checks passed
@djwhitt djwhitt deleted the PE-4924-redis-kv-store branch November 17, 2023 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants