vector/api/schema/metrics/
errors.rs1use async_graphql::Object;
2use chrono::{DateTime, Utc};
3
4use crate::{
5 config::ComponentKey,
6 event::{Metric, MetricValue},
7};
8
9pub struct ErrorsTotal(Metric);
10
11impl ErrorsTotal {
12 pub const fn new(m: Metric) -> Self {
13 Self(m)
14 }
15}
16
17#[Object]
18impl ErrorsTotal {
19 pub async fn timestamp(&self) -> Option<DateTime<Utc>> {
21 self.0.timestamp()
22 }
23
24 pub async fn errors_total(&self) -> f64 {
26 match self.0.value() {
27 MetricValue::Counter { value } => *value,
28 _ => 0.00,
29 }
30 }
31}
32
33impl From<Metric> for ErrorsTotal {
34 fn from(m: Metric) -> Self {
35 Self(m)
36 }
37}
38
39pub struct ComponentErrorsTotal {
40 component_key: ComponentKey,
41 metric: Metric,
42}
43
44impl ComponentErrorsTotal {
45 pub fn new(metric: Metric) -> Self {
48 let component_key = metric.tag_value("component_id").expect(
49 "Returned a metric without a `component_id`, which shouldn't happen. Please report.",
50 );
51 let component_key = ComponentKey::from(component_key);
52
53 Self {
54 component_key,
55 metric,
56 }
57 }
58}
59
60#[Object]
61impl ComponentErrorsTotal {
62 async fn component_id(&self) -> &str {
64 self.component_key.id()
65 }
66
67 async fn metric(&self) -> ErrorsTotal {
69 ErrorsTotal::new(self.metric.clone())
70 }
71}