vector/internal_events/
prometheus.rs1#![allow(dead_code)] #[cfg(feature = "sources-prometheus-scrape")]
4use std::borrow::Cow;
5
6#[cfg(feature = "sources-prometheus-scrape")]
7use vector_lib::prometheus::parser::ParserError;
8use vector_lib::{
9 NamedInternalEvent, counter,
10 internal_event::{
11 ComponentEventsDropped, CounterName, InternalEvent, UNINTENTIONAL, error_stage, error_type,
12 },
13};
14
15#[cfg(feature = "sources-prometheus-scrape")]
16#[derive(Debug, NamedInternalEvent)]
17pub struct PrometheusParseError<'a> {
18 pub error: ParserError,
19 pub url: http::Uri,
20 pub body: Cow<'a, str>,
21}
22
23#[cfg(feature = "sources-prometheus-scrape")]
24impl InternalEvent for PrometheusParseError<'_> {
25 fn emit(self) {
26 error!(
27 message = "Parsing error.",
28 url = %self.url,
29 error = ?self.error,
30 error_type = error_type::PARSER_FAILED,
31 stage = error_stage::PROCESSING,
32 );
33 debug!(
34 message = %format!("Failed to parse response:\n\n{}\n\n", self.body),
35 url = %self.url
36 );
37 counter!(
38 CounterName::ComponentErrorsTotal,
39 "error_type" => error_type::PARSER_FAILED,
40 "stage" => error_stage::PROCESSING,
41 "url" => self.url.to_string(),
42 )
43 .increment(1);
44 }
45}
46
47#[derive(Debug, NamedInternalEvent)]
48pub struct PrometheusRemoteWriteParseError {
49 pub error: prost::DecodeError,
50}
51
52impl InternalEvent for PrometheusRemoteWriteParseError {
53 fn emit(self) {
54 error!(
55 message = "Could not decode request body.",
56 error = ?self.error,
57 error_type = error_type::PARSER_FAILED,
58 stage = error_stage::PROCESSING,
59 );
60 counter!(
61 CounterName::ComponentErrorsTotal,
62 "error_type" => error_type::PARSER_FAILED,
63 "stage" => error_stage::PROCESSING,
64 )
65 .increment(1);
66 }
67}
68
69#[derive(Debug, NamedInternalEvent)]
70pub struct PrometheusNormalizationError;
71
72impl InternalEvent for PrometheusNormalizationError {
73 fn emit(self) {
74 let normalization_reason = "Prometheus metric normalization failed.";
75 error!(
76 message = normalization_reason,
77 error_type = error_type::CONVERSION_FAILED,
78 stage = error_stage::PROCESSING,
79 );
80 counter!(
81 CounterName::ComponentErrorsTotal,
82 "error_type" => error_type::CONVERSION_FAILED,
83 "stage" => error_stage::PROCESSING,
84 )
85 .increment(1);
86 emit!(ComponentEventsDropped::<UNINTENTIONAL> {
87 count: 1,
88 reason: normalization_reason
89 });
90 }
91}