Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
5e630b3
feat(config): prepare sinks before topology build
thomasqueirozb Aug 3, 2026
7408b41
refactor(config): centralize Any erasure in PreparedSink API
thomasqueirozb Aug 4, 2026
e873e27
refactor(clickhouse sink): fold prepared state into config module
thomasqueirozb Aug 4, 2026
5e1095a
Stub out build in SinkConfig, move code inside impl trait blocks
thomasqueirozb Aug 5, 2026
180af14
Move healthcheck_uri fn def
thomasqueirozb Aug 5, 2026
26436e8
refactor(config): fold prepared sink state into SinkOuter
thomasqueirozb Aug 5, 2026
69035af
refactor(config): rename prepared lifecycle to validated
thomasqueirozb Aug 5, 2026
9337f45
refactor(clickhouse sink): drop redundant config from ValidatedClickh…
thomasqueirozb Aug 5, 2026
eae6030
Revert pub(super) changes
thomasqueirozb Aug 5, 2026
343ede5
refactor(clickhouse sink): drop purity annotations from validate_stru…
thomasqueirozb Aug 5, 2026
1c381fe
Revert code change to track master
thomasqueirozb Aug 5, 2026
29f9e3f
build_validated -> build
thomasqueirozb Aug 5, 2026
e6e43c2
validate_structure -> validate
thomasqueirozb Aug 5, 2026
ea1e457
*_structure_erased -> *_erased
thomasqueirozb Aug 5, 2026
d30cfd0
Remove _erased from method names
thomasqueirozb Aug 5, 2026
0ff1f91
Revert "Remove _erased from method names"
thomasqueirozb Aug 5, 2026
7cd72ca
fix(clickhouse sink): reject dynamic ArrowStream targets during valid…
thomasqueirozb Aug 5, 2026
15bde0b
refactor(sinks): rename erased validated boundary to dyn
thomasqueirozb Aug 5, 2026
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
53 changes: 50 additions & 3 deletions src/config/compiler.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use indexmap::{IndexMap, IndexSet};
use std::sync::Arc;
use vector_lib::config::ComponentKey;
use vector_lib::id::Inputs;

use super::{
Config, OutputId, builder::ConfigBuilder, graph::Graph, transform::get_transform_output_ids,
validation,
Config, OutputId, builder::ConfigBuilder, graph::Graph, sink::SinkOuter,
transform::get_transform_output_ids, validation,
};

pub fn compile(mut builder: ConfigBuilder) -> Result<(Config, Vec<String>), Vec<String>> {
Expand Down Expand Up @@ -99,7 +101,7 @@ pub fn compile(mut builder: ConfigBuilder) -> Result<(Config, Vec<String>), Vec<

// Inputs are resolved from string into OutputIds as part of graph construction, so update them
// here before adding to the final config (the types require this).
let sinks = sinks
let sinks: IndexMap<ComponentKey, SinkOuter<OutputId>> = sinks
.into_iter()
.map(|(key, sink)| {
let inputs = graph.inputs_for(&key);
Expand Down Expand Up @@ -141,6 +143,16 @@ pub fn compile(mut builder: ConfigBuilder) -> Result<(Config, Vec<String>), Vec<
graceful_shutdown_duration,
};

// Validate sinks in place
let validate_errors = validate_sinks(&mut config);
if !validate_errors.is_empty() {
errors.extend(validate_errors);
}

if !errors.is_empty() {
return Err(errors);
}

config.propagate_acknowledgements()?;

let warnings = validation::warnings(&config);
Expand Down Expand Up @@ -180,6 +192,41 @@ pub(crate) fn expand_globs(config: &mut ConfigBuilder) {
}
}

/// Validate all sinks (direct and enrichment-table-derived) in place.
///
/// Fills the `validated` field on each sink's `SinkOuter` (and on enrichment tables that
/// double as sinks) with the erased validated state. Returns a list of errors for sinks
/// that failed validation. An empty Vec means success.
fn validate_sinks(config: &mut Config) -> Vec<String> {
let mut errors = Vec::new();

// Validate direct sinks
for (key, sink) in config.sinks.iter_mut() {
if let Some(dyn_sink) = sink.inner.as_dyn_validated() {
match dyn_sink.validate_dyn() {
Ok(state) => sink.validated = Some(Arc::from(state)),
Err(e) => errors.push(format!("Failed to validate sink \"{}\": {}", key, e)),
}
}
}

// Validate enrichment table sinks with resolved inputs.
for (key, table) in config.enrichment_tables.iter_mut() {
if let Some((_, sink)) = table.as_sink(key)
&& let Some(dyn_sink) = sink.inner.as_dyn_validated()
{
match dyn_sink.validate_dyn() {
Ok(state) => table.validated = Some(Arc::from(state)),
Err(error) => errors.push(format!(
"Failed to validate enrichment table sink \"{key}\": {error}"
)),
}
}
}

errors
}

enum InputMatcher {
Pattern(glob::Pattern),
String(String),
Expand Down
20 changes: 19 additions & 1 deletion src/config/enrichment_table.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#![allow(clippy::let_underscore_must_use)]

use std::{any::Any, sync::Arc};

use derivative::Derivative;
use enum_dispatch::enum_dispatch;
use serde::Serialize;
use vector_lib::{
Expand All @@ -11,7 +16,8 @@ use crate::enrichment_tables::EnrichmentTables;

/// Fully resolved enrichment table component.
#[configurable_component]
#[derive(Clone, Debug)]
#[derive(Clone, Derivative)]
#[derivative(Debug)]
pub struct EnrichmentTableOuter<T>
where
T: Configurable + Serialize + 'static + ToValue + Clone,
Expand All @@ -27,6 +33,15 @@ where
skip_serializing_if = "Inputs::is_empty"
)]
pub inputs: Inputs<T>,

/// Validated sink state, filled in during config compilation.
///
/// Mirrors `SinkOuter::validated` for enrichment tables that double as sinks. It is
/// never serialized or diffed, and is shared (via `Arc`) so `as_sink` can hand it to
/// the derived `SinkOuter` without cloning the underlying value.
#[serde(skip)]
#[derivative(Debug = "ignore")]
pub(crate) validated: Option<Arc<dyn Any + Send + Sync>>,
}

impl<T> EnrichmentTableOuter<T>
Expand All @@ -42,6 +57,7 @@ where
inner: inner.into(),
graph: Default::default(),
inputs: Inputs::from_iter(inputs),
validated: None,
}
}

Expand Down Expand Up @@ -69,6 +85,7 @@ where
buffer: Default::default(),
proxy: Default::default(),
inner: sink,
validated: self.validated.clone(),
},
)
})
Expand Down Expand Up @@ -105,6 +122,7 @@ where
inputs: Inputs::from_iter(inputs),
inner: self.inner,
graph: self.graph,
validated: self.validated,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub mod provider;
pub mod schema;
mod secret;
mod sink;
mod sink_validated;
mod source;
mod transform;
pub mod unit_test;
Expand All @@ -61,6 +62,7 @@ pub use loading::{
pub use provider::ProviderConfig;
pub use secret::SecretBackend;
pub use sink::{BoxedSink, SinkConfig, SinkContext, SinkHealthcheckOptions, SinkOuter};
pub use sink_validated::{DynValidatedSink, ValidatedSink};
pub use source::{BoxedSource, SourceConfig, SourceContext, SourceOuter};
pub use transform::{
BoxedTransform, TransformConfig, TransformContext, TransformOuter, get_transform_output_ids,
Expand Down
63 changes: 57 additions & 6 deletions src/config/sink.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::{cell::RefCell, path::PathBuf, time::Duration};
#![allow(clippy::let_underscore_must_use)]

use std::{any::Any, cell::RefCell, path::PathBuf, sync::Arc, time::Duration};

use async_trait::async_trait;
use derivative::Derivative;
use dyn_clone::DynClone;
use serde::Serialize;
use serde_with::serde_as;
Expand All @@ -18,7 +21,9 @@ use vector_lib::{
};
use vector_vrl_metrics::MetricsStorage;

use super::{ComponentKey, ProxyConfig, Resource, dot_graph::GraphConfig, schema};
use super::{
ComponentKey, DynValidatedSink, ProxyConfig, Resource, dot_graph::GraphConfig, schema,
};
use crate::{
extra_context::ExtraContext,
sinks::{Healthcheck, util::UriSerde},
Expand Down Expand Up @@ -55,7 +60,8 @@ impl<T: SinkConfig + 'static> From<T> for BoxedSink {
/// Fully resolved sink component.
#[configurable_component]
#[configurable(metadata(docs::component_base_type = "sink"))]
#[derive(Clone, Debug)]
#[derive(Clone, Derivative)]
#[derivative(Debug)]
pub struct SinkOuter<T>
where
T: Configurable + Serialize + 'static,
Expand Down Expand Up @@ -89,12 +95,36 @@ where
#[serde(flatten)]
#[configurable(metadata(docs::hidden))]
pub inner: BoxedSink,

/// Validated state, filled in during config compilation.
///
/// This is the erased state produced by `ValidatedSink::validate`, retained so
/// the topology builder can build the sink without re-validating. It is never serialized
/// or diffed (see `#[serde(skip)]`), and is shared (via `Arc`) so enrichment-table-derived
/// sinks can carry it without cloning the underlying value.
#[serde(skip)]
#[derivative(Debug = "ignore")]
pub(crate) validated: Option<Arc<dyn Any + Send + Sync>>,
}

impl<T> SinkOuter<T>
where
T: Configurable + Serialize,
{
/// Builds the sink, dispatching through the erased validated boundary when the sink
/// has been migrated, or falling back to the raw config for legacy sinks.
pub async fn build(&self, cx: SinkContext) -> crate::Result<(VectorSink, Healthcheck)> {
match self.inner.as_dyn_validated() {
Some(p) => {
let validated = self
.validated
.as_ref()
.expect("validated state missing for migrated sink");
p.build_dyn(validated.as_ref(), cx).await
}
None => self.inner.build(cx).await,
}
}
pub fn new<I, IS>(inputs: I, inner: IS) -> SinkOuter<T>
where
I: IntoIterator<Item = T>,
Expand All @@ -108,6 +138,7 @@ where
inner: inner.into(),
proxy: Default::default(),
graph: Default::default(),
validated: None,
}
}

Expand Down Expand Up @@ -167,6 +198,7 @@ where
healthcheck_uri: self.healthcheck_uri,
proxy: self.proxy,
graph: self.graph,
validated: self.validated,
}
}
}
Expand Down Expand Up @@ -238,14 +270,23 @@ impl From<UriSerde> for SinkHealthcheckOptions {
pub trait SinkConfig: DynClone + NamedComponent + core::fmt::Debug + Send + Sync {
/// Builds the sink with the given context.
///
/// If the sink is built successfully, `Ok(...)` is returned containing the sink and the sink's
/// healthcheck.
/// Migrated sinks route through the validated lifecycle: this default validates
/// the structure and builds from the retained state. Legacy sinks override this
/// with their own build logic.
///
/// # Errors
///
/// If an error occurs while building the sink, an error variant explaining the issue is
/// returned.
async fn build(&self, cx: SinkContext) -> crate::Result<(VectorSink, Healthcheck)>;
async fn build(&self, cx: SinkContext) -> crate::Result<(VectorSink, Healthcheck)> {
match self.as_dyn_validated() {
Some(dyn_sink) => {
let validated = dyn_sink.validate_dyn()?;
dyn_sink.build_dyn(&*validated, cx).await
}
None => Err("sink does not implement a build method".into()),
}
}

/// Gets the input configuration for this sink.
fn input(&self) -> Input;
Expand Down Expand Up @@ -277,6 +318,16 @@ pub trait SinkConfig: DynClone + NamedComponent + core::fmt::Debug + Send + Sync

/// Gets the acknowledgements configuration for this sink.
fn acknowledgements(&self) -> &AcknowledgementsConfig;

/// Returns this sink as a `DynValidatedSink` if it has been migrated to the
/// validated lifecycle, or `None` for legacy sinks.
///
/// Migrated sinks implement `ValidatedSink` (working with their concrete validated
/// type) and override this to return `Some(self)`. The framework then routes
/// validation and building through the dynamic boundary automatically.
fn as_dyn_validated(&self) -> Option<&dyn DynValidatedSink> {
None
}
}

dyn_clone::clone_trait_object!(SinkConfig);
Expand Down
Loading
Loading