-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This implements the WAL plugin test API. It also introduces a new API for the Python plugins to be called, get their data, and call back into the database server. There are some things that I'll want to address in follow on work: * CLI tests, but will wait on #25737 to land for a refactor of the CLI here * Would be better to hook the Python logging to call back into the plugin return state like here: https://pyo3.rs/v0.23.3/ecosystem/logging.html#the-python-to-rust-direction * We should only load the LineBuilder interface once in a module, rather than on every execution of a WAL plugin * More tests all around But I want to get this in so that the actual plugin and trigger system can get udated to build around this model.
- Loading branch information
Showing
18 changed files
with
913 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,21 @@ | ||
use std::error::Error; | ||
|
||
pub mod wal; | ||
|
||
#[derive(Debug, clap::Parser)] | ||
pub(crate) struct Config { | ||
#[clap(subcommand)] | ||
command: Command, | ||
} | ||
|
||
#[derive(Debug, clap::Parser)] | ||
enum Command { | ||
/// Test a plugin triggered by WAL writes | ||
Wal(wal::Config), | ||
} | ||
|
||
pub(crate) async fn command(config: Config) -> Result<(), Box<dyn Error>> { | ||
match config.command { | ||
Command::Wal(config) => wal::command(config).await, | ||
} | ||
} |
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,79 @@ | ||
use crate::commands::common::{InfluxDb3Config, SeparatedKeyValue, SeparatedList}; | ||
use influxdb3_client::plugin_development::WalPluginTestRequest; | ||
use secrecy::ExposeSecret; | ||
use std::collections::HashMap; | ||
use std::error::Error; | ||
|
||
#[derive(Debug, clap::Parser)] | ||
pub struct Config { | ||
#[clap(flatten)] | ||
influxdb3_config: InfluxDb3Config, | ||
|
||
#[clap(flatten)] | ||
wal_plugin_test: WalPluginTest, | ||
} | ||
|
||
#[derive(Debug, clap::Parser)] | ||
pub struct WalPluginTest { | ||
/// The name of the plugin, which should match its file name on the server `<plugin-dir>/<name>.py` | ||
#[clap(short = 'n', long = "name")] | ||
pub name: String, | ||
/// If given, pass this line protocol as input | ||
#[clap(long = "lp")] | ||
pub input_lp: Option<String>, | ||
/// If given, pass this file of LP as input from on the server `<plugin-dir>/<name>_test/<input-file>` | ||
#[clap(long = "file")] | ||
pub input_file: Option<String>, | ||
/// If given, save the output to this file on the server in `<plugin-dir>/<name>_test/<save-output-to-file>` | ||
#[clap(long = "save-output-to-file")] | ||
pub save_output_to_file: Option<String>, | ||
/// If given, validate the output against this file on the server in `<plugin-dir>/<name>_test/<validate-output-file>` | ||
#[clap(long = "validate-output-file")] | ||
pub validate_output_file: Option<String>, | ||
/// If given pass this map of string key/value pairs as input arguments | ||
#[clap(long = "input-arguments")] | ||
pub input_arguments: Option<SeparatedList<SeparatedKeyValue<String, String>>>, | ||
} | ||
|
||
impl From<WalPluginTest> for WalPluginTestRequest { | ||
fn from(val: WalPluginTest) -> Self { | ||
let input_arguments = val.input_arguments.map(|a| { | ||
a.into_iter() | ||
.map(|SeparatedKeyValue((k, v))| (k, v)) | ||
.collect::<HashMap<String, String>>() | ||
}); | ||
|
||
Self { | ||
name: val.name, | ||
input_lp: val.input_lp, | ||
input_file: val.input_file, | ||
save_output_to_file: val.save_output_to_file, | ||
validate_output_file: val.validate_output_file, | ||
input_arguments, | ||
} | ||
} | ||
} | ||
|
||
pub(super) async fn command(config: Config) -> Result<(), Box<dyn Error>> { | ||
let InfluxDb3Config { | ||
host_url, | ||
auth_token, | ||
.. | ||
} = config.influxdb3_config; | ||
|
||
let wal_plugin_test_request: WalPluginTestRequest = config.wal_plugin_test.into(); | ||
|
||
let mut client = influxdb3_client::Client::new(host_url)?; | ||
if let Some(t) = auth_token { | ||
client = client.with_auth_token(t.expose_secret()); | ||
} | ||
let response = client.wal_plugin_test(wal_plugin_test_request).await?; | ||
|
||
let res = serde_json::to_string_pretty(&response) | ||
.expect("serialize wal plugin test response as JSON"); | ||
|
||
// pretty print the response | ||
println!("{}", res); | ||
|
||
Ok(()) | ||
} |
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,23 @@ | ||
//! Request structs for the /api/v3/plugin_test API | ||
use serde::{Deserialize, Serialize}; | ||
use std::collections::HashMap; | ||
|
||
/// Request definition for `POST /api/v3/plugin_test/wal` API | ||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct WalPluginTestRequest { | ||
pub name: String, | ||
pub input_lp: Option<String>, | ||
pub input_file: Option<String>, | ||
pub save_output_to_file: Option<String>, | ||
pub validate_output_file: Option<String>, | ||
pub input_arguments: Option<HashMap<String, String>>, | ||
} | ||
|
||
/// Response definition for `POST /api/v3/plugin_test/wal` API | ||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct WalPluginTestResponse { | ||
pub log_lines: Vec<String>, | ||
pub database_writes: HashMap<String, Vec<String>>, | ||
pub errors: Vec<String>, | ||
} |
Oops, something went wrong.