Skip to content

Commit

Permalink
fix(sample transform): Use metadata when log namespacing is enabled (#…
Browse files Browse the repository at this point in the history
…18259)

fix sample transform when using log namespacing
  • Loading branch information
fuchsnj authored Aug 16, 2023
1 parent fc17fba commit 69b4c1c
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/transforms/sample.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use vector_config::configurable_component;
use vector_core::config::LogNamespace;
use vrl::event_path;
use vector_core::config::{LegacyKey, LogNamespace};
use vrl::value::Kind;
use vrl::{event_path, owned_value_path};

use crate::{
conditions::{AnyCondition, Condition},
Expand Down Expand Up @@ -85,7 +86,18 @@ impl TransformConfig for SampleConfig {
DataType::Log | DataType::Trace,
input_definitions
.iter()
.map(|(output, definition)| (output.clone(), definition.clone()))
.map(|(output, definition)| {
(
output.clone(),
definition.clone().with_source_metadata(
SampleConfig::NAME,
Some(LegacyKey::Overwrite(owned_value_path!("sample_rate"))),
&owned_value_path!("sample_rate"),
Kind::bytes(),
None,
),
)
})
.collect(),
)]
}
Expand Down Expand Up @@ -153,10 +165,16 @@ impl FunctionTransform for Sample {
if num % self.rate == 0 {
match event {
Event::Log(ref mut event) => {
event.insert(event_path!("sample_rate"), self.rate.to_string())
event.namespace().insert_source_metadata(
SampleConfig::NAME,
event,
Some(LegacyKey::Overwrite(vrl::path!("sample_rate"))),
vrl::path!("sample_rate"),
self.rate.to_string(),
);
}
Event::Trace(ref mut event) => {
event.insert(event_path!("sample_rate"), self.rate.to_string())
event.insert(event_path!("sample_rate"), self.rate.to_string());
}
Event::Metric(_) => panic!("component can never receive metric events"),
};
Expand Down

0 comments on commit 69b4c1c

Please sign in to comment.