vector/internal_events/
http_client_source.rs

1use metrics::counter;
2use vector_lib::internal_event::InternalEvent;
3use vector_lib::{
4    internal_event::{error_stage, error_type},
5    json_size::JsonSize,
6};
7
8use super::prelude::http_error_code;
9
10#[derive(Debug)]
11pub struct HttpClientEventsReceived {
12    pub byte_size: JsonSize,
13    pub count: usize,
14    pub url: String,
15}
16
17impl InternalEvent for HttpClientEventsReceived {
18    fn emit(self) {
19        trace!(
20            message = "Events received.",
21            count = %self.count,
22            byte_size = %self.byte_size,
23            url = %self.url,
24        );
25        counter!(
26            "component_received_events_total",
27            "uri" => self.url.clone(),
28        )
29        .increment(self.count as u64);
30        counter!(
31            "component_received_event_bytes_total",
32            "uri" => self.url.clone(),
33        )
34        .increment(self.byte_size.get() as u64);
35    }
36}
37
38#[derive(Debug)]
39pub struct HttpClientHttpResponseError {
40    pub code: hyper::StatusCode,
41    pub url: String,
42}
43
44impl InternalEvent for HttpClientHttpResponseError {
45    fn emit(self) {
46        error!(
47            message = "HTTP error response.",
48            url = %self.url,
49            stage = error_stage::RECEIVING,
50            error_type = error_type::REQUEST_FAILED,
51            error_code = %http_error_code(self.code.as_u16()),
52            internal_log_rate_limit = true,
53        );
54        counter!(
55            "component_errors_total",
56            "url" => self.url,
57            "stage" => error_stage::RECEIVING,
58            "error_type" => error_type::REQUEST_FAILED,
59            "error_code" => http_error_code(self.code.as_u16()),
60        )
61        .increment(1);
62    }
63}
64
65#[derive(Debug)]
66pub struct HttpClientHttpError {
67    pub error: crate::Error,
68    pub url: String,
69}
70
71impl InternalEvent for HttpClientHttpError {
72    fn emit(self) {
73        error!(
74            message = "HTTP request processing error.",
75            url = %self.url,
76            error = ?self.error,
77            error_type = error_type::REQUEST_FAILED,
78            stage = error_stage::RECEIVING,
79            internal_log_rate_limit = true,
80        );
81        counter!(
82            "component_errors_total",
83            "url" => self.url,
84            "error_type" => error_type::REQUEST_FAILED,
85            "stage" => error_stage::RECEIVING,
86        )
87        .increment(1);
88    }
89}