Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metrics to gas price service #2635

Merged
merged 9 commits into from
Jan 29, 2025
Merged

Conversation

MitchTurner
Copy link
Member

@MitchTurner MitchTurner commented Jan 26, 2025

Linked Issues/PRs

Description

A lot of the data that effects the gas price is somewhat opaque. Up until now, it's been hard to read without direct access to the Gas Price DB. This will give us visibility into:

pub struct GasPriceMetrics {
    pub real_gas_price: Gauge,
    pub exec_gas_price: Gauge,
    pub da_gas_price: Gauge,
    pub total_reward: Gauge,
    pub total_known_costs: Gauge,
    pub predicted_profit: Gauge,
    pub unrecorded_bytes: Gauge,
    pub latest_cost_per_byte: Gauge,
    pub recorded_height: Gauge,
}

which allows us to make charts like (plz ignore the gaps, this was just testing the visualizations):
image

Before requesting review

  • I have reviewed the code myself

@MitchTurner MitchTurner self-assigned this Jan 28, 2025
@MitchTurner MitchTurner marked this pull request as ready for review January 28, 2025 17:19
@@ -303,12 +309,61 @@ where
AtomicStorage::commit_transaction(storage_tx)?;
let new_algo = self.algorithm_updater.algorithm();
tracing::debug!("Updating gas price: {}", &new_algo.calculate());
self.shared_algo.update(new_algo);
self.shared_algo.update(new_algo).await;
Copy link
Member

Choose a reason for hiding this comment

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

why await here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm confused by the error:

    pub async fn update(&mut self, new_algo: A) {
        let mut write_lock = self.0.write();
        *write_lock = new_algo;
    }

Copy link
Member Author

Choose a reason for hiding this comment

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

nvm need to pull

// Clear the buffer after committing changes
self.da_block_costs_buffer.clear();
Ok(())
}

fn record_metrics(
Copy link
Member

Choose a reason for hiding this comment

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

we should conditionally export metrics, see description of #2310 for reference

Comment on lines 262 to 272
let (old_recorded_height, mut new_recorded_height) = match storage_tx
.get_recorded_height()
.map_err(|err| anyhow!(err))?
{
Some(_) => None,
Some(old) => (Some(old), None),
None => {
// Sets it on first run
self.initial_recorded_height.take()
let initial = self.initial_recorded_height.take();
(initial, initial)
}
};
Copy link
Member

Choose a reason for hiding this comment

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

do we need this change?

Copy link
Member Author

@MitchTurner MitchTurner Jan 28, 2025

Choose a reason for hiding this comment

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

Maybe (None, initial) would be clearer.

Copy link
Contributor

@netrome netrome left a comment

Choose a reason for hiding this comment

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

Looks mostly good to me. I'm a bit concerned about returning i64::MAX when we're out of range. I get that this should never happen, but I'd rather see an error or warning log in this scenario rather than reporting a hard-coded value.

Comment on lines +332 to +335
let exec_gas_price_i64 = v1_metadata
.new_exec_gas_price()
.try_into()
.unwrap_or(i64::MAX);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I generally prefer explicit conversions for readability. I.e. i64::try_from().

I'm also uncertain if it makes sense to report i64::MAX if we're out of range. Wouldn't it be better to not report any metrics and log an error in this case?

@xgreenx
Copy link
Collaborator

xgreenx commented Jan 29, 2025

Just a question: Are you sure that it is enough information for you to understand the all internal state of the algorithm?

@MitchTurner MitchTurner merged commit 01c6cb0 into master Jan 29, 2025
33 checks passed
@MitchTurner MitchTurner deleted the feature/gas-price-metrics branch January 29, 2025 02:42
@MitchTurner
Copy link
Member Author

MitchTurner commented Jan 29, 2025

Just a question: Are you sure that it is enough information for you to understand the all internal state of the algorithm?

I think this is enough. I was missing the recorded_height, but added that.

@AurelienFT AurelienFT mentioned this pull request Feb 3, 2025
AurelienFT added a commit that referenced this pull request Feb 3, 2025
## Version 0.41.5

### Changed
- [2387](#2387): Update
description `tx-max-depth` flag.
- [2630](#2630): Removed some
noisy `tracing::info!` logs
- [2643](#2643): Before this
fix when tip is zero, transactions that use 30M have the same priority
as transactions with 1M gas. Now they are correctly ordered.

### Added
- [2617](#2617): Add
integration skeleton of parallel-executor.
- [2553](#2553): Scaffold
global merkle root storage crate.
- [2598](#2598): Add initial
test suite for global merkle root storage updates.
- [2635](#2635): Add metrics
to gas price service

### Fixed
- [2632](#2632): Improved
performance of certain async trait impls in the gas price service.
- [2662](#2662): Fix balances
query endpoint cost without indexation and behavior coins to spend with
one parameter at zero.
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.

5 participants