Skip to content

Commit

Permalink
enhancement(sematext_metrics sink): Adhere to instrumentation spec (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
neuronull authored Sep 14, 2022
1 parent 5d1550a commit de83fb9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
16 changes: 13 additions & 3 deletions src/internal_events/sematext_metrics.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use metrics::counter;
use vector_core::internal_event::InternalEvent;

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

#[derive(Debug)]
Expand All @@ -11,8 +15,9 @@ pub struct SematextMetricsInvalidMetricError<'a> {

impl<'a> InternalEvent for SematextMetricsInvalidMetricError<'a> {
fn emit(self) {
let reason = "Invalid metric 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 @@ -28,6 +33,8 @@ impl<'a> InternalEvent for SematextMetricsInvalidMetricError<'a> {
);
// deprecated
counter!("processing_errors_total", 1);

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

Expand All @@ -38,8 +45,9 @@ pub struct SematextMetricsEncodeEventError<E> {

impl<E: std::fmt::Display> InternalEvent for SematextMetricsEncodeEventError<E> {
fn emit(self) {
let reason = "Failed to encode event.";
error!(
message = "Failed to encode event; dropping event.",
message = reason,
error = %self.error,
error_type = error_type::ENCODER_FAILED,
stage = error_stage::PROCESSING,
Expand All @@ -52,5 +60,7 @@ impl<E: std::fmt::Display> InternalEvent for SematextMetricsEncodeEventError<E>
);
// deprecated
counter!("encode_errors_total", 1);

emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason });
}
}
8 changes: 6 additions & 2 deletions src/sinks/sematext/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,10 @@ mod tests {
use crate::{
event::{metric::MetricKind, Event},
sinks::util::test::{build_test_server, load_sink},
test_util::{next_addr, test_generate_config, trace_init},
test_util::{
components::{assert_sink_compliance, HTTP_SINK_TAGS},
next_addr, test_generate_config,
},
};

#[test]
Expand Down Expand Up @@ -371,7 +374,7 @@ mod tests {

#[tokio::test]
async fn smoke() {
trace_init();
assert_sink_compliance(&HTTP_SINK_TAGS, async {

let (mut config, cx) = load_sink::<SematextMetricsConfig>(indoc! {r#"
region = "eu"
Expand Down Expand Up @@ -437,5 +440,6 @@ mod tests {
assert_eq!("jvm,metric_type=counter,os.host=somehost,token=atoken pool.used=18874368 1597784400000000006", output[6].1);
assert_eq!("jvm,metric_type=counter,os.host=somehost,token=atoken pool.committed=18868584 1597784400000000007", output[7].1);
assert_eq!("jvm,metric_type=counter,os.host=somehost,token=atoken pool.max=18874368 1597784400000000008", output[8].1);
}).await;
}
}

0 comments on commit de83fb9

Please sign in to comment.