vector/internal_events/
aws_ecs_metrics.rs

1use std::borrow::Cow;
2
3use metrics::counter;
4use vector_lib::{
5    NamedInternalEvent,
6    internal_event::{InternalEvent, error_stage, error_type},
7    json_size::JsonSize,
8};
9
10#[derive(Debug, NamedInternalEvent)]
11pub struct AwsEcsMetricsEventsReceived<'a> {
12    pub byte_size: JsonSize,
13    pub count: usize,
14    pub endpoint: &'a str,
15}
16
17impl InternalEvent for AwsEcsMetricsEventsReceived<'_> {
18    fn emit(self) {
19        trace!(
20            message = "Events received.",
21            count = %self.count,
22            byte_size = %self.byte_size,
23            protocol = "http",
24            endpoint = %self.endpoint,
25        );
26        counter!(
27            "component_received_events_total",
28            "endpoint" => self.endpoint.to_string(),
29        )
30        .increment(self.count as u64);
31        counter!(
32            "component_received_event_bytes_total",
33            "endpoint" => self.endpoint.to_string(),
34        )
35        .increment(self.byte_size.get() as u64);
36    }
37}
38
39#[derive(Debug, NamedInternalEvent)]
40pub struct AwsEcsMetricsParseError<'a> {
41    pub error: serde_json::Error,
42    pub endpoint: &'a str,
43    pub body: Cow<'a, str>,
44}
45
46impl InternalEvent for AwsEcsMetricsParseError<'_> {
47    fn emit(self) {
48        error!(
49            message = "Parsing error.",
50            endpoint = %self.endpoint,
51            error = ?self.error,
52            stage = error_stage::PROCESSING,
53            error_type = error_type::PARSER_FAILED,
54        );
55        debug!(
56            response = %self.body.escape_debug(),
57            endpoint = %self.endpoint,
58            "Failed to parse response.",
59        );
60        counter!("parse_errors_total").increment(1);
61        counter!(
62            "component_errors_total",
63            "stage" => error_stage::PROCESSING,
64            "error_type" => error_type::PARSER_FAILED,
65            "endpoint" => self.endpoint.to_string(),
66        )
67        .increment(1);
68    }
69}