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

Merged
merged 5 commits into from
Sep 12, 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/internal_events/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ use std::borrow::Cow;
use metrics::counter;
use vector_core::internal_event::InternalEvent;

use crate::{
emit,
internal_events::{ComponentEventsDropped, UNINTENTIONAL},
};
use vector_common::internal_event::{error_stage, error_type};

fn truncate_string_at(s: &str, maxlen: usize) -> Cow<str> {
Expand Down Expand Up @@ -51,8 +55,9 @@ pub struct ParserMissingFieldError<'a> {

impl InternalEvent for ParserMissingFieldError<'_> {
fn emit(self) {
let reason = "Field does not exist.";
error!(
message = "Field does not exist.",
message = reason,
field = %self.field,
error_code = "field_not_found",
error_type = error_type::CONDITION_FAILED,
Expand All @@ -68,6 +73,8 @@ impl InternalEvent for ParserMissingFieldError<'_> {
);
// deprecated
counter!("processing_errors_total", 1, "error_type" => "missing_field");

emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason });
}
}

Expand Down
15 changes: 11 additions & 4 deletions src/sinks/datadog/events/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ use std::{fmt, num::NonZeroUsize};
use async_trait::async_trait;
use futures::{stream::BoxStream, StreamExt};
use tower::Service;
use vector_config::NamedComponent;
use vector_core::stream::DriverResponse;

use crate::{
config::log_schema,
event::Event,
internal_events::ParserMissingFieldError,
internal_events::{ParserMissingFieldError, SinkRequestBuildError},
sinks::{
datadog::events::request_builder::{DatadogEventsRequest, DatadogEventsRequestBuilder},
datadog::events::{
request_builder::{DatadogEventsRequest, DatadogEventsRequestBuilder},
DatadogEventsConfig,
},
util::{SinkBuilderExt, StreamSink},
},
};
Expand All @@ -34,8 +38,11 @@ where
.request_builder(concurrency_limit, DatadogEventsRequestBuilder::new())
.filter_map(|request| async move {
match request {
Err(e) => {
error!("Failed to build DatadogEvents request: {:?}.", e);
Err(error) => {
emit!(SinkRequestBuildError {
name: DatadogEventsConfig::NAME,
error
});
None
}
Ok(req) => Some(req),
Expand Down
8 changes: 4 additions & 4 deletions src/sinks/datadog/events/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
event::EventArray,
sinks::util::test::{build_test_server_status, load_sink},
test_util::{
components::{self, HTTP_SINK_TAGS},
components::{self, COMPONENT_ERROR_TAGS, HTTP_SINK_TAGS},
next_addr, random_lines_with_stream,
},
};
Expand Down Expand Up @@ -63,10 +63,10 @@ async fn start_test(
let (batch, mut receiver) = BatchNotifier::new_with_receiver();
let (expected, events) = random_events_with_stream(100, 10, Some(batch));

components::init_test();
sink.run(events).await.unwrap();
if batch_status == BatchStatus::Delivered {
components::SINK_TESTS.assert(&HTTP_SINK_TAGS);
components::run_and_assert_sink_compliance(sink, events, &HTTP_SINK_TAGS).await;
} else {
components::run_and_assert_sink_error(sink, events, &COMPONENT_ERROR_TAGS).await;
}

assert_eq!(receiver.try_recv(), Ok(batch_status));
Expand Down