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

Added a Plugin trait #536

Merged
merged 8 commits into from
Oct 3, 2023
Merged

Added a Plugin trait #536

merged 8 commits into from
Oct 3, 2023

Conversation

mdashti
Copy link
Contributor

@mdashti mdashti commented Aug 2, 2023

This PR applies the following improvements:

  • As Address implements the std::fmt::Display trait, we'd better use {} formatter instead of {:?} to make the logs more readable.
  • There were some duplicate error messages, which should be distinguished for easier diagnosis. This is fixed in two instances.
  • The logs should indicate whether a plugin is enabled, instead of showing whether the plugin exists in the configurations. This is fixed.

@levkk
Copy link
Contributor

levkk commented Aug 2, 2023

Looks great! Just going to tag @drdrsh for the address logging change, since I remember him parsing the { .. } debug notation in their log processor to extract some metrics.

@mdashti
Copy link
Contributor Author

mdashti commented Aug 4, 2023

Thanks @levkk. Then, I'll wait on @drdrsh's feedback.

@drdrsh
Copy link
Collaborator

drdrsh commented Aug 4, 2023

@mdashti thank you for the PR. Let me check how the output looks.

@drdrsh
Copy link
Collaborator

drdrsh commented Aug 7, 2023

The change to how Address objects is pretty significant. It will probably break how we parse the logs.

I think for logging we need two modes

  • A JSON mode with a high volume of information per line which is designed for generating metrics and semi-automated analysis.
  • A human-readable mode for humans.

and we can control this using a startup flag. What do you guys think?

@mdashti
Copy link
Contributor Author

mdashti commented Aug 8, 2023

@drdrsh I think it makes sense. I can revert the Address-related changes in this PR for now, how's that?

@mdashti
Copy link
Contributor Author

mdashti commented Aug 11, 2023

@drdrsh Reverted the Address logging changes in b9ff2be.

@mdashti
Copy link
Contributor Author

mdashti commented Sep 22, 2023

Hi, any update on this PR?

mdashti added a commit to crystalcld/pgcat that referenced this pull request Sep 22, 2023
@mdashti mdashti changed the title Logging improvements Added a Plugin trait Sep 22, 2023
@mdashti
Copy link
Contributor Author

mdashti commented Oct 3, 2023

@levkk Is there specific changes needed for this PR? Currently, the "interceptor: {}, table_access: {}, query_logger: {}, prewarmer: {}" log line produces an incorrect result and this PR fixes it.

src/client.rs Outdated
@@ -531,7 +531,7 @@ where
error_response(
&mut write,
&format!(
"No pool configured for database: {:?}, user: {:?}",
"No pool configured for database: {:?}, user: {:?} (in startup)",
Copy link
Contributor

Choose a reason for hiding this comment

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

This is debug level messaging we should not be returning to the client.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Reverted this.

@@ -763,15 +763,26 @@ pub struct Plugins {
pub prewarmer: Option<Prewarmer>,
}

pub trait Plugin {
Copy link
Contributor

@levkk levkk Oct 3, 2023

Choose a reason for hiding this comment

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

Nice to have a trait, but don't think you need it for this particular fix. We should discuss what trait we should have for a Plugin to implement, so we can get on our way to a real plugin system.

Copy link
Contributor

Choose a reason for hiding this comment

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

Second thought I see why you added it here.

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'm also thinking about the plugin system. I should write down my thoughts and share it with you. Please do the same if you have such notes.

src/client.rs Outdated
@@ -1354,7 +1354,7 @@ where
// Sync
// Frontend (client) is asking for the query result now.
'S' => {
debug!("Sending query to server");
debug!("Sending query to server (in Sync mode)");
Copy link
Contributor

Choose a reason for hiding this comment

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

No such thing as "sync" mode, this is the extended protocol. Maybe make the debug line something like:

Sending query to server with extended protocol

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted this.

src/client.rs Outdated
@@ -1241,7 +1241,7 @@ where
let _ = query_router.infer(&ast);
}
}
debug!("Sending query to server");
debug!("Sending query to server (in Query mode)");
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted this.

impl std::fmt::Display for Plugins {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
fn is_enabled<T: Plugin>(arg: Option<&T>) -> bool {
Copy link
Contributor

@levkk levkk Oct 3, 2023

Choose a reason for hiding this comment

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

Cleaner and safer to write it this way:

if let Some(arg) = arg {
    arg.is_enabled()
} else {
    false
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a valid suggestion. Thanks. Done.

Copy link
Contributor

@levkk levkk left a comment

Choose a reason for hiding this comment

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

LGTM. Let me know if it's ready to merge, I'm happy to accept this as-is. Just going to let the CI run first.

Copy link
Contributor Author

@mdashti mdashti left a comment

Choose a reason for hiding this comment

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

@levkk Thanks for the review.

src/client.rs Outdated
@@ -531,7 +531,7 @@ where
error_response(
&mut write,
&format!(
"No pool configured for database: {:?}, user: {:?}",
"No pool configured for database: {:?}, user: {:?} (in startup)",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Reverted this.

src/client.rs Outdated
@@ -1354,7 +1354,7 @@ where
// Sync
// Frontend (client) is asking for the query result now.
'S' => {
debug!("Sending query to server");
debug!("Sending query to server (in Sync mode)");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted this.

impl std::fmt::Display for Plugins {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
fn is_enabled<T: Plugin>(arg: Option<&T>) -> bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a valid suggestion. Thanks. Done.

src/client.rs Outdated
@@ -1241,7 +1241,7 @@ where
let _ = query_router.infer(&ast);
}
}
debug!("Sending query to server");
debug!("Sending query to server (in Query mode)");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted this.

@levkk levkk merged commit 3371c01 into postgresml:main Oct 3, 2023
@mdashti mdashti deleted the improved-log branch October 4, 2023 16:54
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