-
Notifications
You must be signed in to change notification settings - Fork 0
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: add env to disable metrics operation when it is disabled #96
Conversation
if db == nil { | ||
return nil | ||
} |
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.
nitpick: any reason we don't want to return an explicit error rather than a silent return?
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.
Yeh, this is to avoid refactoring. The implementation we have in not methods-based, but expects that we pass the db. To remove db dependency during initialization we return not fake, but nil db and pass it. As it is expected (and added to the comments), we allow to pass db as nil. In such case we don't need errors.
Another ways to do that:
- switch to interface and add
empty
implementation, that does nothing - return particulr errors, but in this case we need to refactor processing among the codebase
This helps us to keep the current metrics in the code, while we don't have the decision about about how do we want to implement metrics
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.
There is an additional further PR (already created), that we discussed with @pirtleshell and in the task: https://app.shortcut.com/kava-labs/story/14336
This one provide a better refactoring, adding interfaces.
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 recognize the desire to #JustGetItDone® but i am compelled to recommend that we refactor into a MetricsDb
interface rather than pretend like we have a postgres db when we do not.
For this case of not having the database, we'd implement a NoopMetricsClient
. The existing code would be the PostgresMetricsClient
The refactor would probably include moving the partitioning/compaction/pruning routines into the client so that different implementations could set them up differently.
Benefits include:
- big code clean up & improved separation of concerns. all the conditional checks for
db == nil
or!serviceConfig.MetricDatabaseEnabled
can be removed - our future selves don't need to keep in our minds for every code change that the PostgresClient might actually not exist
- it will allow a simple transition to using a new backend to store the metrics. if the interface exists and is used, converting the whole service to prometheus becomes the straightforward task of just writing a new
MetricsDb
implementation.
i'd be ok with this change for now to lock in the db destruction cost-savings, but i'd advocate for continuing to work on this and iteratively refactor the code into a more maintainable state.
ci.docker-compose-no-metrics.yml
Outdated
@@ -0,0 +1,32 @@ | |||
--- |
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.
instead of another docker-compose file to maintain, can we make use of multiple env files or just set the env variable directly? seems like the only difference should be setting METRIC_DATABASE_ENABLED
to false
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.
@pirtleshell I think database container is removed from here, but I guess we can just launch it with:
docker compose up redis, proxy
instead of creating new file
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.
Refactored. As there is some problem with passing env variable into the container passing them as part of .env and no_metric.env files depending on type of tests running. Keep one docker compose for both ci
@@ -208,6 +208,7 @@ func TestE2ETestProxyCreatesRequestMetricForEachRequest(t *testing.T) { | |||
|
|||
// make request to api and track start / end time of the request to | |||
startTime := time.Now() | |||
time.Sleep(1 * time.Second) |
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.
what's the motivation for sleeping in these tests? i'm wondering if there is a way to make the tests more resilient?
if we need a sleep before every call to waitForMetricsInWindow
, let's add it into that method instead of needing to remember to call it every time we define startTime
. (include a comment before that call to sleep to explain why it is necessary)
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.
It was the problem on local test environment. Looks like the waitForMetricsInWindow tried to wait for metrics in particular time range. To make it work on local env, there was a problem with timing as we need some delay between startTime and actual metric write
The idea here was to make an update with least amount of refactoring and intrusion to the code, as we don't know how exactly we are going to support and create metrics (mentioned in the second paragraph of description). Totally agree with what you say, but don't believe it will worse the effort for refactoring, as eventually we potentially will delete that code or significantly will refactor that. I started to refactor it according to the comment while reviewing (to introduce interfaces), if you think it make sense at the moment |
Extracted refactoring into a separate task: https://app.shortcut.com/kava-labs/story/14336 |
Was merged already another PR with necessary improvements + refactoring |
METRIC_DATABASE_ENABLED=false
we can run proxy without database dependency.