-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* more plugins * clean up * fix tests * fix flakey test
- Loading branch information
Showing
11 changed files
with
264 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,3 +48,4 @@ serde_json = "1" | |
|
||
[target.'cfg(not(target_env = "msvc"))'.dependencies] | ||
jemallocator = "0.5.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//! Log all queries to stdout (or somewhere else, why not). | ||
|
||
use crate::{ | ||
errors::Error, | ||
plugins::{Plugin, PluginOutput}, | ||
query_router::QueryRouter, | ||
}; | ||
use arc_swap::ArcSwap; | ||
use async_trait::async_trait; | ||
use log::info; | ||
use once_cell::sync::Lazy; | ||
use sqlparser::ast::Statement; | ||
use std::sync::Arc; | ||
|
||
static ENABLED: Lazy<ArcSwap<bool>> = Lazy::new(|| ArcSwap::from_pointee(false)); | ||
|
||
pub struct QueryLogger; | ||
|
||
pub fn setup() { | ||
ENABLED.store(Arc::new(true)); | ||
|
||
info!("Logging queries to stdout"); | ||
} | ||
|
||
pub fn disable() { | ||
ENABLED.store(Arc::new(false)); | ||
} | ||
|
||
pub fn enabled() -> bool { | ||
**ENABLED.load() | ||
} | ||
|
||
#[async_trait] | ||
impl Plugin for QueryLogger { | ||
async fn run( | ||
&mut self, | ||
_query_router: &QueryRouter, | ||
ast: &Vec<Statement>, | ||
) -> Result<PluginOutput, Error> { | ||
let query = ast | ||
.iter() | ||
.map(|q| q.to_string()) | ||
.collect::<Vec<String>>() | ||
.join("; "); | ||
info!("{}", query); | ||
|
||
Ok(PluginOutput::Allow) | ||
} | ||
} |
Oops, something went wrong.