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

chore: (qe) Preparatory refactoring to introduce log capturing. #3617

Merged
merged 5 commits into from
Jan 24, 2023

Conversation

miguelff
Copy link
Contributor

@miguelff miguelff commented Jan 20, 2023

Tracked in https://github.com/prisma/client-planning/issues/158
Extracted from #3505 and rebased.
To be released before #3618

This PR does a preparatory refactoring for the log capturing feature that can be reviewed and be released independently

@miguelff miguelff added this to the 4.10.0 milestone Jan 20, 2023
@miguelff miguelff self-assigned this Jan 20, 2023
@miguelff miguelff force-pushed the integration/log-capture-prep-refactoring branch 2 times, most recently from fffa84e to 6970951 Compare January 22, 2023 21:36
@miguelff miguelff marked this pull request as ready for review January 23, 2023 13:11
@miguelff miguelff requested a review from a team January 23, 2023 13:11
Copy link
Contributor

@Weakky Weakky left a comment

Choose a reason for hiding this comment

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

Great refactoring 💯. I left a few comments, I don't think any are blocking. Feel free to apply whichever makes the most sense to you.

query-engine/query-engine/src/state.rs Outdated Show resolved Hide resolved
query-engine/core/src/executor/interpreting_executor.rs Outdated Show resolved Hide resolved
query-engine/core/src/executor/mod.rs Outdated Show resolved Hide resolved
Comment on lines -124 to 51
if req.method() == Method::POST && req.uri().path().contains("transaction") {
return handle_transaction(state, req).await;
if req.method() == Method::POST && req.uri().path().starts_with("/transaction") {
return transaction_handler(state, req).await;
}

if [Method::POST, Method::GET].contains(req.method())
&& req.uri().path().contains("metrics")
&& req.uri().path().starts_with("/metrics")
&& state.enable_metrics
{
return handle_metrics(state, req).await;
return metrics_handler(state, req).await;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I hope all consumers properly shaped their URLs 😬

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, me too!

query-engine/query-engine/src/logger.rs Outdated Show resolved Hide resolved
Comment on lines -25 to -32
impl PrismaResponse {
pub fn errors(&self) -> Vec<&GQLError> {
match self {
PrismaResponse::Single(ref s) => s.errors().collect(),
PrismaResponse::Multi(ref m) => m.errors().collect(),
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose this was dead code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, there isn't any dynamic call to a particular prisma response

query-engine/query-engine/src/server/mod.rs Outdated Show resolved Hide resolved
}

meta.target() == "quaint::connector::metrics" && meta.name() == "quaint:query"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I see a lot of pub fn items in this file and elsewhere, and that is wholesale reexported as public API to consumers of the crate. Does this all need to be public? It make the API of a crate smaller and easier to understand if internal items are pub(crate) instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I didn't restrict visibility of any of those, and just moved it. I will check and restrict when possible.

Copy link
Contributor

@tomhoule tomhoule left a comment

Choose a reason for hiding this comment

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

Mostly superficial comments on details rather than the big picture. I am still lacking a lot of context to feel onboarded on tracing in the QE, and I have to learn opentelemetry (it's a lot more than a small layer on top of tracing).


impl State {
/// Create a new instance of `State`.
fn new(cx: PrismaContext, enable_playground: bool, enable_debug_mode: bool, enable_metrics: bool) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to change this now, but boolean params are very poor in information when you read callers and really easy to get wrong (which boolean goes at which position). In my experience bitflags with enumflags are a lot easier to read when you construct them (all values are named), on top of being more compact in memory (here it would be 1 byte instead of 3). They're also more code and from a library, so, tradeoffs.

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 totally agree, grabed the whole State object from a previous patch in progress, will try to address in here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not blocking, like the rest of my feedback here, so do what you feel most comfortable with. No need to learn a whole (small) library for this if you haven't used enumflags2 before.

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 like the approach of using enum2flags for modeling a compacted set of flags. FWIW, these do already exist as boolean flags coming from the CLI. so we would have to make a transformation. Nevertheless, I don't want to add yet another boolean to this struct in case we have more flags, so I'm ok with exploring this option. Thanks for the suggestion.

I will do it, though, in a different PR after I merge both this and #3618 to prevent more conflicts, as the #3618 has changes using the state.

query-engine/query-engine/src/state.rs Outdated Show resolved Hide resolved
query-engine/query-engine/src/server/mod.rs Outdated Show resolved Hide resolved
query-engine/core/src/telemetry/helpers.rs Outdated Show resolved Hide resolved
query-engine/core/src/executor/mod.rs Outdated Show resolved Hide resolved
query-engine/query-engine/src/logger.rs Show resolved Hide resolved
query-engine/query-engine/src/logger.rs Outdated Show resolved Hide resolved
query-engine/query-engine/src/logger.rs Show resolved Hide resolved
query-engine/query-engine/src/state.rs Outdated Show resolved Hide resolved
@tomhoule
Copy link
Contributor

(none of my feedback is blocking)

@miguelff
Copy link
Contributor Author

Thank you both @Weakky and @tomhoule for the sensible feedback, it also gives me a lot of good information that I didn't know about and that would help improve the patch, which is the best outcome possible for a review. Thank you so much! 🤗

Will follow up with a new commit addressing the feedback and merge if all good.

@miguelff miguelff force-pushed the integration/log-capture-prep-refactoring branch from ca0e1b0 to d4977fb Compare January 24, 2023 11:07
@miguelff miguelff force-pushed the integration/log-capture-prep-refactoring branch from d4977fb to dbd7ac1 Compare January 24, 2023 12:02
@miguelff miguelff merged commit 887cf26 into main Jan 24, 2023
@miguelff miguelff deleted the integration/log-capture-prep-refactoring branch January 24, 2023 14:22
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