forked from vectordotdev/vector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.rs
1378 lines (1209 loc) · 40.4 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#![allow(missing_docs)]
use std::{
collections::{HashMap, HashSet},
fmt::{self, Display, Formatter},
hash::Hash,
net::SocketAddr,
path::PathBuf,
time::Duration,
};
use crate::{
conditions,
event::{Metric, Value},
secrets::SecretBackends,
serde::OneOrMany,
};
use indexmap::IndexMap;
use serde::Serialize;
use vector_config::configurable_component;
pub use vector_lib::config::{
AcknowledgementsConfig, DataType, GlobalOptions, Input, LogNamespace,
SourceAcknowledgementsConfig, SourceOutput, TransformOutput,
};
pub use vector_lib::configurable::component::{
GenerateConfig, SinkDescription, TransformDescription,
};
pub mod api;
mod builder;
mod cmd;
mod compiler;
mod diff;
pub mod dot_graph;
mod enrichment_table;
pub mod format;
mod graph;
mod loading;
pub mod provider;
pub mod schema;
mod secret;
mod sink;
mod source;
mod transform;
pub mod unit_test;
mod validation;
mod vars;
pub mod watcher;
pub use builder::ConfigBuilder;
pub use cmd::{cmd, Opts};
pub use diff::ConfigDiff;
pub use enrichment_table::{EnrichmentTableConfig, EnrichmentTableOuter};
pub use format::{Format, FormatHint};
pub use loading::{
load, load_builder_from_paths, load_from_paths, load_from_paths_with_provider_and_secrets,
load_from_str, load_source_from_paths, merge_path_lists, process_paths, COLLECTOR,
CONFIG_PATHS,
};
pub use provider::ProviderConfig;
pub use secret::SecretBackend;
pub use sink::{BoxedSink, SinkConfig, SinkContext, SinkHealthcheckOptions, SinkOuter};
pub use source::{BoxedSource, SourceConfig, SourceContext, SourceOuter};
pub use transform::{
get_transform_output_ids, BoxedTransform, TransformConfig, TransformContext, TransformOuter,
};
pub use unit_test::{build_unit_tests, build_unit_tests_main, UnitTestResult};
pub use validation::warnings;
pub use vars::{interpolate, ENVIRONMENT_VARIABLE_INTERPOLATION_REGEX};
pub use vector_lib::{
config::{
init_log_schema, init_telemetry, log_schema, proxy::ProxyConfig, telemetry, ComponentKey,
LogSchema, OutputId,
},
id::Inputs,
};
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq)]
pub struct ComponentConfig {
pub config_paths: Vec<PathBuf>,
pub component_key: ComponentKey,
}
impl ComponentConfig {
pub const fn new(config_paths: Vec<PathBuf>, component_key: ComponentKey) -> Self {
Self {
config_paths,
component_key,
}
}
pub fn contains(&self, config_paths: &[PathBuf]) -> Option<ComponentKey> {
if config_paths.iter().any(|p| self.config_paths.contains(p)) {
return Some(self.component_key.clone());
}
None
}
}
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq)]
pub enum ConfigPath {
File(PathBuf, FormatHint),
Dir(PathBuf),
}
impl<'a> From<&'a ConfigPath> for &'a PathBuf {
fn from(config_path: &'a ConfigPath) -> &'a PathBuf {
match config_path {
ConfigPath::File(path, _) => path,
ConfigPath::Dir(path) => path,
}
}
}
impl ConfigPath {
pub const fn as_dir(&self) -> Option<&PathBuf> {
match self {
Self::Dir(path) => Some(path),
_ => None,
}
}
}
#[derive(Debug, Default, Serialize)]
pub struct Config {
#[cfg(feature = "api")]
pub api: api::Options,
pub schema: schema::Options,
pub global: GlobalOptions,
pub healthchecks: HealthcheckOptions,
sources: IndexMap<ComponentKey, SourceOuter>,
sinks: IndexMap<ComponentKey, SinkOuter<OutputId>>,
transforms: IndexMap<ComponentKey, TransformOuter<OutputId>>,
pub enrichment_tables: IndexMap<ComponentKey, EnrichmentTableOuter<OutputId>>,
tests: Vec<TestDefinition>,
secret: IndexMap<ComponentKey, SecretBackends>,
pub graceful_shutdown_duration: Option<Duration>,
}
impl Config {
pub fn builder() -> builder::ConfigBuilder {
Default::default()
}
pub fn is_empty(&self) -> bool {
self.sources.is_empty()
}
pub fn sources(&self) -> impl Iterator<Item = (&ComponentKey, &SourceOuter)> {
self.sources.iter()
}
pub fn source(&self, id: &ComponentKey) -> Option<&SourceOuter> {
self.sources.get(id)
}
pub fn transforms(&self) -> impl Iterator<Item = (&ComponentKey, &TransformOuter<OutputId>)> {
self.transforms.iter()
}
pub fn transform(&self, id: &ComponentKey) -> Option<&TransformOuter<OutputId>> {
self.transforms.get(id)
}
pub fn sinks(&self) -> impl Iterator<Item = (&ComponentKey, &SinkOuter<OutputId>)> {
self.sinks.iter()
}
pub fn sink(&self, id: &ComponentKey) -> Option<&SinkOuter<OutputId>> {
self.sinks.get(id)
}
pub fn enrichment_tables(
&self,
) -> impl Iterator<Item = (&ComponentKey, &EnrichmentTableOuter<OutputId>)> {
self.enrichment_tables.iter()
}
pub fn enrichment_table(&self, id: &ComponentKey) -> Option<&EnrichmentTableOuter<OutputId>> {
self.enrichment_tables.get(id)
}
pub fn inputs_for_node(&self, id: &ComponentKey) -> Option<&[OutputId]> {
self.transforms
.get(id)
.map(|t| &t.inputs[..])
.or_else(|| self.sinks.get(id).map(|s| &s.inputs[..]))
.or_else(|| self.enrichment_tables.get(id).map(|s| &s.inputs[..]))
}
pub fn propagate_acknowledgements(&mut self) -> Result<(), Vec<String>> {
let inputs: Vec<_> = self
.sinks
.iter()
.filter(|(_, sink)| {
sink.inner
.acknowledgements()
.merge_default(&self.global.acknowledgements)
.enabled()
})
.flat_map(|(name, sink)| {
sink.inputs
.iter()
.map(|input| (name.clone(), input.clone()))
})
.collect();
self.propagate_acks_rec(inputs);
Ok(())
}
fn propagate_acks_rec(&mut self, sink_inputs: Vec<(ComponentKey, OutputId)>) {
for (sink, input) in sink_inputs {
let component = &input.component;
if let Some(source) = self.sources.get_mut(component) {
if source.inner.can_acknowledge() {
source.sink_acknowledgements = true;
} else {
warn!(
message = "Source has acknowledgements enabled by a sink, but acknowledgements are not supported by this source. Silent data loss could occur.",
source = component.id(),
sink = sink.id(),
);
}
} else if let Some(transform) = self.transforms.get(component) {
let inputs = transform
.inputs
.iter()
.map(|input| (sink.clone(), input.clone()))
.collect();
self.propagate_acks_rec(inputs);
}
}
}
}
/// Healthcheck options.
#[configurable_component]
#[derive(Clone, Copy, Debug)]
#[serde(default)]
pub struct HealthcheckOptions {
/// Whether or not healthchecks are enabled for all sinks.
///
/// Can be overridden on a per-sink basis.
pub enabled: bool,
/// Whether or not to require a sink to report as being healthy during startup.
///
/// When enabled and a sink reports not being healthy, Vector will exit during start-up.
///
/// Can be alternatively set, and overridden by, the `--require-healthy` command-line flag.
pub require_healthy: bool,
}
impl HealthcheckOptions {
pub fn set_require_healthy(&mut self, require_healthy: impl Into<Option<bool>>) {
if let Some(require_healthy) = require_healthy.into() {
self.require_healthy = require_healthy;
}
}
fn merge(&mut self, other: Self) {
self.enabled &= other.enabled;
self.require_healthy |= other.require_healthy;
}
}
impl Default for HealthcheckOptions {
fn default() -> Self {
Self {
enabled: true,
require_healthy: false,
}
}
}
/// Unique thing, like port, of which only one owner can be.
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub enum Resource {
Port(SocketAddr, Protocol),
SystemFdOffset(usize),
Fd(u32),
DiskBuffer(String),
}
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd, Copy)]
pub enum Protocol {
Tcp,
Udp,
}
impl Resource {
pub const fn tcp(addr: SocketAddr) -> Self {
Self::Port(addr, Protocol::Tcp)
}
pub const fn udp(addr: SocketAddr) -> Self {
Self::Port(addr, Protocol::Udp)
}
/// From given components returns all that have a resource conflict with any other component.
pub fn conflicts<K: Eq + Hash + Clone>(
components: impl IntoIterator<Item = (K, Vec<Resource>)>,
) -> HashMap<Resource, HashSet<K>> {
let mut resource_map = HashMap::<Resource, HashSet<K>>::new();
let mut unspecified = Vec::new();
// Find equality based conflicts
for (key, resources) in components {
for resource in resources {
if let Resource::Port(address, protocol) = &resource {
if address.ip().is_unspecified() {
unspecified.push((key.clone(), *address, *protocol));
}
}
resource_map
.entry(resource)
.or_default()
.insert(key.clone());
}
}
// Port with unspecified address will bind to all network interfaces
// so we have to check for all Port resources if they share the same
// port.
for (key, address0, protocol0) in unspecified {
for (resource, components) in resource_map.iter_mut() {
if let Resource::Port(address, protocol) = resource {
// IP addresses can either be v4 or v6.
// Therefore we check if the ip version matches, the port matches and if the protocol (TCP/UDP) matches
// when checking for equality.
if &address0 == address && &protocol0 == protocol {
components.insert(key.clone());
}
}
}
}
resource_map.retain(|_, components| components.len() > 1);
resource_map
}
}
impl Display for Protocol {
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), fmt::Error> {
match self {
Protocol::Udp => write!(fmt, "udp"),
Protocol::Tcp => write!(fmt, "tcp"),
}
}
}
impl Display for Resource {
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), fmt::Error> {
match self {
Resource::Port(address, protocol) => write!(fmt, "{} {}", protocol, address),
Resource::SystemFdOffset(offset) => write!(fmt, "systemd {}th socket", offset + 1),
Resource::Fd(fd) => write!(fmt, "file descriptor: {}", fd),
Resource::DiskBuffer(name) => write!(fmt, "disk buffer {:?}", name),
}
}
}
/// A unit test definition.
#[configurable_component]
#[derive(Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct TestDefinition<T: 'static = OutputId> {
/// The name of the unit test.
pub name: String,
/// An input event to test against.
pub input: Option<TestInput>,
/// A set of input events to test against.
#[serde(default)]
pub inputs: Vec<TestInput>,
/// A set of expected output events after the test has run.
#[serde(default)]
pub outputs: Vec<TestOutput<T>>,
/// A set of component outputs that should not have emitted any events.
#[serde(default)]
pub no_outputs_from: Vec<T>,
}
impl TestDefinition<String> {
fn resolve_outputs(
self,
graph: &graph::Graph,
) -> Result<TestDefinition<OutputId>, Vec<String>> {
let TestDefinition {
name,
input,
inputs,
outputs,
no_outputs_from,
} = self;
let mut errors = Vec::new();
let output_map = graph.input_map().expect("ambiguous outputs");
let outputs = outputs
.into_iter()
.map(|old| {
let TestOutput {
extract_from,
conditions,
} = old;
(extract_from.to_vec(), conditions)
})
.filter_map(|(extract_from, conditions)| {
let mut outputs = Vec::new();
for from in extract_from {
if let Some(output_id) = output_map.get(&from) {
outputs.push(output_id.clone());
} else {
errors.push(format!(
r#"Invalid extract_from target in test '{}': '{}' does not exist"#,
name, from
));
}
}
if outputs.is_empty() {
None
} else {
Some(TestOutput {
extract_from: outputs.into(),
conditions,
})
}
})
.collect();
let no_outputs_from = no_outputs_from
.into_iter()
.filter_map(|o| {
if let Some(output_id) = output_map.get(&o) {
Some(output_id.clone())
} else {
errors.push(format!(
r#"Invalid no_outputs_from target in test '{}': '{}' does not exist"#,
name, o
));
None
}
})
.collect();
if errors.is_empty() {
Ok(TestDefinition {
name,
input,
inputs,
outputs,
no_outputs_from,
})
} else {
Err(errors)
}
}
}
impl TestDefinition<OutputId> {
fn stringify(self) -> TestDefinition<String> {
let TestDefinition {
name,
input,
inputs,
outputs,
no_outputs_from,
} = self;
let outputs = outputs
.into_iter()
.map(|old| TestOutput {
extract_from: old
.extract_from
.to_vec()
.into_iter()
.map(|item| item.to_string())
.collect::<Vec<_>>()
.into(),
conditions: old.conditions,
})
.collect();
let no_outputs_from = no_outputs_from.iter().map(ToString::to_string).collect();
TestDefinition {
name,
input,
inputs,
outputs,
no_outputs_from,
}
}
}
/// A unit test input.
///
/// An input describes not only the type of event to insert, but also which transform within the
/// configuration to insert it to.
#[configurable_component]
#[derive(Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct TestInput {
/// The name of the transform to insert the input event to.
pub insert_at: ComponentKey,
/// The type of the input event.
///
/// Can be either `raw`, `vrl`, `log`, or `metric.
#[serde(default = "default_test_input_type", rename = "type")]
pub type_str: String,
/// The raw string value to use as the input event.
///
/// Use this only when the input event should be a raw event (i.e. unprocessed/undecoded log
/// event) and when the input type is set to `raw`.
pub value: Option<String>,
/// The vrl expression to generate the input event.
///
/// Only relevant when `type` is `vrl`.
pub source: Option<String>,
/// The set of log fields to use when creating a log input event.
///
/// Only relevant when `type` is `log`.
pub log_fields: Option<IndexMap<String, Value>>,
/// The metric to use as an input event.
///
/// Only relevant when `type` is `metric`.
pub metric: Option<Metric>,
}
fn default_test_input_type() -> String {
"raw".to_string()
}
/// A unit test output.
///
/// An output describes what we expect a transform to emit when fed a certain event, or events, when
/// running a unit test.
#[configurable_component]
#[derive(Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct TestOutput<T: 'static = OutputId> {
/// The transform outputs to extract events from.
pub extract_from: OneOrMany<T>,
/// The conditions to run against the output to validate that they were transformed as expected.
pub conditions: Option<Vec<conditions::AnyCondition>>,
}
#[cfg(all(test, feature = "sources-file", feature = "sinks-console"))]
mod tests {
use std::{collections::HashMap, path::PathBuf};
use crate::{config, topology};
use indoc::indoc;
use super::{builder::ConfigBuilder, format, load_from_str, ComponentKey, ConfigDiff, Format};
async fn load(config: &str, format: config::Format) -> Result<Vec<String>, Vec<String>> {
match config::load_from_str(config, format) {
Ok(c) => {
let diff = ConfigDiff::initial(&c);
let c2 = config::load_from_str(config, format).unwrap();
match (
config::warnings(&c2),
topology::TopologyPieces::build(&c, &diff, HashMap::new(), Default::default())
.await,
) {
(warnings, Ok(_pieces)) => Ok(warnings),
(_, Err(errors)) => Err(errors),
}
}
Err(error) => Err(error),
}
}
#[tokio::test]
async fn bad_inputs() {
let err = load(
r#"
[sources.in]
type = "test_basic"
[transforms.sample]
type = "test_basic"
inputs = []
suffix = "foo"
increase = 1.25
[transforms.sample2]
type = "test_basic"
inputs = ["qwerty"]
suffix = "foo"
increase = 1.25
[sinks.out]
type = "test_basic"
inputs = ["asdf", "in", "in"]
"#,
Format::Toml,
)
.await
.unwrap_err();
assert_eq!(
vec![
"Sink \"out\" has input \"in\" duplicated 2 times",
"Transform \"sample\" has no inputs",
"Input \"qwerty\" for transform \"sample2\" doesn't match any components.",
"Input \"asdf\" for sink \"out\" doesn't match any components.",
],
err,
);
}
#[tokio::test]
async fn duplicate_name() {
let err = load(
r#"
[sources.foo]
type = "test_basic"
[sources.bar]
type = "test_basic"
[transforms.foo]
type = "test_basic"
inputs = ["bar"]
suffix = "foo"
increase = 1.25
[sinks.out]
type = "test_basic"
inputs = ["foo"]
"#,
Format::Toml,
)
.await
.unwrap_err();
assert_eq!(
err,
vec!["More than one component with name \"foo\" (source, transform).",]
);
}
#[tokio::test]
#[cfg(unix)]
async fn conflicting_stdin_and_fd_resources() {
let errors = load(
r#"
[sources.stdin]
type = "stdin"
[sources.file_descriptor]
type = "file_descriptor"
fd = 0
[sinks.out]
type = "test_basic"
inputs = ["stdin", "file_descriptor"]
"#,
Format::Toml,
)
.await
.unwrap_err();
assert_eq!(errors.len(), 1);
let expected_prefix = "Resource `file descriptor: 0` is claimed by multiple components:";
assert!(errors[0].starts_with(expected_prefix));
}
#[tokio::test]
#[cfg(unix)]
async fn conflicting_fd_resources() {
let errors = load(
r#"
[sources.file_descriptor1]
type = "file_descriptor"
fd = 10
[sources.file_descriptor2]
type = "file_descriptor"
fd = 10
[sinks.out]
type = "test_basic"
inputs = ["file_descriptor1", "file_descriptor2"]
"#,
Format::Toml,
)
.await
.unwrap_err();
assert_eq!(errors.len(), 1);
let expected_prefix = "Resource `file descriptor: 10` is claimed by multiple components:";
assert!(errors[0].starts_with(expected_prefix));
}
#[tokio::test]
#[cfg(all(unix, feature = "sources-file_descriptor"))]
async fn no_conflict_fd_resources() {
use crate::sources::file_descriptors::file_descriptor::null_fd;
let fd1 = null_fd().unwrap();
let fd2 = null_fd().unwrap();
let result = load(
&format!(
r#"
[sources.file_descriptor1]
type = "file_descriptor"
fd = {fd1}
[sources.file_descriptor2]
type = "file_descriptor"
fd = {fd2}
[sinks.out]
type = "test_basic"
inputs = ["file_descriptor1", "file_descriptor2"]
"#
),
Format::Toml,
)
.await;
let expected = Ok(vec![]);
assert_eq!(result, expected);
}
#[tokio::test]
async fn warnings() {
let warnings = load(
r#"
[sources.in1]
type = "test_basic"
[sources.in2]
type = "test_basic"
[transforms.sample1]
type = "test_basic"
inputs = ["in1"]
suffix = "foo"
increase = 1.25
[transforms.sample2]
type = "test_basic"
inputs = ["in1"]
suffix = "foo"
increase = 1.25
[sinks.out]
type = "test_basic"
inputs = ["sample1"]
"#,
Format::Toml,
)
.await
.unwrap();
assert_eq!(
warnings,
vec![
"Transform \"sample2\" has no consumers",
"Source \"in2\" has no consumers",
]
)
}
#[tokio::test]
async fn cycle() {
let errors = load(
r#"
[sources.in]
type = "test_basic"
[transforms.one]
type = "test_basic"
inputs = ["in"]
suffix = "foo"
increase = 1.25
[transforms.two]
type = "test_basic"
inputs = ["one", "four"]
suffix = "foo"
increase = 1.25
[transforms.three]
type = "test_basic"
inputs = ["two"]
suffix = "foo"
increase = 1.25
[transforms.four]
type = "test_basic"
inputs = ["three"]
suffix = "foo"
increase = 1.25
[sinks.out]
type = "test_basic"
inputs = ["four"]
"#,
Format::Toml,
)
.await
.unwrap_err();
assert_eq!(
errors,
vec!["Cyclic dependency detected in the chain [ four -> two -> three -> four ]"]
)
}
#[test]
fn default_data_dir() {
let config = load_from_str(
indoc! {r#"
[sources.in]
type = "test_basic"
[sinks.out]
type = "test_basic"
inputs = ["in"]
"#},
Format::Toml,
)
.unwrap();
assert_eq!(
Some(PathBuf::from("/var/lib/vector")),
config.global.data_dir
)
}
#[test]
fn default_schema() {
let config = load_from_str(
indoc! {r#"
[sources.in]
type = "test_basic"
[sinks.out]
type = "test_basic"
inputs = ["in"]
"#},
Format::Toml,
)
.unwrap();
assert_eq!(
"host",
config.global.log_schema.host_key().unwrap().to_string()
);
assert_eq!(
"message",
config.global.log_schema.message_key().unwrap().to_string()
);
assert_eq!(
"timestamp",
config
.global
.log_schema
.timestamp_key()
.unwrap()
.to_string()
);
}
#[test]
fn custom_schema() {
let config = load_from_str(
indoc! {r#"
[log_schema]
host_key = "this"
message_key = "that"
timestamp_key = "then"
[sources.in]
type = "test_basic"
[sinks.out]
type = "test_basic"
inputs = ["in"]
"#},
Format::Toml,
)
.unwrap();
assert_eq!(
"this",
config.global.log_schema.host_key().unwrap().to_string()
);
assert_eq!(
"that",
config.global.log_schema.message_key().unwrap().to_string()
);
assert_eq!(
"then",
config
.global
.log_schema
.timestamp_key()
.unwrap()
.to_string()
);
}
#[test]
fn config_append() {
let mut config: ConfigBuilder = format::deserialize(
indoc! {r#"
[sources.in]
type = "test_basic"
[sinks.out]
type = "test_basic"
inputs = ["in"]
"#},
Format::Toml,
)
.unwrap();
assert_eq!(
config.append(
format::deserialize(
indoc! {r#"
data_dir = "/foobar"
[proxy]
http = "http://proxy.inc:3128"
[transforms.foo]
type = "test_basic"
inputs = [ "in" ]
suffix = "foo"
increase = 1.25
[[tests]]
name = "check_simple_log"
[tests.input]
insert_at = "foo"
type = "raw"
value = "2019-11-28T12:00:00+00:00 info Sorry, I'm busy this week Cecil"
[[tests.outputs]]
extract_from = "foo"
[[tests.outputs.conditions]]
type = "vrl"
source = ".message == \"Sorry, I'm busy this week Cecil\""
"#},
Format::Toml,
)
.unwrap()
),
Ok(())
);
assert!(config.global.proxy.http.is_some());
assert!(config.global.proxy.https.is_none());
assert_eq!(Some(PathBuf::from("/foobar")), config.global.data_dir);
assert!(config.sources.contains_key(&ComponentKey::from("in")));
assert!(config.sinks.contains_key(&ComponentKey::from("out")));
assert!(config.transforms.contains_key(&ComponentKey::from("foo")));
assert_eq!(config.tests.len(), 1);
}
#[test]
fn config_append_collisions() {
let mut config: ConfigBuilder = format::deserialize(
indoc! {r#"
[sources.in]
type = "test_basic"
[sinks.out]
type = "test_basic"
inputs = ["in"]
"#},
Format::Toml,
)
.unwrap();
assert_eq!(
config.append(
format::deserialize(
indoc! {r#"
[sources.in]
type = "test_basic"
[transforms.foo]