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