-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[exporter/loadbalacing] Refactor how metrics are split and then re-joined after load-balacing #33293
[exporter/loadbalacing] Refactor how metrics are split and then re-joined after load-balacing #33293
Conversation
…ined after load-balacing
@RichieSams, is this ready for review? |
It's ready for technical review. I just need to add a changelog and fix up the CI tests |
So we can rely on the compiler to make sure we don't have typos
please fix the conflicts |
Fixed. This PR is ready for final review and merge |
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.
Still have non-resolved failed checks
--- a/exporter/loadbalancingexporter/go.mod
+++ b/exporter/loadbalancingexporter/go.mod
@@ -74,7 +74,6 @@ require (
github.com/imdario/mergo v0.3.6 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
- github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
go.mod/go.sum deps changes detected, please run "make gotidy" and commit the changes in this PR.
Tests are failing on an unrelated issue:
All other tests are green |
yes, this is a known bug |
Woohoo! everything is green again. Are we ok to merge now? |
@jpkrohling Is this ok to merge? |
Thanks! Since we are in the middle of a release, I will put a reminder to merge this right after this release happens (so this would be available on v0.104.0) |
@RichieSams Can you fix the merge conflicts so that I can merge this? Thanks! |
Updated. Thanks! |
@RichieSams, sorry I wasn't able to review this before it got merged. Would you be willing to add benchmarks, assessing that this change is at least on par with the previous version in terms of performance? |
Sure thing. Before this change:
After:
It's significantly faster and uses significantly less memory |
My next change updates the benchmarks to also test different combinations of ResourceMetrics, ScopeMetrics, Metrics, and DataPoints |
Wonderful, thank you! |
Description: The previous code splits an incoming
pmetric.Metrics
into individualpmetric.Metrics
instances, at the granularity ofpmetric.Metric
. Then afterwards, it used the various routingID functions to create a map of booleans, in order to define how the metrics should be routed. Finally, it merged the metrics by routing key, and exported them by concatenating them all together. While this worked, it's somewhat hard to follow, and inefficient for most of the routingIDs. In a future PR, we'd like to add a new routingID, which would require splitting at the datapoint level. This would add a ton of extra work for the other routingIDs, which don't care about specific datapoints.Therefore, the new code has dedicated splitting functions for each routingID. These functions directly return a
map[string]pmetric.Metrics
instance. IE, a map of routing keys to its metrics. These functions can be unit tested directly, and makes the logic inConsumeMetrics()
very easy to follow. Lastly, when combining metrics for routing, the new code utilizes theMergeMetrics()
helper function frominternal/exp/metrics
. This merges the metrics and removes duplicate ResourceMetrics / ScopeMetrics instances. Which saves compute and bandwidth for serialization downstream.Link to tracking Issue: 32513
Testing: I created a full suite of tests for each routingID enum. For both single endpoint, as well an multi-endpoint loadbalancing
Documentation: The code is documented in comments. I added a changelog entry to explain changes for users