Skip to content

feat: use macro to declare metric constants#1129

Merged
SuperFluffy merged 3 commits intomainfrom
superfluffy/declare_metric_constants
Jun 4, 2024
Merged

feat: use macro to declare metric constants#1129
SuperFluffy merged 3 commits intomainfrom
superfluffy/declare_metric_constants

Conversation

@SuperFluffy
Copy link
Contributor

@SuperFluffy SuperFluffy commented May 31, 2024

Summary

Introduce a macro declare_metric_const! to avoid repetition and common typos when declaring string consts used as metric names.

Background

Noticed some common errors in reviews and when writing metrics: mismatch between the const's name and the actual value. Missing underscores. Annoying repetiton of env!("CARGO_CRATE_NAME");

Changes

  • Declare a macro declare_metric_const! and define all consts in terms of it.
  • Add unit tests for all macros to ensure they don't accidentally break.

Testing

  • Unit tests for all const declaration
  • Simple unit test for the macro

Metrics

  • astria_composer_transactions_per_submission replaces astria_composer_transaction_per_submission

@github-actions github-actions bot added conductor pertaining to the astria-conductor crate sequencer pertaining to the astria-sequencer crate sequencer-relayer pertaining to the astria-sequencer-relayer crate composer pertaining to composer labels May 31, 2024
@SuperFluffy SuperFluffy force-pushed the superfluffy/declare_metric_constants branch 2 times, most recently from ac155db to 5596ddf Compare May 31, 2024 16:11
};

pub const TRANSACTIONS_PER_SUBMISSION: &str =
concat!(env!("CARGO_CRATE_NAME"), "_transaction_per_submission");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The macro (and test) caught this const being oddly named. This is now astria_composer_transactions_per_submission

@SuperFluffy SuperFluffy marked this pull request as ready for review May 31, 2024 16:14
@SuperFluffy SuperFluffy requested a review from a team as a code owner May 31, 2024 16:14
@SuperFluffy SuperFluffy requested a review from Fraser999 May 31, 2024 16:14
Copy link
Contributor

@Fraser999 Fraser999 left a comment

Choose a reason for hiding this comment

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

Nice upgrade! I made a couple of suggestions, but both non-blocking.

I also think the unit tests aren't needed (except for the one in astria-telemetry) and could be removed since they're likely to become a source of frustration as we'll inevitably change metrics over time.

I was planning to add metrics snapshot testing of some sort in an upcoming PR, and I think if that's in place, these unit tests are really only testing the macro, which has its own unit test :)

@SuperFluffy SuperFluffy force-pushed the superfluffy/declare_metric_constants branch from 5596ddf to 9fe63a0 Compare June 4, 2024 12:23
@SuperFluffy
Copy link
Contributor Author

Rebased on top of recent main and used the new macro for the new bridge-withdrawer service

@SuperFluffy SuperFluffy enabled auto-merge June 4, 2024 12:25
@SuperFluffy SuperFluffy added this pull request to the merge queue Jun 4, 2024
Merged via the queue into main with commit fb1d7b8 Jun 4, 2024
@SuperFluffy SuperFluffy deleted the superfluffy/declare_metric_constants branch June 4, 2024 12:34
steezeburger added a commit that referenced this pull request Jun 5, 2024
* main:
  fix(charts): conductor configmap fix (#1146)
  feat(sequencer): add `allowed_fee_asset_ids` abci query and `sequencer_client` support (#1127)
  chore(conductor): release conductor 0.17 (#1139)
  feat: use macro to declare metric constants (#1129)
  refactor(merkle): remove source of panics in audit API (#1137)
  feat(conductor): skip outdated block metadata (#1120)
  refactor(sequencer): remove mint module (#1134)
  feat(bridge-withdrawer): add justfile (#1135)
  chore(chart): change evm back to latest on dev (#1132)
  feat(conductor, proto)!: celestia base heights in commitment state (#1121)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

composer pertaining to composer conductor pertaining to the astria-conductor crate sequencer pertaining to the astria-sequencer crate sequencer-relayer pertaining to the astria-sequencer-relayer crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants