Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions server/etcdserver/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
"go.uber.org/zap"

"go.etcd.io/etcd/api/v3/version"
Expand Down Expand Up @@ -162,6 +163,10 @@ var (
)

func init() {
// register more extensive go runtime metrics, for that we need to unregister the default metrics first
prometheus.Unregister(collectors.NewGoCollector())
Copy link
Member

Choose a reason for hiding this comment

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

I haven't diged into the implementation of prometheus.Unregister, but you unregister a newly created objerct collectors.NewGoCollector() instead of the existing already registered one, are you sure it's correct?

Copy link
Contributor Author

@tjungblu tjungblu Jan 7, 2026

Choose a reason for hiding this comment

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

Yes. The registry works by the metric name, so it will list all the metric names and remove them. It doesn't refer to the metrics by their references or addresses.

The duplication logic that returns errors on duplicate registers also goes via names.

prometheus.MustRegister(collectors.NewGoCollector(collectors.WithGoCollectorRuntimeMetrics(collectors.MetricsAll)))

prometheus.MustRegister(hasLeader)
prometheus.MustRegister(isLeader)
prometheus.MustRegister(leaderChanges)
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ func TestNoMetricsMissing(t *testing.T) {
"etcd_snap_db_save_total_duration_seconds",
"etcd_snap_fsync_duration_seconds",
"go_gc_duration_seconds",
"go_gc_heap_allocs_by_size_bytes",
"go_gc_gogc_percent",
"go_gc_gomemlimit_bytes",
"go_goroutines",
Expand Down Expand Up @@ -244,6 +245,7 @@ func TestNoMetricsMissing(t *testing.T) {
"go_memstats_stack_sys_bytes",
"go_memstats_sys_bytes",
"go_sched_gomaxprocs_threads",
"go_sched_pauses_stopping_gc_seconds",
"go_threads",
"grpc_server_handled_total",
"grpc_server_msg_received_total",
Expand Down