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(statsd sink): Adhere to instrumentation spec #14434

Merged
merged 3 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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/internal_events/statsd_sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ use metrics::counter;
use vector_core::internal_event::InternalEvent;

use crate::event::metric::{MetricKind, MetricValue};
use crate::{
emit,
internal_events::{ComponentEventsDropped, UNINTENTIONAL},
};
use vector_common::internal_event::{error_stage, error_type};

#[derive(Debug)]
Expand All @@ -12,8 +16,9 @@ pub struct StatsdInvalidMetricError<'a> {

impl<'a> InternalEvent for StatsdInvalidMetricError<'a> {
fn emit(self) {
let reason = "Invalid metric type received.";
error!(
message = "Invalid metric received; dropping event.",
message = reason,
error_code = "invalid_metric",
error_type = error_type::ENCODER_FAILED,
stage = error_stage::PROCESSING,
Expand All @@ -29,5 +34,7 @@ impl<'a> InternalEvent for StatsdInvalidMetricError<'a> {
);
// deprecated
counter!("processing_errors_total", 1);

emit!(ComponentEventsDropped::<UNINTENTIONAL> { reason, count: 1 });
}
}
4 changes: 4 additions & 0 deletions src/sinks/statsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ impl SinkConfig for StatsdSinkConfig {
stream::iter({
let byte_size = event.size_of();
let mut bytes = BytesMut::new();

// Errors are handled by `Encoder`.
encoder
.encode(event, &mut bytes)
.map(|_| Ok(EncodedEvent::new(bytes, byte_size)))
Expand Down Expand Up @@ -282,10 +284,12 @@ impl Service<BytesMut> for StatsdSvc {
type Error = crate::Error;
type Future = future::BoxFuture<'static, Result<(), Self::Error>>;

// Emission of Error internal event is handled upstream by the caller
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.inner.poll_ready(cx).map_err(Into::into)
}

// Emission of Error internal event is handled upstream by the caller
neuronull marked this conversation as resolved.
Show resolved Hide resolved
fn call(&mut self, frame: BytesMut) -> Self::Future {
self.inner.call(frame).err_into().boxed()
}
Expand Down
2 changes: 2 additions & 0 deletions src/sinks/util/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ impl tower::Service<BytesMut> for UdpService {
type Error = UdpError;
type Future = BoxFuture<'static, Result<(), Self::Error>>;

// Emission of Error internal event is handled upstream by the caller
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
loop {
self.state = match &mut self.state {
Expand All @@ -223,6 +224,7 @@ impl tower::Service<BytesMut> for UdpService {
Poll::Ready(Ok(()))
}

// Emission of Error internal event is handled upstream by the caller
fn call(&mut self, msg: BytesMut) -> Self::Future {
let (sender, receiver) = oneshot::channel();
let byte_size = msg.len();
Expand Down