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