Skip to content

Commit 5d88655

Browse files
authored
enhancement(vdev): Load compose files and inject network block (vectordotdev#17025)
* enhancement(vdev): Load compose files and inject network block * remove temp file after compose.stop() is called * Make config service for serialization include more fields * Add compose support for webdhfs * remove renaming setting from serde annotations * Use from_iter() in network injection * utilize tempfile for creation of the rewritten compose file * chore(vdev): Make network non optional in Compose struct * Merge via cherry-pick network name PR, cargo fmt * Remove unneeded comments * Reintroduce path in Compose struct, clean up comments * add cargo.toml * Utilize tempfile_in() to fix relative file path resolution of compose files * Restore proxy network on nginx integration test * Make Compose run command command use the original file path if environment is active * Conditional compile for Unix, prevent windows CI failure * Condtional compilation fix * Using Value for fields not used * Remove conditional compilation flags to ensure temp_file created on Windows * Allow deadcode for windows * Remove unneeded to_string()
1 parent eafba69 commit 5d88655

File tree

32 files changed

+80
-132
lines changed

32 files changed

+80
-132
lines changed

scripts/integration/amqp/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,3 @@ services:
55
image: docker.io/rabbitmq:${CONFIG_VERSION}
66
ports:
77
- 5672:5672
8-
9-
networks:
10-
default:
11-
name: ${VECTOR_NETWORK}

scripts/integration/aws/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,3 @@ services:
1414
volumes:
1515
- $DOCKER_SOCKET:/var/run/docker.sock
1616
- $HOME/.aws/:/home/.aws/
17-
18-
networks:
19-
default:
20-
name: ${VECTOR_NETWORK}

scripts/integration/azure/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,3 @@ services:
66
command: azurite --blobHost 0.0.0.0 --loose
77
volumes:
88
- /var/run:/var/run
9-
10-
networks:
11-
default:
12-
name: ${VECTOR_NETWORK}

scripts/integration/chronicle/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,3 @@ services:
1010
command:
1111
- -p
1212
- /public.pem
13-
14-
networks:
15-
default:
16-
name: ${VECTOR_NETWORK}

scripts/integration/clickhouse/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,3 @@ version: '3'
33
services:
44
clickhouse:
55
image: docker.io/yandex/clickhouse-server:${CONFIG_VERSION}
6-
7-
networks:
8-
default:
9-
name: ${VECTOR_NETWORK}

scripts/integration/databend/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,3 @@ services:
1919
- minio
2020
healthcheck:
2121
test: "curl -f localhost:8080/v1/health || exit 1"
22-
23-
networks:
24-
default:
25-
name: ${VECTOR_NETWORK}

scripts/integration/datadog-agent/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,3 @@ services:
2626
- DD_CMD_PORT=5002
2727
- DD_USE_DOGSTATSD=false
2828
- DD_HOSTNAME=datadog-trace-agent
29-
30-
networks:
31-
default:
32-
name: ${VECTOR_NETWORK}

scripts/integration/datadog-traces/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,3 @@ services:
2929
- DD_APM_MAX_MEMORY=0
3030
- DD_APM_MAX_CPU_PERCENT=0
3131
- DD_HOSTNAME=datadog-trace-agent-to-vector
32-
33-
networks:
34-
default:
35-
name: ${VECTOR_NETWORK}

scripts/integration/dnstap/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,5 @@ services:
1111
- dnstap-sockets:/bind2/etc/bind/socket
1212
- dnstap-sockets:/bind3/etc/bind/socket
1313

14-
networks:
15-
default:
16-
name: ${VECTOR_NETWORK}
17-
1814
volumes:
1915
dnstap-sockets: {}

scripts/integration/elasticsearch/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,3 @@ services:
2525
- ES_JAVA_OPTS=-Xms400m -Xmx400m
2626
volumes:
2727
- ../../../tests/data/ca:/usr/share/elasticsearch/config/certs:ro
28-
29-
networks:
30-
default:
31-
name: ${VECTOR_NETWORK}

scripts/integration/eventstoredb/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,3 @@ services:
66
command: --insecure --stats-period-sec=1
77
volumes:
88
- ../../../tests/data:/etc/vector:ro
9-
10-
networks:
11-
default:
12-
name: ${VECTOR_NETWORK}

scripts/integration/gcp/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,3 @@ services:
66
environment:
77
- PUBSUB_PROJECT1=testproject,topic1:subscription1
88
- PUBSUB_PROJECT2=sourceproject,topic2:subscription2
9-
10-
networks:
11-
default:
12-
name: ${VECTOR_NETWORK}

scripts/integration/http-client/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,3 @@ services:
2929
- ../../../tests/data/http-client/serve:/data
3030
- ../../../tests/data/ca/intermediate_server/certs/dufs-https-chain.cert.pem:/certs/ca.cert.pem
3131
- ../../../tests/data/ca/intermediate_server/private/dufs-https.key.pem:/certs/ca.key.pem
32-
33-
networks:
34-
default:
35-
name: ${VECTOR_NETWORK}

scripts/integration/humio/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,3 @@ version: '3'
33
services:
44
humio:
55
image: docker.io/humio/humio:${CONFIG_VERSION}
6-
7-
networks:
8-
default:
9-
name: ${VECTOR_NETWORK}

scripts/integration/influxdb/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,3 @@ services:
1919
command: influxd --reporting-disabled
2020
environment:
2121
- INFLUXDB_REPORTING_DISABLED=true
22-
23-
networks:
24-
default:
25-
name: ${VECTOR_NETWORK}

scripts/integration/kafka/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,3 @@ services:
3333
volumes:
3434
- ../../../tests/data/ca/intermediate_server/private/kafka.p12:/certs/kafka.p12:ro
3535
- ../../../tests/data/kafka_server_jaas.conf:/etc/kafka/kafka_server_jaas.conf
36-
37-
networks:
38-
default:
39-
name: ${VECTOR_NETWORK}

scripts/integration/logstash/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,3 @@ services:
1212
- /dev/null:/usr/share/logstash/pipeline/logstash.yml
1313
- ../../../tests/data/host.docker.internal.crt:/tmp/logstash.crt
1414
- ../../../tests/data/logstash/logstash.conf:/usr/share/logstash/pipeline/logstash.conf
15-
16-
networks:
17-
default:
18-
name: ${VECTOR_NETWORK}

scripts/integration/loki/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,3 @@ services:
44
loki:
55
image: docker.io/grafana/loki:${CONFIG_VERSION}
66
command: -config.file=/etc/loki/local-config.yaml -auth.enabled=true
7-
8-
networks:
9-
default:
10-
name: ${VECTOR_NETWORK}

scripts/integration/mongodb/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,3 @@ services:
3030
- MONGODB_INITIAL_PRIMARY_PORT_NUMBER=27017
3131
- MONGODB_INITIAL_PRIMARY_ROOT_PASSWORD=toor
3232
- MONGODB_REPLICA_SET_KEY=vector
33-
34-
networks:
35-
default:
36-
name: ${VECTOR_NETWORK}

scripts/integration/nats/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,3 @@ services:
4343
- /usr/share/nats/config/nats-jwt.conf
4444
volumes:
4545
- ../../../tests/data/nats:/usr/share/nats/config
46-
47-
networks:
48-
default:
49-
name: ${VECTOR_NETWORK}

scripts/integration/nginx/compose.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,4 @@ services:
2222
- proxy
2323

2424
networks:
25-
default:
26-
name: ${VECTOR_NETWORK}
2725
proxy: {}

scripts/integration/opentelemetry/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,3 @@ services:
55
image: docker.io/otel/opentelemetry-collector-contrib:${CONFIG_VERSION}
66
volumes:
77
- ../../../tests/data/opentelemetry/config.yaml:/etc/otelcol-contrib/config.yaml
8-
9-
networks:
10-
default:
11-
name: ${VECTOR_NETWORK}

scripts/integration/postgres/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,5 @@ services:
1212
- ../../../tests/data/postgres-init.sh:/postgres-init.sh:ro
1313
- ../../../tests/data/ca:/certs:ro
1414

15-
networks:
16-
default:
17-
name: ${VECTOR_NETWORK}
18-
1915
volumes:
2016
socket: {}

scripts/integration/prometheus/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,3 @@ services:
2121
command: --config.file=/etc/vector/prometheus.yaml
2222
volumes:
2323
- ../../../tests/data:/etc/vector:ro
24-
25-
networks:
26-
default:
27-
name: ${VECTOR_NETWORK}

scripts/integration/pulsar/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,3 @@ services:
66
command: bin/pulsar standalone
77
ports:
88
- 6650:6650
9-
10-
networks:
11-
default:
12-
name: ${VECTOR_NETWORK}

scripts/integration/redis/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,3 @@ version: '3'
33
services:
44
redis:
55
image: docker.io/redis:${CONFIG_VERSION}
6-
7-
networks:
8-
default:
9-
name: ${VECTOR_NETWORK}

scripts/integration/shutdown/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,3 @@ services:
3131
volumes:
3232
- ../../../tests/data/ca/intermediate_server/private/kafka.p12:/certs/kafka.p12:ro
3333
- ../../../tests/data/kafka_server_jaas.conf:/etc/kafka/kafka_server_jaas.conf
34-
35-
networks:
36-
default:
37-
name: ${VECTOR_NETWORK}

scripts/integration/splunk/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,3 @@ services:
1313
- 8000:8000
1414
- 8088:8088
1515
- 8089:8089
16-
17-
networks:
18-
default:
19-
name: ${VECTOR_NETWORK}

scripts/integration/webhdfs/compose.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,3 @@ services:
3030
interval: 5s
3131
timeout: 5s
3232
retries: 3
33-
34-
networks:
35-
default:
36-
name: ${VECTOR_NETWORK}

vdev/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ serde = { version = "1.0", features = ["derive"] }
3535
serde_json = "1.0.95"
3636
serde_yaml = "0.9.19"
3737
sha2 = "0.10.6"
38-
tempfile = "3.4.0"
38+
tempfile = "3.5.0"
3939
toml = { version = "0.7.2", default-features = false, features = ["parse"] }

vdev/src/testing/config.rs

+34-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{env, fs};
55
use anyhow::{bail, Context, Result};
66
use hashlink::LinkedHashMap;
77
use itertools::{self, Itertools};
8-
use serde::Deserialize;
8+
use serde::{Deserialize, Serialize};
99
use serde_yaml::Value;
1010

1111
use crate::{app, util};
@@ -37,20 +37,49 @@ impl RustToolchainConfig {
3737
}
3838
}
3939

40-
#[derive(Debug, Deserialize)]
40+
#[derive(Debug, Deserialize, Serialize)]
4141
pub struct ComposeConfig {
4242
pub services: BTreeMap<String, ComposeService>,
43-
#[serde(default)]
43+
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
4444
pub volumes: BTreeMap<String, Value>,
45+
#[serde(default)]
46+
pub networks: BTreeMap<String, BTreeMap<String, String>>,
4547
}
4648

47-
#[derive(Debug, Deserialize)]
49+
#[derive(Debug, Deserialize, Serialize)]
4850
pub struct ComposeService {
51+
#[serde(default, skip_serializing_if = "Option::is_none")]
52+
pub image: Option<String>,
53+
#[serde(default, skip_serializing_if = "Option::is_none")]
54+
pub hostname: Option<String>,
55+
#[serde(default, skip_serializing_if = "Option::is_none")]
56+
pub container_name: Option<String>,
57+
#[serde(default, skip_serializing_if = "Option::is_none")]
58+
pub build: Option<Value>,
59+
#[serde(default, skip_serializing_if = "Option::is_none")]
60+
pub command: Option<Command>,
61+
#[serde(default, skip_serializing_if = "Option::is_none")]
62+
pub ports: Option<Vec<String>>,
63+
#[serde(default, skip_serializing_if = "Option::is_none")]
64+
pub env_file: Option<Vec<String>>,
65+
#[serde(default, skip_serializing_if = "Option::is_none")]
4966
pub volumes: Option<Vec<String>>,
67+
#[serde(default, skip_serializing_if = "Option::is_none")]
68+
pub environment: Option<Vec<String>>,
69+
#[serde(default, skip_serializing_if = "Option::is_none")]
70+
pub depends_on: Option<Vec<String>>,
71+
#[serde(default, skip_serializing_if = "Option::is_none")]
72+
pub healthcheck: Option<Value>,
73+
}
74+
75+
#[derive(Debug, Deserialize, Serialize)]
76+
#[serde(untagged)]
77+
pub enum Command {
78+
Single(String),
79+
Multiple(Vec<String>),
5080
}
5181

5282
impl ComposeConfig {
53-
#[cfg(unix)]
5483
pub fn parse(path: &Path) -> Result<Self> {
5584
let contents =
5685
fs::read_to_string(path).with_context(|| format!("failed to read {path:?}"))?;

vdev/src/testing/integration.rs

+45-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use std::{path::Path, path::PathBuf, process::Command};
1+
use std::{collections::BTreeMap, fs, path::Path, path::PathBuf, process::Command};
22

33
use anyhow::{bail, Context, Result};
4+
use tempfile::{Builder, NamedTempFile};
45

5-
#[cfg(unix)]
66
use super::config::ComposeConfig;
77
use super::config::{Environment, IntegrationTestConfig};
88
use super::runner::{
@@ -135,30 +135,52 @@ impl IntegrationTest {
135135
}
136136

137137
struct Compose {
138-
path: PathBuf,
138+
original_path: PathBuf,
139139
test_dir: PathBuf,
140140
env: Environment,
141-
#[cfg(unix)]
141+
#[cfg_attr(target_family = "windows", allow(dead_code))]
142142
config: ComposeConfig,
143143
network: String,
144+
temp_file: NamedTempFile,
144145
}
145146

146147
impl Compose {
147148
fn new(test_dir: PathBuf, env: Environment, network: String) -> Result<Option<Self>> {
148-
let path: PathBuf = [&test_dir, Path::new("compose.yaml")].iter().collect();
149-
match path.try_exists() {
150-
Err(error) => Err(error).with_context(|| format!("Could not lookup {path:?}")),
149+
let original_path: PathBuf = [&test_dir, Path::new("compose.yaml")].iter().collect();
150+
151+
match original_path.try_exists() {
152+
Err(error) => Err(error).with_context(|| format!("Could not lookup {original_path:?}")),
151153
Ok(false) => Ok(None),
152154
Ok(true) => {
153-
#[cfg(unix)]
154-
let config = ComposeConfig::parse(&path)?;
155+
let mut config = ComposeConfig::parse(&original_path)?;
156+
// Inject the networks block
157+
config.networks.insert(
158+
"default".to_string(),
159+
BTreeMap::from_iter([("name".to_string(), network.clone())]),
160+
);
161+
162+
// Create a named tempfile, there may be resource leakage here in case of SIGINT
163+
// Tried tempfile::tempfile() but this returns a File object without a usable path
164+
// https://docs.rs/tempfile/latest/tempfile/#resource-leaking
165+
let temp_file = Builder::new()
166+
.prefix("compose-temp-")
167+
.suffix(".yaml")
168+
.tempfile_in(&test_dir)
169+
.with_context(|| "Failed to create temporary compose file")?;
170+
171+
fs::write(
172+
temp_file.path(),
173+
serde_yaml::to_string(&config)
174+
.with_context(|| "Failed to serialize modified compose.yaml")?,
175+
)?;
176+
155177
Ok(Some(Self {
156-
path,
178+
original_path,
157179
test_dir,
158180
env,
159-
#[cfg(unix)]
160181
config,
161182
network,
183+
temp_file,
162184
}))
163185
}
164186
}
@@ -178,8 +200,19 @@ impl Compose {
178200
let mut command = CONTAINER_TOOL.clone();
179201
command.push("-compose");
180202
let mut command = Command::new(command);
203+
// When the integration test environment is already active, the tempfile path does not
204+
// exist because `Compose::new()` has not been called. In this case, the `stop` command
205+
// needs to use the calculated path from the integration name instead of the nonexistent
206+
// tempfile path. This is because `stop` doesn't go through the same logic as `start`
207+
// and doesn't create a new tempfile before calling docker compose.
208+
// If stop command needs to use some of the injected bits then we need to rebuild it
181209
command.arg("--file");
182-
command.arg(&self.path);
210+
if config.is_none() {
211+
command.arg(&self.original_path);
212+
} else {
213+
command.arg(self.temp_file.path());
214+
}
215+
183216
command.args(args);
184217

185218
command.current_dir(&self.test_dir);

0 commit comments

Comments
 (0)