Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sources): annotation suppression failed when log_namespace is enabled in kubernetes_logs #21045

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
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 @@
}
}

#[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
Loading