-
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.
- Loading branch information
Showing
17 changed files
with
442 additions
and
7 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
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,68 @@ | ||
use std::error::Error; | ||
use secrecy::ExposeSecret; | ||
use influxdb3_client::plugin_test::WalPluginTestRequest; | ||
use crate::commands::common::InfluxDb3Config; | ||
|
||
#[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>, | ||
} | ||
|
||
impl Into<WalPluginTestRequest> for WalPluginTest { | ||
fn into(self) -> WalPluginTestRequest { | ||
WalPluginTestRequest { | ||
name: self.name, | ||
input_lp: self.input_lp, | ||
input_file: self.input_file, | ||
save_output_to_file: self.save_output_to_file, | ||
validate_output_file: self.validate_output_file, | ||
} | ||
} | ||
} | ||
|
||
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 resonse = client.wal_plugin_test(wal_plugin_test_request).await?; | ||
|
||
// pretty print the response | ||
println!( | ||
"RESPONSE:\n{}", | ||
serde_json::to_string_pretty(&resonse).expect("serialize wal plugin test response as JSON") | ||
); | ||
|
||
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,22 @@ | ||
//! Request structs for the /api/v3/plugin_test API | ||
use std::collections::HashMap; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// 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>, | ||
} | ||
|
||
/// 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>, | ||
} |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#[cfg(feature = "system-py")] | ||
pub mod system_py; | ||
pub mod system_py; |
Oops, something went wrong.