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 );
31 debug!(
32 message = %format!("Failed to parse response:\n\n{}\n\n", self.body),
33 url = %self.url
34 );
35 counter!(
36 "component_errors_total",
37 "error_type" => error_type::PARSER_FAILED,
38 "stage" => error_stage::PROCESSING,
39 "url" => self.url.to_string(),
40 )
41 .increment(1);
42 }
43}
44
45#[derive(Debug)]
46pub struct PrometheusRemoteWriteParseError {
47 pub error: prost::DecodeError,
48}
49
50impl InternalEvent for PrometheusRemoteWriteParseError {
51 fn emit(self) {
52 error!(
53 message = "Could not decode request body.",
54 error = ?self.error,
55 error_type = error_type::PARSER_FAILED,
56 stage = error_stage::PROCESSING,
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 );
78 counter!(
79 "component_errors_total",
80 "error_type" => error_type::CONVERSION_FAILED,
81 "stage" => error_stage::PROCESSING,
82 )
83 .increment(1);
84 emit!(ComponentEventsDropped::<UNINTENTIONAL> {
85 count: 1,
86 reason: normalization_reason
87 });
88 }
89}