Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
252 changes: 252 additions & 0 deletions scripts/integration/prometheus/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions scripts/integration/prometheus/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "vector-prometheus-env-manager"
version = "0.1.0"
edition = "2021"
authors = ["Vector Contributors <vector@datadoghq.com>"]
license = "MPL-2.0"
readme = "README.md"
publish = false

[dependencies]
anyhow = "1.0.66"
clap = { version = "4.0.18", features = ["derive"] }
dunce = "1.0.3"
serde_json = "1.0.87"

[workspace]
11 changes: 11 additions & 0 deletions scripts/integration/prometheus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# vector-prometheus-env-manager

-----

## Usage

```text
vdev int show prometheus
vdev int start prometheus <ENV>
vdev int stop prometheus <ENV>
```
28 changes: 28 additions & 0 deletions scripts/integration/prometheus/data/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: '3'

services:
influxdb:
image: docker.io/influxdb:${PROMETHEUS_VERSION}
environment:
- INFLUXDB_REPORTING_DISABLED=true
influxdb-tls:
image: docker.io/influxdb:${PROMETHEUS_VERSION}
environment:
- INFLUXDB_REPORTING_DISABLED=true
- INFLUXDB_HTTP_HTTPS_ENABLED=true
- INFLUXDB_HTTP_BIND_ADDRESS=:8087
- INFLUXDB_BIND_ADDRESS=:8089
- INFLUXDB_HTTP_HTTPS_CERTIFICATE=/etc/ssl/intermediate_server/certs/localhost-chain.cert.pem
- INFLUXDB_HTTP_HTTPS_PRIVATE_KEY=/etc/ssl/intermediate_server/private/localhost.key.pem
volumes:
- ../../../../tests/data/ca:/etc/ssl:ro
prometheus:
image: docker.io/prom/prometheus:${PROMETHEUS_VERSION:-v2.33.4}
command: --config.file=/etc/vector/prometheus.yaml
volumes:
- ../../../../tests/data:/etc/vector:ro

networks:
default:
name: ${VECTOR_NETWORK}
external: true
61 changes: 61 additions & 0 deletions scripts/integration/prometheus/src/core.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
use anyhow::{bail, Result};
use serde_json::Value;
use std::path::PathBuf;
use std::process::Command;
use std::thread;
use std::time::Duration;

pub fn start(config: Value) -> Result<()> {
let mut command = compose_command();
command.args(["up", "-d"]);

apply_env_vars(&mut command, &config);

let status = command.status()?;
if status.success() {
thread::sleep(Duration::from_secs(20));
return Ok(());
} else {
bail!("failed to execute: {}", render_command(&mut command));
}
}

pub fn stop(config: Value) -> Result<()> {
let mut command = compose_command();
command.args(["down", "-t", "0"]);

apply_env_vars(&mut command, &config);

let status = command.status()?;
if status.success() {
return Ok(());
} else {
bail!("failed to execute: {}", render_command(&mut command));
}
}

fn compose_command() -> Command {
let path = PathBuf::from_iter(["data", "docker-compose.yml"].iter());
let compose_file = match dunce::canonicalize(&path) {
Ok(p) => p.display().to_string(),
Err(_) => path.display().to_string(),
};

let mut command = Command::new("docker");
command.args(["compose", "-f", &compose_file]);
command
}

fn apply_env_vars(command: &mut Command, config: &Value) {
if let Some(version) = config.get("version") {
command.env("PROMETHEUS_VERSION", version.as_str().unwrap());
}
}

fn render_command(command: &mut Command) -> String {
format!(
"{} {}",
command.get_program().to_str().unwrap(),
Vec::from_iter(command.get_args().map(|arg| arg.to_str().unwrap())).join(" ")
)
}
26 changes: 26 additions & 0 deletions scripts/integration/prometheus/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
mod core;

use anyhow::Result;
use clap::{Parser, Subcommand};

#[derive(Parser, Debug)]
#[command(disable_help_subcommand = true)]
struct Cli {
#[command(subcommand)]
command: Commands,
}

#[derive(Subcommand, Debug)]
enum Commands {
Start { json: String },
Stop { json: String },
}

fn main() -> Result<()> {
let cli = Cli::parse();

match &cli.command {
Commands::Start { json } => core::start(serde_json::from_str(&json)?),
Commands::Stop { json } => core::stop(serde_json::from_str(&json)?),
}
}
Loading