-
Notifications
You must be signed in to change notification settings - Fork 229
Added a Plugin
trait
#536
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
Changes from 4 commits
804fd0d
1424388
a1926fa
b9ff2be
dcabbbb
2cb16d2
dee386f
c23a5d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -531,7 +531,7 @@ where | |
error_response( | ||
&mut write, | ||
&format!( | ||
"No pool configured for database: {:?}, user: {:?}", | ||
"No pool configured for database: {:?}, user: {:?} (in startup)", | ||
pool_name, username | ||
), | ||
) | ||
|
@@ -1241,7 +1241,7 @@ where | |
let _ = query_router.infer(&ast); | ||
} | ||
} | ||
debug!("Sending query to server"); | ||
debug!("Sending query to server (in Query mode)"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as below. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reverted this. |
||
|
||
self.send_and_receive_loop( | ||
code, | ||
|
@@ -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)"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reverted this. |
||
|
||
match plugin_output { | ||
Some(PluginOutput::Deny(error)) => { | ||
|
@@ -1499,7 +1499,7 @@ where | |
error_response( | ||
&mut self.write, | ||
&format!( | ||
"No pool configured for database: {}, user: {}", | ||
"No pool configured for database: {}, user: {} (in get_pool)", | ||
self.pool_name, self.username | ||
), | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -763,15 +763,26 @@ pub struct Plugins { | |
pub prewarmer: Option<Prewarmer>, | ||
} | ||
|
||
pub trait Plugin { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Second thought I see why you added it here. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
fn is_enabled(&self) -> bool; | ||
} | ||
|
||
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a valid suggestion. Thanks. Done. |
||
if arg.is_some() { | ||
arg.unwrap().is_enabled() | ||
} else { | ||
false | ||
} | ||
} | ||
write!( | ||
f, | ||
"interceptor: {}, table_access: {}, query_logger: {}, prewarmer: {}", | ||
self.intercept.is_some(), | ||
self.table_access.is_some(), | ||
self.query_logger.is_some(), | ||
self.prewarmer.is_some(), | ||
is_enabled(self.intercept.as_ref()), | ||
is_enabled(self.table_access.as_ref()), | ||
is_enabled(self.query_logger.as_ref()), | ||
is_enabled(self.prewarmer.as_ref()), | ||
) | ||
} | ||
} | ||
|
@@ -782,23 +793,47 @@ pub struct Intercept { | |
pub queries: BTreeMap<String, Query>, | ||
} | ||
|
||
impl Plugin for Intercept { | ||
fn is_enabled(&self) -> bool { | ||
self.enabled | ||
} | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default, Hash, Eq)] | ||
pub struct TableAccess { | ||
pub enabled: bool, | ||
pub tables: Vec<String>, | ||
} | ||
|
||
impl Plugin for TableAccess { | ||
fn is_enabled(&self) -> bool { | ||
self.enabled | ||
} | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default, Hash, Eq)] | ||
pub struct QueryLogger { | ||
pub enabled: bool, | ||
} | ||
|
||
impl Plugin for QueryLogger { | ||
fn is_enabled(&self) -> bool { | ||
self.enabled | ||
} | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default, Hash, Eq)] | ||
pub struct Prewarmer { | ||
pub enabled: bool, | ||
pub queries: Vec<String>, | ||
} | ||
|
||
impl Plugin for Prewarmer { | ||
fn is_enabled(&self) -> bool { | ||
self.enabled | ||
} | ||
} | ||
|
||
impl Intercept { | ||
pub fn substitute(&mut self, db: &str, user: &str) { | ||
for (_, query) in self.queries.iter_mut() { | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Reverted this.