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

feat: add victoria_metrics module #77

Merged
merged 5 commits into from Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ postgres = []
rabbitmq = []
redis = []
trufflesuite_ganachecli = []
victoriametrics = []
zookeeper = []

[dependencies]
Expand All @@ -52,7 +53,7 @@ postgres = "0.19.7"
pretty_env_logger = "0.5.0"
rdkafka = "0.36.0"
redis = "0.24.0"
reqwest = { version = "0.11.20", features = ["blocking"] }
reqwest = { version = "0.11.20", features = ["blocking", "json"] }
serde = { version = "1.0.188", features = [ "derive" ] }
serde_json = "1.0.107"
tokio = { version = "1", features = ["macros"] }
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ pub mod redis;
#[cfg(feature = "trufflesuite_ganachecli")]
#[cfg_attr(docsrs, doc(cfg(feature = "trufflesuite_ganachecli")))]
pub mod trufflesuite_ganachecli;
#[cfg(feature = "victoriametrics")]
#[cfg_attr(docsrs, doc(cfg(feature = "victoriametrics")))]
DDtKey marked this conversation as resolved.
Show resolved Hide resolved
pub mod victoriametrics;
#[cfg(feature = "zookeeper")]
#[cfg_attr(docsrs, doc(cfg(feature = "zookeeper")))]
pub mod zookeeper;
Expand Down
73 changes: 73 additions & 0 deletions src/victoriametrics/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
use testcontainers::{core::WaitFor, Image};

const NAME: &str = "victoriametrics/victoria-metrics";
const TAG: &str = "v1.96.0";

/// Module to work with [`VictoriaMetrics`] inside of tests.
///
/// Starts an instance of single-node VictoriaMetrics.
///
/// This module is based on the official [`VictoriaMetrics docker image`].
///
/// # Example
/// ```
/// use testcontainers::clients;
/// use testcontainers_modules::victoriametrics;
///
/// let docker = clients::Cli::default();
/// let victoriametrics_instance = docker.run(victoriametrics::VictoriaMetrics);
///
/// let import_url = format!("http://127.0.0.1:{}/api/v1/import", victoriametrics_instance.get_host_port_ipv4(8428));
/// let export_url = format!("http://127.0.0.1:{}/api/v1/export", victoriametrics_instance.get_host_port_ipv4(8428));
///
/// // operate on the import and export URLs..
/// ```
///
/// [`VictoriaMetrics`]: https://docs.victoriametrics.com/
/// [`VictoriaMetrics API examples`]: https://docs.victoriametrics.com/url-examples.html#victoriametrics-api-examples
/// [`VictoriaMetrics Docker image`]: https://hub.docker.com/r/victoriametrics/victoria-metrics
#[derive(Debug, Default)]
pub struct VictoriaMetrics;

impl Image for VictoriaMetrics {
type Args = ();

fn name(&self) -> String {
NAME.to_owned()
}

fn tag(&self) -> String {
TAG.to_owned()
}

fn ready_conditions(&self) -> Vec<WaitFor> {
vec![
WaitFor::message_on_stderr("started VictoriaMetrics"),
WaitFor::message_on_stderr(
"pprof handlers are exposed at http://127.0.0.1:8428/debug/pprof/",
),
]
}
}

#[cfg(test)]
mod tests {
use crate::victoriametrics::VictoriaMetrics as VictoriaMetricsImage;
use testcontainers::clients;

#[test]
fn query_buildinfo() {
let docker = clients::Cli::default();
let node = docker.run(VictoriaMetricsImage);
let host_port = node.get_host_port_ipv4(8428);
let url = format!("http://127.0.0.1:{}/api/v1/status/buildinfo", host_port);

let response = reqwest::blocking::get(url)
.unwrap()
.json::<serde_json::Value>()
.unwrap();
let version = response["data"]["version"].as_str().unwrap();

assert_eq!(version, "2.24.0");
}
}
Loading