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

chore(metrics): use libevm metrics package and delete local metrics #1422

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

qdm12
Copy link
Collaborator

@qdm12 qdm12 commented Jan 13, 2025

Why this should be merged

Contribution to the libevm effort.
Note there are the same changes for both coreth and subnet-evm, but they should not be part of libevm since these are extra features specific to subnet-evm/coreth, even if they're the same for both.

How this works

Comparing the following:

Therefore:

  1. All files in metrics are deleted EXCEPT:
    • metrics/prometheus/prometheus.go
    • metrics/prometheus/prometheus_test.go
    • metrics/prometheus/interfaces.go (new file added whilst refactoring)
    • go-ethereum's metrics.Enabled is set to true in initializeMetrics
  2. Refactoring and fixes were done in some intermediary step (in chore(metrics/prometheus): add files needed for coreth and subnet-evm libevm#103), so I decided to bring this over here so it doesn't get trashed. I can split it in another PR if you feel it's necessary.

How this was tested

CI passing

Need to be documented?

No

Need to update RELEASES.md?

Not really, since it should not change anything 🙏

@qdm12 qdm12 force-pushed the qdm12/libevm/metrics branch from 6cb3c96 to b63a56c Compare January 13, 2025 13:56
- Bring over refactoring and fixes done in ava-labs/libevm#103
- Bring over test refactoring done in ava-labs/libevm#103
@qdm12 qdm12 force-pushed the qdm12/libevm/metrics branch from 34e9afd to 8c8514c Compare January 13, 2025 14:57
@@ -32,8 +33,7 @@ import (
"github.com/ava-labs/subnet-evm/core/types"
"github.com/ava-labs/subnet-evm/eth"
"github.com/ava-labs/subnet-evm/eth/ethconfig"
"github.com/ava-labs/subnet-evm/metrics"
subnetEVMPrometheus "github.com/ava-labs/subnet-evm/metrics/prometheus"
subnetevmprometheus "github.com/ava-labs/subnet-evm/metrics/prometheus"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nit I took the liberty to have this all lowercase, I believe this is Go convention for package name aliases (correct me if I'm wrong!)

@@ -555,7 +555,7 @@ func (vm *VM) initializeMetrics() error {
return nil
}

gatherer := subnetEVMPrometheus.Gatherer(metrics.DefaultRegistry)
gatherer := subnetevmprometheus.NewGatherer(metrics.DefaultRegistry)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nit I took the liberty (again) to rename Gatherer to NewGatherer in order to export gatherer as Gatherer and return a *Gatherer from NewGatherer to satisfy the "return concrete types" concept

Comment on lines 25 to 31
metricsEnabled := metrics.Enabled
if !metricsEnabled {
metrics.Enabled = true
t.Cleanup(func() {
metrics.Enabled = false
})
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This might not be needed given the init() block setting the metrics to Enabled, but I preferred to keep it here if we one day revert the default Metrics Enabled to false (as it is in geth)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we put this code in a different location such as plugin/evm/metricstest
then have metricstest.WithMetrics(t) for example?

I'm assuming this code was added only to tests that were failing when metrics was disabled?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done in plugin/evm/testutils/metrics.go with a function WithMetrics(t). I went a bit crazy on the use-testutils-only-for-tests-outside-plugin/evm (inspired by your import test + arran's check for test files), since I think it would be good to only have a testutils to reduce changes in geth code, not for our own code (prefer copy pasting and defining local code for readability + reduce package dependencies)

Comment on lines 190 to 191
default:
return nil, fmt.Errorf("metric type is not supported: %T", metric)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I took the liberty to change this to return an error (instead of silently ignoring it) on an unsupported type to prevent in the future to define new types and forget to add the implementation in the switch here.

Comment on lines -165 to -173
ps := snapshot.Percentiles(pvShortPercent)
qs := make([]*dto.Quantile, len(pv))
for i := range pvShort {
v := pv[i]
s := ps[i]
qs[i] = &dto.Quantile{
Quantile: &v,
Value: &s,
}
Copy link
Collaborator Author

@qdm12 qdm12 Jan 13, 2025

Choose a reason for hiding this comment

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

Note this was some really sketchy copy and paste code; the test is refactored to cover those lines which were not previously covered.

@qdm12 qdm12 marked this pull request as ready for review January 13, 2025 16:08
@qdm12 qdm12 requested review from ceyonur, darioush and a team as code owners January 13, 2025 16:08
metrics/prometheus/prometheus.go Outdated Show resolved Hide resolved
metrics/prometheus/prometheus_test.go Outdated Show resolved Hide resolved
qdm12 added 2 commits January 13, 2025 17:16
Signed-off-by: Quentin McGaw <quentin.mcgaw@gmail.com>
Signed-off-by: Quentin McGaw <quentin.mcgaw@gmail.com>
go.mod Outdated Show resolved Hide resolved
Comment on lines 25 to 31
metricsEnabled := metrics.Enabled
if !metricsEnabled {
metrics.Enabled = true
t.Cleanup(func() {
metrics.Enabled = false
})
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we put this code in a different location such as plugin/evm/metricstest
then have metricstest.WithMetrics(t) for example?

I'm assuming this code was added only to tests that were failing when metrics was disabled?

metrics/prometheus/prometheus.go Outdated Show resolved Hide resolved
@qdm12 qdm12 force-pushed the qdm12/libevm/metrics branch from 7c08815 to 15866c8 Compare January 15, 2025 11:15
@qdm12 qdm12 requested a review from darioush January 15, 2025 11:40
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.

2 participants