Open
Conversation
Collaborator
Pull Request Test Coverage Report for Build 23269894458Details
💛 - Coveralls |
spacebear21
requested changes
Mar 13, 2026
Collaborator
spacebear21
left a comment
There was a problem hiding this comment.
cACK, but I have a suggestion for a different approach.
Now that the directory lives in payjoin-mailroom, we should be able to wrap a Metrics wrapper around the DB following a middleware pattern. Something like this:
// db/mod.rs
/// Db decorator that records write metrics.
#[derive(Clone)]
pub struct MetricsDb<D: Db> {
inner: D,
metrics: MetricsService,
}
impl<D: Db> Db for MetricsDb<D> {
type OperationalError = D::OperationalError;
async fn post_v2_payload(
&self,
mailbox_id: &ShortId,
data: Vec<u8>,
) -> Result<Option<()>, Error<Self::OperationalError>> {
let result = self.inner.post_v2_payload(mailbox_id, data).await?;
self.metrics.record_db_entry("2");
Ok(result)
}
// ...
}
// lib.rs
struct Services {
directory: directory::Service<MetricsDb<DbServiceAdapter>>,
relay: ohttp_relay::Service,
metrics: MetricsService,
// ...
}
async fn init_directory(
config: &Config,
sentinel_tag: SentinelTag,
metrics: MetricsService,
) -> anyhow::Result<directory::Service<MetricsDb<DbServiceAdapter>>> {
let files_db = FilesDb::init(config.timeout, config.storage_dir.clone()).await?;
files_db.spawn_background_prune().await;
let db = MetricsDb::new(DbServiceAdapter::new(files_db), metrics);
// ...
}This keeps metrics out of the directory and follows a more modular approach in line with tower patterns.
spacebear21
reviewed
Mar 13, 2026
f21c0df to
ad71757
Compare
spacebear21
requested changes
Mar 17, 2026
payjoin-mailroom/src/lib.rs
Outdated
| let geoip = init_geoip(&config).await?; | ||
|
|
||
| let directory = init_directory(&config, sentinel_tag).await?; | ||
| let directory = init_directory(&config, sentinel_tag, metrics.clone()).await?; |
Collaborator
There was a problem hiding this comment.
This clones the metrics service, that would result in two separate instances of MetricsService tracking different things independently right? We should probably pass some type of reference to ensure there is only one source of truth.
this pr addresses payjoin#941 , it adds db entries metrics seperated by version (v1/v2)
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
this pr addresses the db entries part of #941 , it adds db entries metrics seperated by version (v1/v2). For now it's just simple incremental counter seperated by v1/v2.
Pull Request Checklist
Please confirm the following before requesting review:
AI
in the body of this PR.