Skip to content

Commit 441dd74

Browse files
committed
Add missing documentation
1 parent 97c31a5 commit 441dd74

File tree

6 files changed

+21
-8
lines changed

6 files changed

+21
-8
lines changed

internal/mithril-metric/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ check:
1616
${CARGO} fmt --check
1717

1818
doc:
19-
${CARGO} doc --no-deps --open --features full
19+
${CARGO} doc --no-deps --open

internal/mithril-metric/src/helper.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Helper to create a metric service.
2+
13
/// Create a MetricService.
24
///
35
/// To build the service you need to provide the structure name and a list of metrics.
@@ -28,17 +30,17 @@ macro_rules! build_metrics_service {
2830
paste::item! {
2931
/// Metrics service which is responsible for recording and exposing metrics.
3032
pub struct $service {
31-
registry: Registry,
33+
registry: prometheus::Registry,
3234
$(
3335
$metric_attribute: $metric_type,
3436
)*
3537
}
3638

3739
impl $service {
3840
/// Create a new MetricsService instance.
39-
pub fn new(logger: Logger) -> StdResult<Self> {
41+
pub fn new(logger: slog::Logger) -> mithril_common::StdResult<Self> {
4042

41-
let registry = Registry::new();
43+
let registry = prometheus::Registry::new();
4244

4345
$(
4446
let $metric_attribute = $metric_type::new(
@@ -65,7 +67,7 @@ macro_rules! build_metrics_service {
6567
}
6668

6769
impl MetricsServiceExporter for $service {
68-
fn export_metrics(&self) -> StdResult<String> {
70+
fn export_metrics(&self) -> mithril_common::StdResult<String> {
6971
Ok(prometheus::TextEncoder::new().encode_to_string(&self.registry.gather())?)
7072
}
7173
}

internal/mithril-metric/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![warn(missing_docs)]
2+
13
//! metrics module.
24
//! This module contains the tools to create a metrics service and a metrics server.
35

internal/mithril-metric/src/metric.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! This module contains wrapper to prometheus metrics for use in a metrics service.
2+
13
use prometheus::{core::Collector, Counter, Gauge, Opts};
24
use slog::{debug, Logger};
35

@@ -26,6 +28,7 @@ pub struct MetricCounter {
2628
}
2729

2830
impl MetricCounter {
31+
/// Create a new metric counter.
2932
pub fn new(logger: Logger, name: &str, help: &str) -> StdResult<Self> {
3033
let counter = MetricCounter::create_metric_counter(name, help)?;
3134
Ok(Self {
@@ -35,11 +38,13 @@ impl MetricCounter {
3538
})
3639
}
3740

41+
/// Increment the counter.
3842
pub fn increment(&self) {
3943
debug!(self.logger, "Incrementing '{}' counter", self.name);
4044
self.counter.inc();
4145
}
4246

47+
/// Get the counter value.
4348
pub fn get(&self) -> CounterValue {
4449
self.counter.get().round() as CounterValue
4550
}
@@ -70,6 +75,7 @@ pub struct MetricGauge {
7075
}
7176

7277
impl MetricGauge {
78+
/// Create a new metric gauge.
7379
pub fn new(logger: Logger, name: &str, help: &str) -> StdResult<Self> {
7480
let gauge = MetricGauge::create_metric_gauge(name, help)?;
7581
Ok(Self {
@@ -79,6 +85,7 @@ impl MetricGauge {
7985
})
8086
}
8187

88+
/// Record a value in the gauge.
8289
pub fn record<T: Into<f64> + Copy>(&self, value: T) {
8390
debug!(
8491
self.logger,
@@ -89,6 +96,7 @@ impl MetricGauge {
8996
self.gauge.set(value.into());
9097
}
9198

99+
/// Get the gauge value.
92100
pub fn get(&self) -> f64 {
93101
self.gauge.get().round()
94102
}

internal/mithril-metric/src/server.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ use tokio::sync::oneshot::Receiver;
1313
use mithril_common::logging::LoggerExtensions;
1414
use mithril_common::StdResult;
1515

16+
/// Metrics service exporter gives the possibility of exporting metrics.
1617
pub trait MetricsServiceExporter {
18+
/// Export metrics.
1719
fn export_metrics(&self) -> StdResult<String>;
1820
}
1921

mithril-signer/src/metrics/service.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use mithril_metric::{build_metrics_service, MetricsServiceExporter};
2-
use prometheus::Registry;
3-
use slog::Logger;
42

5-
use mithril_common::{entities::Epoch, StdResult};
3+
use mithril_common::entities::Epoch;
64

75
use mithril_metric::metric::{CounterValue, MetricCollector, MetricCounter, MetricGauge};
86

@@ -147,6 +145,7 @@ impl MetricsService {
147145

148146
#[cfg(test)]
149147
mod tests {
148+
use mithril_common::StdResult;
150149
use prometheus_parse::Value;
151150
use std::collections::BTreeMap;
152151

0 commit comments

Comments
 (0)