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

Introducing Stream Direction to Optimize Metric Collection #224

Merged

Conversation

attilakreiner
Copy link
Contributor

@attilakreiner attilakreiner commented Apr 27, 2023

Description

This change reduces the performance overhead of the metric collection. All the metrics that we currently have operate exclusively either on received or on sent streams. It makes sense to add the stream direction as a property so that the engine should only call the necessary metrics when processing the received vs sent streams. We will soon have metrics that process both streams, so there is an option for that, too:

    enum Direction
    {
        RECEIVED,
        SENT,
        BOTH
    }

This also clears up some code duplication as the current received vs sent metric pairs have identical implementation when the stream direction check is removed, so the common logic is extracted to *Context and *Handler classes.

It depends on PR #223.

if (direction == RECEIVED || direction == BOTH)
{
receivedOriginMetricHandler = receivedOriginMetricHandler.andThen(handler);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like there should be a simpler way to handle this than nested if-else, but it works. 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, unfortunately it looks like this, but I don't exactly see a better way. We could introduce a map, but we have two keys so it should be something like Map<Direction, Map<MetricHandlerKind, MessageConsumer>> so I am not sure it would be actually simpler. 🤔

@attilakreiner attilakreiner changed the title Stream direction Introducing Stream Direction to Optimize Metric Collection Apr 28, 2023
@attilakreiner attilakreiner marked this pull request as ready for review April 28, 2023 13:47
@attilakreiner attilakreiner requested a review from jfallows April 28, 2023 13:47
@jfallows jfallows merged commit 593e1c5 into aklivity:feature/telemetry-metrics May 2, 2023
jfallows added a commit that referenced this pull request May 12, 2023
* Add stream metrics spec and impl projects

* Add http metrics spec and impl projects

* Add metrics modules to incubator docker image

* Metrics schema, extensibility, storage and command line support (#173)

* Create incubator projects for exporter-prometheus.spec and exporter-prometheus

* Engine support to exporters (#202)

* Fix metrics command, find layout files in the engine dir (#204)

* Prometheus Exporter (#203)

* Minimize performance overhead for metric collection (#217)

* Remove zilla load command (#223)

* Introducing Stream Direction to Optimize Metric Collection (#224)

* Add http.active.requests and http.duration metrics (#227)

---------

Co-authored-by: Attila Kreiner <[email protected]>
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.

2 participants