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

feat: fetch chain-specific metrics in standalone task #3214

Merged
merged 6 commits into from
Feb 8, 2024

Conversation

daniel-savu
Copy link
Contributor

@daniel-savu daniel-savu commented Feb 2, 2024

Description

Spawning a tokio task to fetch chain-specific metrics in provider middleware was wasteful because we ended up with 15 tasks doing the same job. Now there is a single task that is spawned inside the relayer, which I added in the struct that used to only fetch relayer balance.

Some questions:

  • I'm realising in the current state I'm probably removing these metrics from validators. Lmk if yes and I'll add back
  • the chain-specific metrics were moved out of MiddlewareMetrics because they're no longer part of middleware, but I wasn't sure where to place them. Maybe CoreMetrics is a better place than the current custom_metrics.rs file?

tokio-metrics turned out not to be useful because we'd need to instrument every call site of tokio::spawn with it. We should still do it but as a separate task imo.

Drive-by changes

  • This PR also makes it very easy to add the metrics tasks for new chains, by extending the HyperlaneProvider trait with a get_chain_metrics call which seems reasonably general to me to have implemented by all providers. (Bc we currently only track these for evm chains)
    • the description, naming and logic of the gas_price metric was also changed to support new chains

Related issues

Backward compatibility

Yes

Testing

Still need to manually test

@daniel-savu daniel-savu requested a review from tkporter as a code owner February 2, 2024 18:08
Copy link

changeset-bot bot commented Feb 2, 2024

⚠️ No Changeset found

Latest commit: 02ba925

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

codecov bot commented Feb 2, 2024

Codecov Report

Merging #3214 (02ba925) into main (ab17af5) will increase coverage by 67.65%.
The diff coverage is n/a.

Additional details and impacted files
@@            Coverage Diff            @@
##           main    #3214       +/-   ##
=========================================
+ Coverage      0   67.65%   +67.65%     
=========================================
  Files         0       99       +99     
  Lines         0     1014     +1014     
  Branches      0      106      +106     
=========================================
+ Hits          0      686      +686     
- Misses        0      284      +284     
- Partials      0       44       +44     
Components Coverage Δ
core 50.00% <ø> (∅)
hooks 68.79% <ø> (∅)
isms 65.94% <ø> (∅)
token 58.41% <ø> (∅)
middlewares 81.46% <ø> (∅)

Copy link
Collaborator

@tkporter tkporter left a comment

Choose a reason for hiding this comment

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

I think you're right that this removes the metrics from the validator and scraper. is there a way to spawn the metric updater task in agent agnostic code?

rust/chains/hyperlane-ethereum/src/provider.rs Outdated Show resolved Hide resolved
rust/hyperlane-base/src/metrics/custom_metrics.rs Outdated Show resolved Hide resolved
rust/hyperlane-base/src/metrics/custom_metrics.rs Outdated Show resolved Hide resolved
rust/hyperlane-base/src/metrics/custom_metrics.rs Outdated Show resolved Hide resolved
rust/hyperlane-base/src/metrics/custom_metrics.rs Outdated Show resolved Hide resolved
rust/hyperlane-base/src/metrics/custom_metrics.rs Outdated Show resolved Hide resolved
rust/hyperlane-core/src/traits/provider.rs Outdated Show resolved Hide resolved
rust/hyperlane-core/src/types/chain_data.rs Outdated Show resolved Hide resolved
rust/hyperlane-base/src/metrics/custom_metrics.rs Outdated Show resolved Hide resolved
rust/hyperlane-base/src/metrics/agent_metrics.rs Outdated Show resolved Hide resolved
rust/chains/hyperlane-ethereum/src/provider.rs Outdated Show resolved Hide resolved
rust/chains/hyperlane-ethereum/src/provider.rs Outdated Show resolved Hide resolved
rust/hyperlane-base/src/metrics/agent_metrics.rs Outdated Show resolved Hide resolved
rust/hyperlane-base/src/metrics/custom_metrics.rs Outdated Show resolved Hide resolved
@daniel-savu daniel-savu enabled auto-merge (squash) February 8, 2024 17:14
@daniel-savu daniel-savu merged commit 3cbb06a into main Feb 8, 2024
21 of 22 checks passed
@daniel-savu daniel-savu deleted the dan/optimize-chain-metrics-fetching branch February 8, 2024 17:44
yorhodes pushed a commit that referenced this pull request Feb 12, 2024
### Description

Spawning a tokio task to fetch chain-specific metrics in provider
middleware was wasteful because we ended up with 15 tasks doing the same
job. Now there is a single task that is spawned inside the relayer,
which I added in the struct that used to only fetch relayer balance.

Some questions:
- I'm realising in the current state I'm probably removing these metrics
from validators. Lmk if yes and I'll add back
- the chain-specific metrics were moved out of `MiddlewareMetrics`
because they're no longer part of middleware, but I wasn't sure where to
place them. Maybe `CoreMetrics` is a better place than the current
`custom_metrics.rs` file?

`tokio-metrics` turned out not to be useful because we'd need to
instrument every call site of `tokio::spawn` with it. We should still do
it but as a separate task imo.

### Drive-by changes

- This PR also makes it very easy to add the metrics tasks for new
chains, by extending the `HyperlaneProvider` trait with a
`get_chain_metrics` call which seems reasonably general to me to have
implemented by all providers. (Bc we currently only track these for evm
chains)
- the description, naming and logic of the `gas_price` metric was also
changed to support new chains

### Related issues

- Fixes #3047

### Backward compatibility

Yes

### Testing

Still need to manually test
ltyu pushed a commit to ltyu/hyperlane-monorepo that referenced this pull request Mar 13, 2024
…3214)

### Description

Spawning a tokio task to fetch chain-specific metrics in provider
middleware was wasteful because we ended up with 15 tasks doing the same
job. Now there is a single task that is spawned inside the relayer,
which I added in the struct that used to only fetch relayer balance.

Some questions:
- I'm realising in the current state I'm probably removing these metrics
from validators. Lmk if yes and I'll add back
- the chain-specific metrics were moved out of `MiddlewareMetrics`
because they're no longer part of middleware, but I wasn't sure where to
place them. Maybe `CoreMetrics` is a better place than the current
`custom_metrics.rs` file?

`tokio-metrics` turned out not to be useful because we'd need to
instrument every call site of `tokio::spawn` with it. We should still do
it but as a separate task imo.

### Drive-by changes

- This PR also makes it very easy to add the metrics tasks for new
chains, by extending the `HyperlaneProvider` trait with a
`get_chain_metrics` call which seems reasonably general to me to have
implemented by all providers. (Bc we currently only track these for evm
chains)
- the description, naming and logic of the `gas_price` metric was also
changed to support new chains

### Related issues

- Fixes hyperlane-xyz#3047

### Backward compatibility

Yes

### Testing

Still need to manually test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Investigate spawned metric tasks in agents
2 participants