fix: refactor metrics durable object #1112
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As part of #1091 , this PR handles:
Previous metrics durable object was responsible for tracking the metrics of all the gateways, as well as generic metrics (total sum of winner response times). As a result, this PR creates two new Durable Objects. A GatewayMetrics DO, which will have an instance per gateway and a GenericMetrics DO, which will keep generic metrics agnostic to specific gateways.
An implementation detail worth mentioning is when metrics per gateway are updated. The winner gateway metrics is updated right away (after the winner request finishes), while all the other gateways will be updated in parallel once the remaining requests end. We could store every single request as soon as it finishes, but it would add complexity to the codebase for having the metrics a bit later updated. The extra complexity is likely not worth for having the metrics sooner updated. I am still considering wether adding the winner first is worth it, but given we need to update the generic metrics I added it earlier on.