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