vector/internal_events/
http_client_source.rs

1#![allow(dead_code)] // TODO requires optional feature compilation
2
3use metrics::counter;
4use vector_lib::{
5    internal_event::{InternalEvent, error_stage, error_type},
6    json_size::JsonSize,
7};
8
9use super::prelude::http_error_code;
10
11#[derive(Debug)]
12pub struct HttpClientEventsReceived {
13    pub byte_size: JsonSize,
14    pub count: usize,
15    pub url: String,
16}
17
18impl InternalEvent for HttpClientEventsReceived {
19    fn emit(self) {
20        trace!(
21            message = "Events received.",
22            count = %self.count,
23            byte_size = %self.byte_size,
24            url = %self.url,
25        );
26        counter!(
27            "component_received_events_total",
28            "uri" => self.url.clone(),
29        )
30        .increment(self.count as u64);
31        counter!(
32            "component_received_event_bytes_total",
33            "uri" => self.url.clone(),
34        )
35        .increment(self.byte_size.get() as u64);
36    }
37}
38
39#[derive(Debug)]
40pub struct HttpClientHttpResponseError {
41    pub code: hyper::StatusCode,
42    pub url: String,
43}
44
45impl InternalEvent for HttpClientHttpResponseError {
46    fn emit(self) {
47        error!(
48            message = "HTTP error response.",
49            url = %self.url,
50            stage = error_stage::RECEIVING,
51            error_type = error_type::REQUEST_FAILED,
52            error_code = %http_error_code(self.code.as_u16()),
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        );
80        counter!(
81            "component_errors_total",
82            "url" => self.url,
83            "error_type" => error_type::REQUEST_FAILED,
84            "stage" => error_stage::RECEIVING,
85        )
86        .increment(1);
87    }
88}