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

Update mobc and metrics crates #5015

Merged
merged 10 commits into from
Oct 24, 2024
Merged

Update mobc and metrics crates #5015

merged 10 commits into from
Oct 24, 2024

Conversation

SevInf
Copy link
Contributor

@SevInf SevInf commented Oct 8, 2024

mobc update includes fixes from importcjj/mobc#99
Rest of the PR is update to new api of the metrics crate.

Ref: prisma/team-orm#1317

@SevInf SevInf requested a review from a team as a code owner October 8, 2024 15:48
@SevInf SevInf requested review from aqrln and removed request for a team October 8, 2024 15:48
@SevInf SevInf added this to the 5.21.0 milestone Oct 8, 2024
Copy link

codspeed-hq bot commented Oct 8, 2024

CodSpeed Performance Report

Merging #5015 will not alter performance

Comparing mobc-and-metrics-up (f9c052a) with main (8263a1f)

Summary

✅ 11 untouched benchmarks

Copy link
Contributor

github-actions bot commented Oct 8, 2024

WASM Query Engine file Size

Engine This PR Base branch Diff
Postgres 2.044MiB 2.040MiB 3.587KiB
Postgres (gzip) 821.706KiB 820.411KiB 1.295KiB
Mysql 2.011MiB 2.006MiB 4.784KiB
Mysql (gzip) 808.476KiB 806.506KiB 1.970KiB
Sqlite 1.910MiB 1.904MiB 5.625KiB
Sqlite (gzip) 769.246KiB 766.951KiB 2.295KiB

@SevInf SevInf force-pushed the mobc-and-metrics-up branch 3 times, most recently from 65fdda5 to 3f44866 Compare October 16, 2024 08:58
aqrln added a commit that referenced this pull request Oct 23, 2024
After updating mobc in
#5015, we faced some test
failures due to previous bugs unmasking others. For some reason
filtering the events emitted by the metrics to tracing bridge didn't
quite work as expected, and some of the callsites (like the decrement
method for counters) were disabled the first time they were registered
with the subscriber, unless the interest cache was rebuilt right before
emitting the event, making decrementing the counters not work.

Aside from the fixed mobc issues, this is another reason behind issues
like prisma/prisma#25177.

We tried debugging it with Serhii before he left but we eventually
agreed that it would be better to just get rid of the hack with carrying
the metrics data through traces.

Now, the reason this hack was necessary was because we always had a
global metrics recorder but we somehow needed to isolate the metrics by
the engine instance in the library engine, and have a way to associate
the emitted metrics with the correct engine implicitly based on the
async context. Tracing conveniently has all of that implemented, but
`metrics` crate provides no instrumentation for futures. Luckily, it
does have a way to run a (synchronous) closure overriding the global
recorder for this closure (or without a global recorder at all), and
this is enough of a building block to implement the necessary
instrumentation ourselves, which is exactly what this PR does!

Now we have simpler, more robust and more efficient setup for metrics
that is not coupled with tracing, no global recorder in Node-API engine
and in tests, and we still support a global recorder in the binary
engine just in case (and to avoid some boilerplate the library engine
has to have for both tracing and metrics in request handlers).

Closes: prisma/team-orm#1317
aqrln added a commit that referenced this pull request Oct 23, 2024
After updating mobc in
#5015, we faced some test
failures due to previous bugs unmasking others. For some reason
filtering the events emitted by the metrics to tracing bridge didn't
quite work as expected, and some of the callsites (like the decrement
method for counters) were disabled the first time they were registered
with the subscriber, unless the interest cache was rebuilt right before
emitting the event, making decrementing the counters not work.

Aside from the fixed mobc issues, this is another reason behind issues
like prisma/prisma#25177.

We tried debugging it with Serhii before he left but we eventually
agreed that it would be better to just get rid of the hack with carrying
the metrics data through traces.

Now, the reason this hack was necessary was because we always had a
global metrics recorder but we somehow needed to isolate the metrics by
the engine instance in the library engine, and have a way to associate
the emitted metrics with the correct engine implicitly based on the
async context. Tracing conveniently has all of that implemented, but
`metrics` crate provides no instrumentation for futures. Luckily, it
does have a way to run a (synchronous) closure overriding the global
recorder for this closure (or without a global recorder at all), and
this is enough of a building block to implement the necessary
instrumentation ourselves, which is exactly what this PR does!

Now we have simpler, more robust and more efficient setup for metrics
that is not coupled with tracing, no global recorder in Node-API engine
and in tests, and we still support a global recorder in the binary
engine just in case (and to avoid some boilerplate the library engine
has to have for both tracing and metrics in request handlers).

Closes: prisma/team-orm#1317
@@ -9,4 +9,4 @@ proc-macro = true
[dependencies]
proc-macro2 = "1.0.26"
quote = "1.0.2"
syn = "1.0.5"
syn = { version = "1.0.5", features = ["full"] }
Copy link
Member

@aqrln aqrln Oct 23, 2024

Choose a reason for hiding this comment

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

Story behind this: we use types gated behind the full feature in this crate but we didn't specify this feature here. We also depended on something elsewhere in the workspace which transitively depended on syn with this feature enabled, so we got this feature enabled here via cargo feature unification, but now that the transitive dependency is gone after updating crates, this crate stopped compiling as we started getting exactly what we were asking for in dependencies.

@aqrln
Copy link
Member

aqrln commented Oct 24, 2024

Failing tests are fixed in #5023

@aqrln aqrln removed this from the 5.21.0 milestone Oct 24, 2024
@aqrln aqrln added this to the 5.22.0 milestone Oct 24, 2024
@aqrln aqrln merged commit a87a639 into main Oct 24, 2024
307 of 368 checks passed
@aqrln aqrln deleted the mobc-and-metrics-up branch October 24, 2024 11:11
aqrln added a commit that referenced this pull request Oct 24, 2024
After updating mobc in
#5015, we faced some test
failures due to previous bugs unmasking others. For some reason
filtering the events emitted by the metrics to tracing bridge didn't
quite work as expected, and some of the callsites (like the decrement
method for counters) were disabled the first time they were registered
with the subscriber, unless the interest cache was rebuilt right before
emitting the event, making decrementing the counters not work.

Aside from the fixed mobc issues, this is another reason behind issues
like prisma/prisma#25177.

We tried debugging it with Serhii before he left but we eventually
agreed that it would be better to just get rid of the hack with carrying
the metrics data through traces.

Now, the reason this hack was necessary was because we always had a
global metrics recorder but we somehow needed to isolate the metrics by
the engine instance in the library engine, and have a way to associate
the emitted metrics with the correct engine implicitly based on the
async context. Tracing conveniently has all of that implemented, but
`metrics` crate provides no instrumentation for futures. Luckily, it
does have a way to run a (synchronous) closure overriding the global
recorder for this closure (or without a global recorder at all), and
this is enough of a building block to implement the necessary
instrumentation ourselves, which is exactly what this PR does!

Now we have simpler, more robust and more efficient setup for metrics
that is not coupled with tracing, no global recorder in Node-API engine
and in tests, and we still support a global recorder in the binary
engine just in case (and to avoid some boilerplate the library engine
has to have for both tracing and metrics in request handlers).

Closes: prisma/team-orm#1317
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