|
1 | 1 | use vector_config::configurable_component;
|
2 |
| -use vector_core::config::LogNamespace; |
3 |
| -use vrl::event_path; |
| 2 | +use vector_core::config::{LegacyKey, LogNamespace}; |
| 3 | +use vrl::value::Kind; |
| 4 | +use vrl::{event_path, owned_value_path}; |
4 | 5 |
|
5 | 6 | use crate::{
|
6 | 7 | conditions::{AnyCondition, Condition},
|
@@ -85,7 +86,18 @@ impl TransformConfig for SampleConfig {
|
85 | 86 | DataType::Log | DataType::Trace,
|
86 | 87 | input_definitions
|
87 | 88 | .iter()
|
88 |
| - .map(|(output, definition)| (output.clone(), definition.clone())) |
| 89 | + .map(|(output, definition)| { |
| 90 | + ( |
| 91 | + output.clone(), |
| 92 | + definition.clone().with_source_metadata( |
| 93 | + SampleConfig::NAME, |
| 94 | + Some(LegacyKey::Overwrite(owned_value_path!("sample_rate"))), |
| 95 | + &owned_value_path!("sample_rate"), |
| 96 | + Kind::bytes(), |
| 97 | + None, |
| 98 | + ), |
| 99 | + ) |
| 100 | + }) |
89 | 101 | .collect(),
|
90 | 102 | )]
|
91 | 103 | }
|
@@ -153,10 +165,16 @@ impl FunctionTransform for Sample {
|
153 | 165 | if num % self.rate == 0 {
|
154 | 166 | match event {
|
155 | 167 | Event::Log(ref mut event) => {
|
156 |
| - event.insert(event_path!("sample_rate"), self.rate.to_string()) |
| 168 | + event.namespace().insert_source_metadata( |
| 169 | + SampleConfig::NAME, |
| 170 | + event, |
| 171 | + Some(LegacyKey::Overwrite(vrl::path!("sample_rate"))), |
| 172 | + vrl::path!("sample_rate"), |
| 173 | + self.rate.to_string(), |
| 174 | + ); |
157 | 175 | }
|
158 | 176 | Event::Trace(ref mut event) => {
|
159 |
| - event.insert(event_path!("sample_rate"), self.rate.to_string()) |
| 177 | + event.insert(event_path!("sample_rate"), self.rate.to_string()); |
160 | 178 | }
|
161 | 179 | Event::Metric(_) => panic!("component can never receive metric events"),
|
162 | 180 | };
|
|
0 commit comments