Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
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
2 changes: 1 addition & 1 deletion lib/vector-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ rand = "0.8.5"
rand_distr = "0.4.3"
tracing-subscriber = { version = "0.3.17", default-features = false, features = ["env-filter", "fmt", "ansi", "registry"] }
vector-common = { path = "../vector-common", default-features = false, features = ["test"] }
vrl = { version = "0.4.0", default-features = false, features = ["value", "arbitrary", "lua"] }
vrl = { version = "0.4.0", default-features = false, features = ["value", "arbitrary", "lua", "test"] }

[features]
api = ["dep:async-graphql"]
Expand Down
19 changes: 7 additions & 12 deletions lib/vector-core/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,7 @@ impl SourceOutput {
} else {
let mut new_definition =
schema::Definition::default_for_namespace(definition.log_namespaces());

if definition.log_namespaces().contains(&LogNamespace::Vector) {
new_definition.add_meanings(definition.meanings());
}

new_definition.add_meanings(definition.meanings());
new_definition
}
})
Expand All @@ -201,7 +197,7 @@ pub struct TransformOutput {
/// enabled, at least one definition should be output. If the transform
/// has multiple connected sources, it is possible to have multiple output
/// definitions - one for each input.
log_schema_definitions: HashMap<OutputId, schema::Definition>,
pub log_schema_definitions: HashMap<OutputId, schema::Definition>,
}

impl TransformOutput {
Expand Down Expand Up @@ -243,11 +239,7 @@ impl TransformOutput {
.map(|(output, definition)| {
let mut new_definition =
schema::Definition::default_for_namespace(definition.log_namespaces());

if definition.log_namespaces().contains(&LogNamespace::Vector) {
new_definition.add_meanings(definition.meanings());
}

new_definition.add_meanings(definition.meanings());
(output.clone(), new_definition)
})
.collect()
Expand Down Expand Up @@ -604,7 +596,10 @@ mod test {

// There should be the default legacy definition without schemas enabled.
assert_eq!(
Some(schema::Definition::default_legacy_namespace()),
Some(
schema::Definition::default_legacy_namespace()
.with_meaning(OwnedTargetPath::event(owned_value_path!("zork")), "zork")
),
output.schema_definition(false)
);
}
Expand Down
22 changes: 21 additions & 1 deletion lib/vector-core/src/event/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@ pub struct EventMetadata {
/// The id of the source
source_id: Option<Arc<OutputId>>,

/// The id of the component this event originated from. This is used to
/// determine which schema definition to attach to an event in transforms.
/// This should always have a value set for events in transforms. It will always be `None`
/// in a source, and there is currently no use-case for reading the value in a sink.
upstream_id: Option<Arc<OutputId>>,

/// An identifier for a globally registered schema definition which provides information about
/// the event shape (type information, and semantic meaning of fields).
/// This definition is only currently valid for logs, and shouldn't be used for other event types.
///
/// TODO(Jean): must not skip serialization to track schemas across restarts.
#[serde(default = "default_schema_definition", skip)]
Expand Down Expand Up @@ -73,17 +80,29 @@ impl EventMetadata {
&mut self.secrets
}

/// Returns a reference to the metadata source.
/// Returns a reference to the metadata source id.
#[must_use]
pub fn source_id(&self) -> Option<&OutputId> {
self.source_id.as_deref()
}

/// Returns a reference to the metadata parent id. This is the `OutputId`
/// of the previous component the event was sent through (if any).
#[must_use]
pub fn upstream_id(&self) -> Option<&OutputId> {
self.upstream_id.as_deref()
}

/// Sets the `source_id` in the metadata to the provided value.
pub fn set_source_id(&mut self, source_id: Arc<OutputId>) {
self.source_id = Some(source_id);
}

/// Sets the `upstream_id` in the metadata to the provided value.
pub fn set_upstream_id(&mut self, upstream_id: Arc<OutputId>) {
self.upstream_id = Some(upstream_id);
}

/// Return the datadog API key, if it exists
pub fn datadog_api_key(&self) -> Option<Arc<str>> {
self.secrets.get(DATADOG_API_KEY).cloned()
Expand Down Expand Up @@ -113,6 +132,7 @@ impl Default for EventMetadata {
finalizers: Default::default(),
schema_definition: default_schema_definition(),
source_id: None,
upstream_id: None,
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions lib/vector-core/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,24 @@ impl Event {
self.metadata_mut().set_source_id(source_id);
}

/// Sets the `upstream_id` in the event metadata to the provided value.
pub fn set_upstream_id(&mut self, upstream_id: Arc<OutputId>) {
self.metadata_mut().set_upstream_id(upstream_id);
}

/// Sets the `source_id` in the event metadata to the provided value.
#[must_use]
pub fn with_source_id(mut self, source_id: Arc<OutputId>) -> Self {
self.metadata_mut().set_source_id(source_id);
self
}

/// Sets the `upstream_id` in the event metadata to the provided value.
#[must_use]
pub fn with_upstream_id(mut self, upstream_id: Arc<OutputId>) -> Self {
self.metadata_mut().set_upstream_id(upstream_id);
self
}
}

impl EventDataEq for Event {
Expand Down
Loading