forked from open-telemetry/opentelemetry-rust
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmetric_reader.rs
68 lines (57 loc) · 1.57 KB
/
metric_reader.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use std::sync::{Arc, Mutex, Weak};
use crate::metrics::{
aggregation::Aggregation,
data::{ResourceMetrics, Temporality},
instrument::InstrumentKind,
pipeline::Pipeline,
reader::{AggregationSelector, MetricReader, TemporalitySelector},
};
use opentelemetry::metrics::Result;
#[derive(Debug, Clone)]
pub struct TestMetricReader {
is_shutdown: Arc<Mutex<bool>>,
}
impl TestMetricReader {
// Constructor to initialize the TestMetricReader
pub fn new() -> Self {
TestMetricReader {
is_shutdown: Arc::new(Mutex::new(false)),
}
}
// Method to check if the reader is shutdown
pub fn is_shutdown(&self) -> bool {
*self.is_shutdown.lock().unwrap()
}
}
impl Default for TestMetricReader {
fn default() -> Self {
Self::new()
}
}
impl MetricReader for TestMetricReader {
fn register_pipeline(&self, _pipeline: Weak<Pipeline>) {}
fn collect(&self, _rm: &mut ResourceMetrics) -> Result<()> {
Ok(())
}
fn force_flush(&self) -> Result<()> {
Ok(())
}
fn shutdown(&self) -> Result<()> {
let result = self.force_flush();
{
let mut is_shutdown = self.is_shutdown.lock().unwrap();
*is_shutdown = true;
}
result
}
}
impl AggregationSelector for TestMetricReader {
fn aggregation(&self, _kind: InstrumentKind) -> Aggregation {
Aggregation::Drop
}
}
impl TemporalitySelector for TestMetricReader {
fn temporality(&self, _kind: InstrumentKind) -> Temporality {
Temporality::Cumulative
}
}