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

fix(qe): Prevent descriptions from mobc leaking into the presentation of metrics #4239

Merged
merged 7 commits into from
Sep 15, 2023

Conversation

miguelff
Copy link
Contributor

@miguelff miguelff commented Sep 14, 2023

This is the first of set of a series of patches to improve metrics correctness and tech-debt.

I recommend seeing the modified files entirely. The code has been clarified with comments.

In this patch, the fix is to rename the metrics descriptions properly instead of leaking the descriptions coming from mobc.

I took the descriptions from the docs and changed them for clarity. I'd love a review from @ruheni in here. You can find the descriptions of each metric in the updated smoke tests, and if you agree, maybe you can tweak the docs to reflect the new descriptions.

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 14, 2023

CodSpeed Performance Report

Merging #4239 will not alter performance

Comparing miguelff/fix/metrics-2 (73ee455) with main (3ef05ff)

Summary

✅ 11 untouched benchmarks

@miguelff miguelff self-assigned this Sep 14, 2023
@miguelff miguelff marked this pull request as ready for review September 15, 2023 07:58
@miguelff miguelff requested a review from a team as a code owner September 15, 2023 07:58
@Jolg42 Jolg42 added this to the 5.4.0 milestone Sep 15, 2023
@@ -55,22 +55,54 @@ mod smoke_tests {
.text()
.await
.unwrap();

// I would have loved to use insta in here and check the snapshot but the order of the metrics is not guaranteed
Copy link
Contributor

@janpio janpio Sep 15, 2023

Choose a reason for hiding this comment

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

OT: We might want to guarantee the order of metrics in the future maybe then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about it, but given that's not a requirement that is set on the exposed format. I would say that sorting wouldn't add any value for consumers of metrics, and is an additional operation to make at runtime, that would (a priori) only benefit testability.

But also given that the values of the metrics will vary from run to run, (in particular histograms recording times) we would need further processing on the response to match it with a snapshot. To the least, we would need setting numeric values to a placeholder before comparing.

We could have another approach to testing, like unmarshaling into a struct and making assertions on it, but in my opinion, doing so won't add better coverage than what we have now.

let accepted_metric_count = query_engine_metrics::ACCEPT_LIST.len();
let displayed_metric_count = metrics.matches("# TYPE").count();
let non_prisma_metric_count = displayed_metric_count - metrics.matches("# TYPE prisma").count();

Copy link
Contributor

Choose a reason for hiding this comment

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

OT: Maybe another assertion that we have 4 counters, 4 gauges and 3 histograms? Or is that repetitive?

/// Describe all first-party metrics that we record in prisma-engines. Metrics recorded by third-parties
/// --like mobc-- are described by such third parties, but ignored, and replaced by the descriptions in the
/// METRICS_RENAMES map.
fn initialize_metrics_descriptions() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Maybe make more explicit that those are the "first party" metrics descriptions?

Comment on lines +136 to +138
describe_histogram!(
PRISMA_DATASOURCE_QUERIES_DURATION_HISTOGRAM_MS,
"The distribution of the time datasource queries took to run"
Copy link
Contributor

@janpio janpio Sep 15, 2023

Choose a reason for hiding this comment

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

Semi OT: Why are these (this one and also PRISMA_DATASOURCE_QUERIES_TOTAL done by us, and not mobc? Wouldn't it make sense for mobc to take care of everything datasource as well?

Copy link
Contributor

@janpio janpio left a comment

Choose a reason for hiding this comment

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

❤️

@miguelff miguelff merged commit 79f2257 into main Sep 15, 2023
50 of 53 checks passed
@miguelff miguelff deleted the miguelff/fix/metrics-2 branch September 15, 2023 14:24
@Jolg42
Copy link
Contributor

Jolg42 commented Sep 15, 2023

Note: the test in prisma/prisma (obviously) needed to be updated, see prisma/prisma#21096

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.

3 participants