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

refactor: Use two instances of the query service for queries and https outcall transform functions #3992

Merged
merged 2 commits into from
Feb 19, 2025

Conversation

dsarlis
Copy link
Member

@dsarlis dsarlis commented Feb 18, 2025

In a previous change, the older AnonymousQueryService was dropped in order to re-use the same QueryService for handling both regular queries and transform functions from https outcalls.

While this change is a step in a good direction as we don't have mostly duplicate code in AnonymousQueryService, it couples regular queries with transform function executions. To provide better quality of service, go back to using two instances of the same service. This way we can get the best of both worlds: code reusability as well as isolation between the two types of queries.

@dsarlis dsarlis requested review from a team as code owners February 18, 2025 08:58
Copy link
Member Author

@dsarlis dsarlis left a comment

Choose a reason for hiding this comment

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

One part where I would appreciate any better ideas is how to handle instantiating the same service twice, specifically because of registering metrics with the same name (if done naively).

For now I took the approach of passing an extra "namespace" argument when creating the service which is used as the prefix of the exported metrics. While it's not too bad, it still feels somewhat hacky. If anyone has a better idea, let me know.

@eichhorl
Copy link
Contributor

One part where I would appreciate any better ideas is how to handle instantiating the same service twice, specifically because of registering metrics with the same name (if done naively).

For now I took the approach of passing an extra "namespace" argument when creating the service which is used as the prefix of the exported metrics. While it's not too bad, it still feels somewhat hacky. If anyone has a better idea, let me know.

I guess one alternative could be to instead switch to a HistogramVec and use the "namespace" as a label. That might make it easier to aggregate over both namespaces if that's of any interest, but I don't have a strong opinion.

@dsarlis
Copy link
Member Author

dsarlis commented Feb 18, 2025

One part where I would appreciate any better ideas is how to handle instantiating the same service twice, specifically because of registering metrics with the same name (if done naively).
For now I took the approach of passing an extra "namespace" argument when creating the service which is used as the prefix of the exported metrics. While it's not too bad, it still feels somewhat hacky. If anyone has a better idea, let me know.

I guess one alternative could be to instead switch to a HistogramVec and use the "namespace" as a label. That might make it easier to aggregate over both namespaces if that's of any interest, but I don't have a strong opinion.

That's an interesting alternative. It does feel kinda wrong though as each service has a single metric, so making it a HistogramVec to support different namespace sounds like it's still abusing things a bit. Also, I doubt there's gonna be a third service at some point, so the aggregation is still relatively easy, we just need to add the two metrics. So, I think I'll stick to the current approach.

@kpop-dfinity
Copy link
Contributor

One part where I would appreciate any better ideas is how to handle instantiating the same service twice, specifically because of registering metrics with the same name (if done naively).
For now I took the approach of passing an extra "namespace" argument when creating the service which is used as the prefix of the exported metrics. While it's not too bad, it still feels somewhat hacky. If anyone has a better idea, let me know.

I guess one alternative could be to instead switch to a HistogramVec and use the "namespace" as a label. That might make it easier to aggregate over both namespaces if that's of any interest, but I don't have a strong opinion.

That's an interesting alternative. It does feel kinda wrong though as each service has a single metric, so making it a HistogramVec to support different namespace sounds like it's still abusing things a bit. Also, I doubt there's gonna be a third service at some point, so the aggregation is still relatively easy, we just need to add the two metrics. So, I think I'll stick to the current approach.

Another alternative would be to use the Histogram::with_opts constructor and provide a list of fixed labels (see https://sourcegraph.com/github.com/dfinity/ic/-/blob/rs/artifact_pool/src/consensus_pool.rs?L137-147 for an example of how we do it in the consensus pool)

@dsarlis
Copy link
Member Author

dsarlis commented Feb 18, 2025

One part where I would appreciate any better ideas is how to handle instantiating the same service twice, specifically because of registering metrics with the same name (if done naively).
For now I took the approach of passing an extra "namespace" argument when creating the service which is used as the prefix of the exported metrics. While it's not too bad, it still feels somewhat hacky. If anyone has a better idea, let me know.

I guess one alternative could be to instead switch to a HistogramVec and use the "namespace" as a label. That might make it easier to aggregate over both namespaces if that's of any interest, but I don't have a strong opinion.

That's an interesting alternative. It does feel kinda wrong though as each service has a single metric, so making it a HistogramVec to support different namespace sounds like it's still abusing things a bit. Also, I doubt there's gonna be a third service at some point, so the aggregation is still relatively easy, we just need to add the two metrics. So, I think I'll stick to the current approach.

Another alternative would be to use the Histogram::with_opts constructor and provide a list of fixed labels (see https://sourcegraph.com/github.com/dfinity/ic/-/blob/rs/artifact_pool/src/consensus_pool.rs?L137-147 for an example of how we do it in the consensus pool)

I'm actually not sure any of these would work after thinking about it some more. As long as the metric name is the same, we're still gonna have an issue I think as the metric name cannot be registered twice with the MetricsRegistry we use. Labels do not matter in that respect.

@dsarlis
Copy link
Member Author

dsarlis commented Feb 18, 2025

One part where I would appreciate any better ideas is how to handle instantiating the same service twice, specifically because of registering metrics with the same name (if done naively).
For now I took the approach of passing an extra "namespace" argument when creating the service which is used as the prefix of the exported metrics. While it's not too bad, it still feels somewhat hacky. If anyone has a better idea, let me know.

I guess one alternative could be to instead switch to a HistogramVec and use the "namespace" as a label. That might make it easier to aggregate over both namespaces if that's of any interest, but I don't have a strong opinion.

That's an interesting alternative. It does feel kinda wrong though as each service has a single metric, so making it a HistogramVec to support different namespace sounds like it's still abusing things a bit. Also, I doubt there's gonna be a third service at some point, so the aggregation is still relatively easy, we just need to add the two metrics. So, I think I'll stick to the current approach.

Another alternative would be to use the Histogram::with_opts constructor and provide a list of fixed labels (see https://sourcegraph.com/github.com/dfinity/ic/-/blob/rs/artifact_pool/src/consensus_pool.rs?L137-147 for an example of how we do it in the consensus pool)

I'm actually not sure any of these would work after thinking about it some more. As long as the metric name is the same, we're still gonna have an issue I think as the metric name cannot be registered twice with the MetricsRegistry we use. Labels do not matter in that respect.

Hmm, seems I was wrong. Trying out @kpop-dfinity's suggestion seems to work. Not entirely sure it's a lot better but I'm also ok with that and it doesn't make a whole lot of difference in the amount of changes needed.

@dsarlis dsarlis added this pull request to the merge queue Feb 19, 2025
Merged via the queue into master with commit 075a364 Feb 19, 2025
30 checks passed
@dsarlis dsarlis deleted the dimitris/separate-https-outcalls-queries branch February 19, 2025 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants