-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: continously publish provider records (#175)
- Loading branch information
1 parent
75e2137
commit 7e2d3f4
Showing
11 changed files
with
445 additions
and
35 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,61 @@ | ||
use ceramic_metrics::Recorder; | ||
use prometheus_client::{ | ||
encoding::{EncodeLabelSet, EncodeLabelValue}, | ||
metrics::{counter::Counter, family::Family}, | ||
registry::Registry, | ||
}; | ||
|
||
/// Metrics for Ceramic P2P events | ||
#[derive(Clone)] | ||
pub struct Metrics { | ||
publish_results: Family<PublishResultsLabels, Counter>, | ||
} | ||
|
||
#[derive(Clone, Debug, Hash, PartialEq, Eq, EncodeLabelSet)] | ||
struct PublishResultsLabels { | ||
result: PublishResult, | ||
} | ||
|
||
impl From<&PublishResult> for PublishResultsLabels { | ||
fn from(value: &PublishResult) -> Self { | ||
Self { result: *value } | ||
} | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, EncodeLabelValue)] | ||
pub enum PublishResult { | ||
Success, | ||
Failed, | ||
} | ||
|
||
impl Metrics { | ||
/// Register and construct Metrics | ||
pub fn register(registry: &mut Registry) -> Self { | ||
let sub_registry = registry.sub_registry_with_prefix("p2p"); | ||
|
||
let publish_results = Family::<PublishResultsLabels, Counter>::default(); | ||
sub_registry.register( | ||
"publish_results", | ||
"Number of provider records results", | ||
publish_results.clone(), | ||
); | ||
|
||
Self { publish_results } | ||
} | ||
} | ||
|
||
pub enum Event { | ||
PublishResult(PublishResult), | ||
} | ||
|
||
impl Recorder<Option<Event>> for Metrics { | ||
fn record(&self, event: &Option<Event>) { | ||
match event { | ||
Some(Event::PublishResult(result)) => { | ||
let labels = result.into(); | ||
self.publish_results.get_or_create(&labels).inc(); | ||
} | ||
None => {} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.