Skip to content

Commit

Permalink
chore(core): Add helper function to add a semantic meaning to an even…
Browse files Browse the repository at this point in the history
…t metadata (#20439)
  • Loading branch information
bruceg committed Jul 19, 2024
1 parent fd35e1c commit cae6a88
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions lib/vector-core/src/event/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use std::{borrow::Cow, collections::BTreeMap, fmt, sync::Arc};

use lookup::OwnedTargetPath;
use serde::{Deserialize, Serialize};
use vector_common::{byte_size_of::ByteSizeOf, config::ComponentKey, EventDataEq};
use vrl::{
Expand Down Expand Up @@ -345,6 +346,26 @@ impl EventMetadata {
pub fn set_schema_definition(&mut self, definition: &Arc<schema::Definition>) {
self.schema_definition = Arc::clone(definition);
}

/// Helper function to add a semantic meaning to the schema definition.
///
/// This replaces the common code sequence of:
///
/// ```
/// let new_schema = log_event

Check failure on line 355 in lib/vector-core/src/event/metadata.rs

View workflow job for this annotation

GitHub Actions / test-misc / test-misc

cannot find value `log_event` in this scope
/// .metadata()
/// .schema_definition()
/// .as_ref()
/// .clone()
/// .with_meaning(target_path, meaning);

Check failure on line 360 in lib/vector-core/src/event/metadata.rs

View workflow job for this annotation

GitHub Actions / test-misc / test-misc

cannot find value `target_path` in this scope

Check failure on line 360 in lib/vector-core/src/event/metadata.rs

View workflow job for this annotation

GitHub Actions / test-misc / test-misc

cannot find value `meaning` in this scope
/// log_event

Check failure on line 361 in lib/vector-core/src/event/metadata.rs

View workflow job for this annotation

GitHub Actions / test-misc / test-misc

cannot find value `log_event` in this scope
/// .metadata_mut()
/// .set_schema_definition(new_schema);
/// ````
pub fn add_schema_meaning(&mut self, target_path: OwnedTargetPath, meaning: &str) {
let schema = Arc::make_mut(&mut self.schema_definition);
schema.add_meaning(target_path, meaning);
}
}

impl EventDataEq for EventMetadata {
Expand Down
2 changes: 1 addition & 1 deletion lib/vector-core/src/schema/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ impl Definition {
/// # Panics
///
/// This method panics if the provided path points to an unknown location in the collection.
fn add_meaning(&mut self, target_path: OwnedTargetPath, meaning: &str) {
pub fn add_meaning(&mut self, target_path: OwnedTargetPath, meaning: &str) {
self.try_with_meaning(target_path, meaning)
.unwrap_or_else(|err| panic!("{}", err));
}
Expand Down

0 comments on commit cae6a88

Please sign in to comment.