-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make metrics value composable (#648)
* Make metrics value composable * Allow any metric value that can be casted to record * Move crawler metrics to crawler client
- Loading branch information
1 parent
ace06c8
commit 2fbed04
Showing
6 changed files
with
109 additions
and
57 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,30 @@ | ||
use crate::types::Origin; | ||
|
||
pub trait Value: Send + Clone { | ||
fn is_allowed(&self, origin: &Origin) -> bool; | ||
} | ||
|
||
#[cfg(test)] | ||
pub mod tests { | ||
use crate::telemetry::{metric, MetricCounter, Metrics, Record}; | ||
use async_trait::async_trait; | ||
use color_eyre::eyre; | ||
use libp2p::{kad::Mode, Multiaddr}; | ||
|
||
pub struct MockMetrics {} | ||
|
||
#[async_trait] | ||
impl Metrics for MockMetrics { | ||
async fn count(&self, _: MetricCounter) {} | ||
async fn record<T>(&self, _: T) | ||
where | ||
T: metric::Value + Into<Record> + Send, | ||
{ | ||
} | ||
async fn flush(&self) -> eyre::Result<()> { | ||
Ok(()) | ||
} | ||
async fn update_operating_mode(&self, _: Mode) {} | ||
async fn update_multiaddress(&self, _: Multiaddr) {} | ||
} | ||
} |
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