Skip to content

Add db entry metrics#1412

Merged
spacebear21 merged 2 commits into
payjoin:masterfrom
zealsham:db-metrics
Mar 30, 2026
Merged

Add db entry metrics#1412
spacebear21 merged 2 commits into
payjoin:masterfrom
zealsham:db-metrics

Conversation

@zealsham

@zealsham zealsham commented Mar 12, 2026

Copy link
Copy Markdown
Collaborator

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:

@coveralls

coveralls commented Mar 12, 2026

Copy link
Copy Markdown
Collaborator

Pull Request Test Coverage Report for Build 23306027115

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 91 of 97 (93.81%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.09%) to 84.216%

Changes Missing Coverage Covered Lines Changed/Added Lines %
payjoin-mailroom/src/lib.rs 9 15 60.0%
Totals Coverage Status
Change from base Build 23193941891: 0.09%
Covered Lines: 10730
Relevant Lines: 12741

💛 - Coveralls

@zealsham
zealsham requested a review from spacebear21 March 13, 2026 12:08

@spacebear21 spacebear21 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread payjoin-mailroom/src/metrics.rs Outdated
@zealsham
zealsham force-pushed the db-metrics branch 2 times, most recently from f21c0df to ad71757 Compare March 17, 2026 10:05
Comment thread 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?;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread payjoin-mailroom/src/directory.rs Outdated
Comment thread payjoin-mailroom/src/metrics.rs Outdated
this pr addresses payjoin#941 , it adds db entries metrics seperated
by version (v1/v2)
Instead of kitchen-sinking the v1/_core payjoin feature just for this

@spacebear21 spacebear21 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK ca80b75, applied my suggestion from #1412 (comment)

@zealsham
zealsham requested review from DanGould March 20, 2026 23:55

@DanGould DanGould left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK ca80b75

@spacebear21
spacebear21 merged commit 6a32bcc into payjoin:master Mar 30, 2026
16 checks passed
@benalleng benalleng mentioned this pull request Jun 7, 2026
17 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants