Skip to content

Commit 6821972

Browse files
committed
Enable support for YAML merges in configuration
1 parent e2b83f2 commit 6821972

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Vector now supports YAML merges in configuration files, a part of the YAML 1.1
2+
specification. This functionality is useful for reducing the size of transform
3+
configurations. See YAML documentation [here](https://yaml.org/type/merge.html).
4+
5+
authors: lattwood

src/config/format.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,13 @@ where
6666
{
6767
match format {
6868
Format::Toml => toml::from_str(content).map_err(|e| vec![e.to_string()]),
69-
Format::Yaml => serde_yaml::from_str(content).map_err(|e| vec![e.to_string()]),
69+
Format::Yaml => {
70+
serde_yaml::from_str::<serde_yaml::Value>(content).and_then(|mut v| {
71+
v.apply_merge()?;
72+
serde_yaml::from_value(v)
73+
})
74+
.map_err(|e| vec![e.to_string()])
75+
}
7076
Format::Json => serde_json::from_str(content).map_err(|e| vec![e.to_string()]),
7177
}
7278
}
@@ -171,6 +177,10 @@ mod tests {
171177
type = "socket"
172178
mode = "tcp"
173179
address = "127.0.0.1:1235"
180+
[sources.in2]
181+
type = "socket"
182+
mode = "tcp"
183+
address = "127.0.0.1:1234"
174184
[transforms.sample]
175185
type = "sample"
176186
inputs = ["in"]
@@ -208,10 +218,13 @@ mod tests {
208218
r#" encoding:"#,
209219
r#" type: "csv""#,
210220
r#"sources:"#,
211-
r#" in:"#,
221+
r#" in: &a"#,
212222
r#" type: "socket""#,
213-
r#" mode: "tcp""#,
223+
r#" mode: &b "tcp""#,
214224
r#" address: "127.0.0.1:1235""#,
225+
r#" in2:"#,
226+
r#" <<: *a"#,
227+
r#" address: "127.0.0.1:1234""#,
215228
r#"transforms:"#,
216229
r#" sample:"#,
217230
r#" type: "sample""#,
@@ -220,7 +233,7 @@ mod tests {
220233
r#"sinks:"#,
221234
r#" out:"#,
222235
r#" type: "socket""#,
223-
r#" mode: "tcp""#,
236+
r#" mode: *b"#,
224237
r#" inputs: ["sample"]"#,
225238
r#" encoding:"#,
226239
r#" codec: "text""#,
@@ -248,6 +261,11 @@ mod tests {
248261
"type": "socket",
249262
"mode": "tcp",
250263
"address": "127.0.0.1:1235"
264+
},
265+
"in2": {
266+
"type": "socket",
267+
"mode": "tcp",
268+
"address": "127.0.0.1:1234"
251269
}
252270
},
253271
"transforms": {

0 commit comments

Comments
 (0)