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

[exporter/loadbalacing] Add support for new streamID routing #32690

Closed
wants to merge 3 commits into from

Conversation

RichieSams
Copy link
Contributor

@RichieSams RichieSams commented Apr 25, 2024

Description: This adds a new routing option for metrics: streamID. This routes datapoints based on their streamID. That's the unique hash of all it's attributes, plus the attributes and identifying information of its resource, scope, and metric data

Detailed change list:

  • Created const string values for all the routingKey enums
    • To prevent fat-finger typos in code
  • Refactored metricExporterImp::ConsumeMetrics()
    • Simplified the metrics splitting to be explicit functions, instead of doing generic splitting, and then flagging routing using a dict of bools
      • If we had kept it as-is, I would have needed to further split by datapoint for streamID routing, but the other routingKey methods don't need that. And would just require more work in MergeMetrics()
  • Added a new set of helper functions in internal/exp/metrics: MergeMetrics()
    • This will merge the metrics in mdB into mdA, trying to re-use resourceMetrics, scopeMetrics, and metric values as possible
      • This was a flaw in the previous mergeMetrics()
      • It would only append values, instead of trying to re-use existing resourceMetrics, scopeMetrics, and metric values
      • This meant that all downstream collectors would lose out on potentially lots of data deduplication, since there would be duplicate resourcMetrics, scopeMetrics, and metric instances

NOTE: The old ConsumeMetrics() used its own custom hashing function to create the key for resource routing. The new code uses identity.OfResource() from internal/exp/metrics/identity. The effect is the same, but the key will be different from before. So when a user updates to this code, the routing will be slightly different.

Link to tracking Issue: #32513

Testing:

I added a new suite of tests for the splitting of metrics depending on the routingKey. I utilize golden so all input / output metric data can be declared in yaml, which is much easier to visually parse. Meaning we can have much more complicated / "real-life" data sets.

I updated the benchmarks to also test different numbers of resourceMetrics and scopeMetrics. So we can see how those affect routing times.

Documentation:

I updated the README to describe the new routingKey: metricID, and how it works

Copy link
Contributor

@tiffany76 tiffany76 left a comment

Choose a reason for hiding this comment

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

Just a few quick suggestions from a docs perspective. Thanks!

exporter/loadbalancingexporter/README.md Outdated Show resolved Hide resolved
* `traceID` (default): exports spans based on their `traceID`.
* If not configured, defaults to `traceID` based routing.
* The `routing_key` property is used to specify how to route values (spans or metrics) to exporters based on different parameters. This functionality is currently enabled only for `trace` and `metric` pipeline types. It supports one of the following values:
* `service`: routes values based on their service name. This is useful when using processors like the span metrics, so all spans for each service are sent to consistent collector instances for metric collection. Otherwise, metrics for the same services are sent to different collectors, making aggregations inaccurate.
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the spanmetrics processor has been deprecated, so you may want to choose a different example here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair point. I just kept the README as it was. @jpkrohling do you have any suggestions for a replacement example?

Copy link
Member

Choose a reason for hiding this comment

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

the span metrics connector is the replacement for that, I believe the same requirement around the load balancer exists on a setup with that connector

exporter/loadbalancingexporter/README.md Outdated Show resolved Hide resolved
exporter/loadbalancingexporter/README.md Outdated Show resolved Hide resolved
exporter/loadbalancingexporter/README.md Outdated Show resolved Hide resolved
internal/exp/metrics/streams/streams.go Outdated Show resolved Hide resolved
Copy link
Member

@jpkrohling jpkrohling left a comment

Choose a reason for hiding this comment

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

I started looking into this, but I cannot complete today. I also noticed that there are quite a few things that are not necessarily related to this PR: some look like simple refactorings, some are stylistic changes. Would it be possible to send those changes on a separate PR, perhaps to be merged before this one? It would make reviewing this rather large PR easier.

@RichieSams
Copy link
Contributor Author

Fair point. I'll work on breaking this up into more manageable pieces. Thanks for the input

Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label May 15, 2024
@RichieSams
Copy link
Contributor Author

This PR will be broken up into smaller pieces

@RichieSams RichieSams closed this May 15, 2024
jpkrohling pushed a commit that referenced this pull request May 29, 2024
**Description:**

This will merge the metrics in mdB into mdA, trying to re-use
resourceMetrics, scopeMetrics, and metric values as possible. This will
be used to help implement the new feature for:
#32513


**Link to tracking Issue:**
#32513
/
#32690

**Testing:**

I created a unit test which tests various scenarios of how merge
behavior should happen

**Documentation:**

The exported function is documented using standard golang style. And
there are comments inside the code to explain what is going on and why

---------

Co-authored-by: Ziqi Zhao <zhaoziqi9146@gmail.com>
@RichieSams RichieSams deleted the routing branch July 16, 2024 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants