Skip to content

Commit

Permalink
fix annotation suppression failed when log_namespace is enabled in ku…
Browse files Browse the repository at this point in the history
…bernetes_logs.

Signed-off-by: ifuryst <[email protected]>
  • Loading branch information
iFurySt committed Aug 11, 2024
1 parent 7be4be6 commit c168bd7
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 5 deletions.
3 changes: 3 additions & 0 deletions changelog.d/20682_consistent_annotation_suppression.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixes an issue where annotation suppression failed when `log_namespace` was set to `true` in kubernetes_logs.

authors: ifuryst
13 changes: 8 additions & 5 deletions lib/vector-core/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,14 @@ impl LogNamespace {
value: impl Into<Value>,
) {
match self {
LogNamespace::Vector => {
log.metadata_mut()
.value_mut()
.insert(path!(source_name).concat(metadata_key), value);
}
LogNamespace::Vector => match legacy_key {
None => { /* don't insert */ }
_ => {
log.metadata_mut()
.value_mut()
.insert(path!(source_name).concat(metadata_key), value);
}
},
LogNamespace::Legacy => match legacy_key {
None => { /* don't insert */ }
Some(LegacyKey::Overwrite(key)) => {
Expand Down
58 changes: 58 additions & 0 deletions src/sources/kubernetes_logs/pod_metadata_annotator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,64 @@ mod tests {
}
}

#[test]
fn test_suppress_annotation_fields() {
let cases = vec![
(
FieldsSpec {
container_id: OptionalTargetPath::none(),
..FieldsSpec::default()
},
ContainerStatus {
container_id: Some("container_id_foo".to_owned()),
image_id: "test_image_id".to_owned(),
..ContainerStatus::default()
},
{
let mut log = LogEvent::default();
log.insert(
event_path!("kubernetes", "container_image_id"),
"test_image_id",
);
log
},
LogNamespace::Legacy,
),
(
FieldsSpec {
container_id: OptionalTargetPath::none(),
..FieldsSpec::default()
},
ContainerStatus {
container_id: Some("container_id_foo".to_owned()),
image_id: "test_image_id".to_owned(),
..ContainerStatus::default()
},
{
let mut log = LogEvent::default();
log.insert(
metadata_path!("kubernetes_logs", "container_image_id"),
"test_image_id",
);
log
},
LogNamespace::Vector,
),
];
for (fields_spec, container_status, expected, log_namespace) in cases.into_iter() {
let mut log = LogEvent::default();
annotate_from_container_status(
&mut log,
&fields_spec,
&container_status,
log_namespace,
);
println!("{:?}", log);

Check failure on line 1045 in src/sources/kubernetes_logs/pod_metadata_annotator.rs

View workflow job for this annotation

GitHub Actions / Checks

use of `println!`
println!("{:?}", expected);

Check failure on line 1046 in src/sources/kubernetes_logs/pod_metadata_annotator.rs

View workflow job for this annotation

GitHub Actions / Checks

use of `println!`
assert_eq!(log, expected);
}
}

#[test]
fn test_annotate_from_container() {
let cases = vec![
Expand Down

0 comments on commit c168bd7

Please sign in to comment.