Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement(console sink): Add end-to-end acknowledgement support #13022

Merged
merged 3 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 8 additions & 1 deletion src/sinks/console/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,20 @@ pub struct ConsoleSinkConfig {
EncodingConfig<StandardEncodings>,
StandardEncodingsWithFramingMigrator,
>,
#[serde(
default,
deserialize_with = "crate::serde::bool_or_struct",
skip_serializing_if = "crate::serde::skip_serializing_if_default"
)]
pub acknowledgements: AcknowledgementsConfig,
}

impl GenerateConfig for ConsoleSinkConfig {
fn generate_config() -> toml::Value {
toml::Value::try_from(Self {
target: Target::Stdout,
encoding: EncodingConfig::from(StandardEncodings::Json).into(),
acknowledgements: Default::default(),
})
.unwrap()
}
Expand Down Expand Up @@ -97,7 +104,7 @@ impl SinkConfig for ConsoleSinkConfig {
}

fn acknowledgements(&self) -> Option<&AcknowledgementsConfig> {
None
Some(&self.acknowledgements)
}
}

Expand Down
44 changes: 26 additions & 18 deletions src/sinks/console/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use vector_core::{

use crate::{
codecs::Encoder,
event::Event,
event::{Event, EventStatus, Finalizable},
sinks::util::{encoding::Transformer, StreamSink},
};

Expand All @@ -33,28 +33,36 @@ where
let event_byte_size = event.size_of();
self.transformer.transform(&mut event);

let finalizers = event.take_finalizers();
let mut bytes = BytesMut::new();
self.encoder.encode(event, &mut bytes).map_err(|_| {
// Error is handled by `Encoder`.
finalizers.update_status(EventStatus::Errored);
})?;

self.output.write_all(&bytes).await.map_err(|error| {
// Error when writing to stdout/stderr is likely irrecoverable,
// so stop the sink.
error!(message = "Error writing to output. Stopping sink.", %error);
})?;

self.acker.ack(1);

emit!(EventsSent {
byte_size: event_byte_size,
count: 1,
output: None,
});
emit!(BytesSent {
byte_size: bytes.len(),
protocol: "console"
});
match self.output.write_all(&bytes).await {
Err(error) => {
// Error when writing to stdout/stderr is likely irrecoverable,
// so stop the sink.
error!(message = "Error writing to output. Stopping sink.", %error);
finalizers.update_status(EventStatus::Errored);
return Err(());
}
Ok(()) => {
finalizers.update_status(EventStatus::Delivered);
self.acker.ack(1);

emit!(EventsSent {
byte_size: event_byte_size,
count: 1,
output: None,
});
emit!(BytesSent {
byte_size: bytes.len(),
protocol: "console"
});
}
}
}

Ok(())
Expand Down
1 change: 1 addition & 0 deletions src/topology/test/doesnt_reload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ async fn topology_doesnt_reload_new_data_dir() {
ConsoleSinkConfig {
target: Target::Stdout,
encoding: EncodingConfig::from(StandardEncodings::Text).into(),
acknowledgements: Default::default(),
},
);
old_config.global.data_dir = Some(Path::new("/asdf").to_path_buf());
Expand Down
5 changes: 5 additions & 0 deletions src/topology/test/reload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ async fn topology_reuse_old_port() {
ConsoleSinkConfig {
target: Target::Stdout,
encoding: EncodingConfig::from(StandardEncodings::Text).into(),
acknowledgements: Default::default(),
},
);

Expand All @@ -50,6 +51,7 @@ async fn topology_reuse_old_port() {
ConsoleSinkConfig {
target: Target::Stdout,
encoding: EncodingConfig::from(StandardEncodings::Text).into(),
acknowledgements: Default::default(),
},
);

Expand All @@ -73,6 +75,7 @@ async fn topology_rebuild_old() {
ConsoleSinkConfig {
target: Target::Stdout,
encoding: EncodingConfig::from(StandardEncodings::Text).into(),
acknowledgements: Default::default(),
},
);

Expand All @@ -84,6 +87,7 @@ async fn topology_rebuild_old() {
ConsoleSinkConfig {
target: Target::Stdout,
encoding: EncodingConfig::from(StandardEncodings::Text).into(),
acknowledgements: Default::default(),
},
);

Expand All @@ -109,6 +113,7 @@ async fn topology_old() {
ConsoleSinkConfig {
target: Target::Stdout,
encoding: EncodingConfig::from(StandardEncodings::Text).into(),
acknowledgements: Default::default(),
},
);

Expand Down
1 change: 1 addition & 0 deletions src/topology/test/source_finished.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ async fn sources_finished() {
ConsoleSinkConfig {
target: Target::Stdout,
encoding: EncodingConfig::from(StandardEncodings::Text).into(),
acknowledgements: Default::default(),
},
);

Expand Down
2 changes: 1 addition & 1 deletion website/cue/reference/components/sinks/console.cue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ components: sinks: console: {
}

features: {
acknowledgements: false
acknowledgements: true
healthcheck: enabled: false
send: {
compression: enabled: false
Expand Down