-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instrument the opencensus exporter (#362)
Fixes linkerd/linkerd2#3453 Instrument the opencensus exporter with the following metrics: ``` # HELP span_export_streams Total count of opened span export streams # TYPE span_export_streams counter span_export_streams 1 # HELP span_export_requests Total count of span export request messages # TYPE span_export_requests counter span_export_requests 497 # HELP span_exports Total count of spans exported # TYPE span_exports counter span_exports 994 ``` Signed-off-by: Alex Leong <alex@buoyant.io>
- Loading branch information
Showing
5 changed files
with
99 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use linkerd2_metrics::{metrics, Counter, FmtMetrics}; | ||
use std::fmt; | ||
use std::sync::{Arc, Mutex}; | ||
use tracing::error; | ||
|
||
metrics! { | ||
opencensus_span_export_streams: Counter { "Total count of opened span export streams" }, | ||
opencensus_span_export_requests: Counter { "Total count of span export request messages" }, | ||
opencensus_span_exports: Counter { "Total count of spans exported" } | ||
} | ||
|
||
struct Metrics { | ||
streams: Counter, | ||
requests: Counter, | ||
spans: Counter, | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct Registry(Arc<Mutex<Metrics>>); | ||
|
||
#[derive(Clone)] | ||
pub struct Report(Arc<Mutex<Metrics>>); | ||
|
||
pub fn new() -> (Registry, Report) { | ||
let metrics = Metrics { | ||
streams: Counter::default(), | ||
requests: Counter::default(), | ||
spans: Counter::default(), | ||
}; | ||
let shared = Arc::new(Mutex::new(metrics)); | ||
(Registry(shared.clone()), Report(shared)) | ||
} | ||
|
||
impl Registry { | ||
pub fn start_stream(&mut self) { | ||
match self.0.lock() { | ||
Ok(mut metrics) => metrics.streams.incr(), | ||
Err(e) => error!(message="failed to lock metrics", %e), | ||
} | ||
} | ||
|
||
pub fn send(&mut self, spans: u64) { | ||
match self.0.lock() { | ||
Ok(mut metrics) => { | ||
metrics.requests.incr(); | ||
metrics.spans += spans; | ||
} | ||
Err(e) => error!(message="failed to lock metrics", %e), | ||
} | ||
} | ||
} | ||
|
||
impl FmtMetrics for Report { | ||
fn fmt_metrics(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
let metrics = match self.0.lock() { | ||
Err(_) => return Ok(()), | ||
Ok(lock) => lock, | ||
}; | ||
|
||
opencensus_span_export_streams.fmt_help(f)?; | ||
opencensus_span_export_streams.fmt_metric(f, metrics.streams)?; | ||
|
||
opencensus_span_export_requests.fmt_help(f)?; | ||
opencensus_span_export_requests.fmt_metric(f, metrics.requests)?; | ||
|
||
opencensus_span_exports.fmt_help(f)?; | ||
opencensus_span_exports.fmt_metric(f, metrics.spans)?; | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters