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