go-ethereum/p2p
Martin HS 9045b79bc2
metrics, cmd/geth: change init-process of metrics (#30814)
This PR modifies how the metrics library handles `Enabled`: previously,
the package `init` decided whether to serve real metrics or just
dummy-types.

This has several drawbacks: 
- During pkg init, we need to determine whether metrics are enabled or
not. So we first hacked in a check if certain geth-specific
commandline-flags were enabled. Then we added a similar check for
geth-env-vars. Then we almost added a very elaborate check for
toml-config-file, plus toml parsing.

- Using "real" types and dummy types interchangeably means that
everything is hidden behind interfaces. This has a performance penalty,
and also it just adds a lot of code.

This PR removes the interface stuff, uses concrete types, and allows for
the setting of Enabled to happen later. It is still assumed that
`metrics.Enable()` is invoked early on.

The somewhat 'heavy' operations, such as ticking meters and exp-decay,
now checks the enable-flag to prevent resource leak.

The change may be large, but it's mostly pretty trivial, and from the
last time I gutted the metrics, I ensured that we have fairly good test
coverage.

---------

Co-authored-by: Felix Lange <fjl@twurst.com>
2024-12-10 13:27:29 +01:00
..
discover metrics, cmd/geth: change init-process of metrics (#30814) 2024-12-10 13:27:29 +01:00
dnsdisc p2p/dnsdisc: using clear builtin func (#29418) 2024-04-04 12:19:48 +02:00
enode p2p/discover: fix flaky tests writing to test.log after completion (#30506) 2024-09-26 08:12:12 +02:00
enr p2p/enode: add quic ENR entry (#30283) 2024-09-13 23:47:18 +02:00
msgrate log: remove lazy, remove unused interfaces, unexport methods (#28622) 2023-12-05 11:54:44 +01:00
nat p2p/nat: return correct port for ExtIP NAT (#30234) 2024-07-27 10:18:05 +02:00
netutil p2p/netutil: unittests for addrutil (#30439) 2024-11-11 11:43:22 +01:00
pipes p2p/simulations: remove packages (#30250) 2024-08-12 10:36:48 +02:00
rlpx p2p/simulations: remove packages (#30250) 2024-08-12 10:36:48 +02:00
tracker metrics, cmd/geth: change init-process of metrics (#30814) 2024-12-10 13:27:29 +01:00
dial.go p2p: use netip.Addr where possible (#29891) 2024-06-05 19:31:04 +02:00
dial_test.go p2p: initialize maps with known size (#27229) 2023-05-10 10:52:26 +02:00
message.go p2p: use atomic types (#27764) 2023-08-01 23:20:52 +02:00
message_test.go p2p: move rlpx into separate package (#21464) 2020-09-22 10:17:39 +02:00
metrics.go metrics, cmd/geth: change init-process of metrics (#30814) 2024-12-10 13:27:29 +01:00
peer.go metrics, cmd/geth: change init-process of metrics (#30814) 2024-12-10 13:27:29 +01:00
peer_error.go p2p: use errors.Is for error comparison (#24882) 2022-06-07 17:27:21 +02:00
peer_test.go p2p: move rlpx into separate package (#21464) 2020-09-22 10:17:39 +02:00
protocol.go all: update golang/x/ext and fix slice sorting fallout (#27909) 2023-08-12 00:04:12 +02:00
server.go p2p: use package slices to sort in PeersInfo (#29957) 2024-06-09 22:50:22 +02:00
server_nat.go p2p: fix ip change log parameter (#30158) 2024-07-15 10:15:35 +02:00
server_nat_test.go p2p: fix flaky test TestServerPortMapping (#30241) 2024-07-30 07:31:27 -06:00
server_test.go cmd/bootnode, p2p: support for alternate mapped ports (#26359) 2023-07-14 14:58:27 +02:00
transport.go metrics, cmd/geth: change init-process of metrics (#30814) 2024-12-10 13:27:29 +01:00
transport_test.go p2p/simulations: remove packages (#30250) 2024-08-12 10:36:48 +02:00
util.go all: assign zero after resize in implementations of heap.Interface (#26296) 2022-12-05 13:49:54 +01:00
util_test.go p2p: new dial scheduler (#20592) 2020-02-13 11:10:03 +01:00