-
Notifications
You must be signed in to change notification settings - Fork 5
refactor(metrics): New* constructors use GetOrRegister* functions
#159
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
Conversation
- Avoid conflicts for metrics used both in consumers and in libevm - See ava-labs/coreth#848
|
Is this a correct understanding of the status quo?
EDIT: I hadn't considered the yet-to-transition packages that exist in |
New* constructors use GetOrRegister* functionsNew* constructors use GetOrRegister* functions
The order can be forced with a blank import for side effects. Here's a pattern that I think has the desired effect without the need to change |
|
Packages which are:
are the following:
Now, the good thing is all their metrics are unexported, so that reduces the problem scope. However, say for the EDIT: using underscore imports in those packages above + GetOrRegister in consumers solves this |
Closing in favour of ava-labs/coreth#860. |
`geth` (and hence `libevm`) global metrics tend to be created with `NewRegistered*()`, which assumes that there are no name conflicts on the same `Registry`. If there are then the second call fails silently to register the new metric. Except for in `warp` (where there won't be any conflicts) metric registration is changed globally to use `GetOrRegister*()` instead of `NewRegistered*()`. With GNU tools (not the Mac budget replacements): ```shell find -iname '*.go' -not -iwholename '*/warp/*' | xargs sed -i 's|metrics.NewRegistered|metrics.GetOrRegister|g' ``` All modified files that don't already import their `libevm` counterparts now `_` import them to force the initialisation order. The `libevm` construction with `NewRegistered*()` therefore always comes before the respective `GetOrRegister*()` so both call sites have the same metric instance. Metrics that we expect to be counters instead of timers are unregistered and newly created with the correct type, borrowing from ava-labs/libevm#159.
`geth` (and hence `libevm`) global metrics tend to be created with `NewRegistered*()`, which assumes that there are no name conflicts on the same `Registry`. If there are then the second call fails silently to register the new metric. Except for in `warp` (where there won't be any conflicts) metric registration is changed globally to use `GetOrRegister*()` instead of `NewRegistered*()`. With GNU tools (not the Mac budget replacements): ```shell find -iname '*.go' -not -iwholename '*/warp/*' | xargs sed -i 's|metrics.NewRegistered|metrics.GetOrRegister|g' ``` All modified files that don't already import their `libevm` counterparts now `_` import them to force the initialisation order. The `libevm` construction with `NewRegistered*()` therefore always comes before the respective `GetOrRegister*()` so both call sites have the same metric instance. Metrics that we expect to be counters instead of timers are unregistered and newly created with the correct type, borrowing from ava-labs/libevm#159.
`geth` (and hence `libevm`) global metrics tend to be created with `NewRegistered*()`, which assumes that there are no name conflicts on the same `Registry`. If there are then the second call fails silently to register the new metric. Except for in `warp` (where there won't be any conflicts) metric registration is changed globally to use `GetOrRegister*()` instead of `NewRegistered*()`. With GNU tools (not the Mac budget replacements): ```shell find -iname '*.go' -not -iwholename '*/warp/*' | xargs sed -i 's|metrics.NewRegistered|metrics.GetOrRegister|g' ``` All modified files that don't already import their `libevm` counterparts now `_` import them to force the initialisation order. The `libevm` construction with `NewRegistered*()` therefore always comes before the respective `GetOrRegister*()` so both call sites have the same metric instance. Metrics that we expect to be counters instead of timers are unregistered and newly created with the correct type, borrowing from ava-labs/libevm#159.
`geth` (and hence `libevm`) global metrics tend to be created with `NewRegistered*()`, which assumes that there are no name conflicts on the same `Registry`. If there are then the second call fails silently to register the new metric. Except for in `warp` (where there won't be any conflicts) metric registration is changed globally to use `GetOrRegister*()` instead of `NewRegistered*()`. With GNU tools (not the Mac budget replacements): ```shell find -iname '*.go' -not -iwholename '*/warp/*' | xargs sed -i 's|metrics.NewRegistered|metrics.GetOrRegister|g' ``` All modified files that don't already import their `libevm` counterparts now `_` import them to force the initialisation order. The `libevm` construction with `NewRegistered*()` therefore always comes before the respective `GetOrRegister*()` so both call sites have the same metric instance. Metrics that we expect to be counters instead of timers are unregistered and newly created with the correct type, borrowing from ava-labs/libevm#159.
`geth` (and hence `libevm`) global metrics tend to be created with `NewRegistered*()`, which assumes that there are no name conflicts on the same `Registry`. If there are then the second call fails silently to register the new metric. Except for in `warp` (where there won't be any conflicts) metric registration is changed globally to use `GetOrRegister*()` instead of `NewRegistered*()`. With GNU tools (not the Mac budget replacements): ```shell find -iname '*.go' -not -iwholename '*/warp/*' | xargs sed -i 's|metrics.NewRegistered|metrics.GetOrRegister|g' ``` All modified files that don't already import their `libevm` counterparts now `_` import them to force the initialisation order. The `libevm` construction with `NewRegistered*()` therefore always comes before the respective `GetOrRegister*()` so both call sites have the same metric instance. Metrics that we expect to be counters instead of timers are unregistered and newly created with the correct type, borrowing from ava-labs/libevm#159. See original PR ava-labs/coreth#860
`geth` (and hence `libevm`) global metrics tend to be created with `NewRegistered*()`, which assumes that there are no name conflicts on the same `Registry`. If there are then the second call fails silently to register the new metric. Except for in `warp` (where there won't be any conflicts) metric registration is changed globally to use `GetOrRegister*()` instead of `NewRegistered*()`. With GNU tools (not the Mac budget replacements): ```shell find -iname '*.go' -not -iwholename '*/warp/*' | xargs sed -i 's|metrics.NewRegistered|metrics.GetOrRegister|g' ``` All modified files that don't already import their `libevm` counterparts now `_` import them to force the initialisation order. The `libevm` construction with `NewRegistered*()` therefore always comes before the respective `GetOrRegister*()` so both call sites have the same metric instance. Metrics that we expect to be counters instead of timers are unregistered and newly created with the correct type, borrowing from ava-labs/libevm#159. See original PR ava-labs/coreth#860
`geth` (and hence `libevm`) global metrics tend to be created with `NewRegistered*()`, which assumes that there are no name conflicts on the same `Registry`. If there are then the second call fails silently to register the new metric. Except for in `warp` (where there won't be any conflicts) metric registration is changed globally to use `GetOrRegister*()` instead of `NewRegistered*()`. With GNU tools (not the Mac budget replacements): ```shell find -iname '*.go' -not -iwholename '*/warp/*' | xargs sed -i 's|metrics.NewRegistered|metrics.GetOrRegister|g' ``` All modified files that don't already import their `libevm` counterparts now `_` import them to force the initialisation order. The `libevm` construction with `NewRegistered*()` therefore always comes before the respective `GetOrRegister*()` so both call sites have the same metric instance. Metrics that we expect to be counters instead of timers are unregistered and newly created with the correct type, borrowing from ava-labs/libevm#159. See original PR ava-labs/coreth#860
`geth` (and hence `libevm`) global metrics tend to be created with `NewRegistered*()`, which assumes that there are no name conflicts on the same `Registry`. If there are then the second call fails silently to register the new metric. Except for in `warp` (where there won't be any conflicts) metric registration is changed globally to use `GetOrRegister*()` instead of `NewRegistered*()`. With GNU tools (not the Mac budget replacements): ```shell find -iname '*.go' -not -iwholename '*/warp/*' | xargs sed -i 's|metrics.NewRegistered|metrics.GetOrRegister|g' ``` All modified files that don't already import their `libevm` counterparts now `_` import them to force the initialisation order. The `libevm` construction with `NewRegistered*()` therefore always comes before the respective `GetOrRegister*()` so both call sites have the same metric instance. Metrics that we expect to be counters instead of timers are unregistered and newly created with the correct type, borrowing from ava-labs/libevm#159. See original PR ava-labs/coreth#860
`geth` (and hence `libevm`) global metrics tend to be created with `NewRegistered*()`, which assumes that there are no name conflicts on the same `Registry`. If there are then the second call fails silently to register the new metric. Except for in `warp` (where there won't be any conflicts) metric registration is changed globally to use `GetOrRegister*()` instead of `NewRegistered*()`. With GNU tools (not the Mac budget replacements): ```shell find -iname '*.go' -not -iwholename '*/warp/*' | xargs sed -i 's|metrics.NewRegistered|metrics.GetOrRegister|g' ``` All modified files that don't already import their `libevm` counterparts now `_` import them to force the initialisation order. The `libevm` construction with `NewRegistered*()` therefore always comes before the respective `GetOrRegister*()` so both call sites have the same metric instance. Metrics that we expect to be counters instead of timers are unregistered and newly created with the correct type, borrowing from ava-labs/libevm#159. See original PR ava-labs/coreth#860
`geth` (and hence `libevm`) global metrics tend to be created with `NewRegistered*()`, which assumes that there are no name conflicts on the same `Registry`. If there are then the second call fails silently to register the new metric. Except for in `warp` (where there won't be any conflicts) metric registration is changed globally to use `GetOrRegister*()` instead of `NewRegistered*()`. With GNU tools (not the Mac budget replacements): ```shell find -iname '*.go' -not -iwholename '*/warp/*' | xargs sed -i 's|metrics.NewRegistered|metrics.GetOrRegister|g' ``` All modified files that don't already import their `libevm` counterparts now `_` import them to force the initialisation order. The `libevm` construction with `NewRegistered*()` therefore always comes before the respective `GetOrRegister*()` so both call sites have the same metric instance. Metrics that we expect to be counters instead of timers are unregistered and newly created with the correct type, borrowing from ava-labs/libevm#159. See original PR ava-labs/coreth#860
`geth` (and hence `libevm`) global metrics tend to be created with `NewRegistered*()`, which assumes that there are no name conflicts on the same `Registry`. If there are then the second call fails silently to register the new metric. Except for in `warp` (where there won't be any conflicts) metric registration is changed globally to use `GetOrRegister*()` instead of `NewRegistered*()`. With GNU tools (not the Mac budget replacements): ```shell find -iname '*.go' -not -iwholename '*/warp/*' | xargs sed -i 's|metrics.NewRegistered|metrics.GetOrRegister|g' ``` All modified files that don't already import their `libevm` counterparts now `_` import them to force the initialisation order. The `libevm` construction with `NewRegistered*()` therefore always comes before the respective `GetOrRegister*()` so both call sites have the same metric instance. Metrics that we expect to be counters instead of timers are unregistered and newly created with the correct type, borrowing from ava-labs/libevm#159. See original PR ava-labs/coreth#860
`geth` (and hence `libevm`) global metrics tend to be created with `NewRegistered*()`, which assumes that there are no name conflicts on the same `Registry`. If there are then the second call fails silently to register the new metric. Except for in `warp` (where there won't be any conflicts) metric registration is changed globally to use `GetOrRegister*()` instead of `NewRegistered*()`. With GNU tools (not the Mac budget replacements): ```shell find -iname '*.go' -not -iwholename '*/warp/*' | xargs sed -i 's|metrics.NewRegistered|metrics.GetOrRegister|g' ``` All modified files that don't already import their `libevm` counterparts now `_` import them to force the initialisation order. The `libevm` construction with `NewRegistered*()` therefore always comes before the respective `GetOrRegister*()` so both call sites have the same metric instance. Metrics that we expect to be counters instead of timers are unregistered and newly created with the correct type, borrowing from ava-labs/libevm#159. See original PR ava-labs/coreth#860
Why this should be merged
The alternative would be to change all occurrences of
metrics.New*bymetrics.GetOrRegister*in both the consumer code and in the libevm code (because it's unpredictable which one would register first), but that produces a lot more diffs.Just for historical purposes, I did try to have a custom registry on a consumer (coreth) for all metrics but:
How this works
metrics.New*function implementations to usemetrics.GetOrRegister*functions.GetOrRegisterOrOverrideCounterbecause counter metrics in consumers are defined as timer metrics in libevm, so consumers need to use this function when this happens.How this was tested
GetOrRegisterOrOverrideCounterneeds test