Skip to content

Expose all Go runtime metrics on /metrics - #22248

Merged
ahrtr merged 1 commit into
etcd-io:mainfrom
Jefftree:go-runtime-metrics
Aug 13, 2026
Merged

Expose all Go runtime metrics on /metrics#22248
ahrtr merged 1 commit into
etcd-io:mainfrom
Jefftree:go-runtime-metrics

Conversation

@Jefftree

@Jefftree Jefftree commented Aug 5, 2026

Copy link
Copy Markdown
Member

Turns on all the Go runtime/metrics instead of the three the default collector enables, which gives us scheduler latency, mutex contention and GC CPU share for tracking down etcd bottlenecks. 35 -> 224 series.

client_golang registers its own Go collector into the default registry at init, so reconfiguring it means dropping that one first. This is the same pattern as client_golang's own example, prometheus and coredns.

Kubernetes turned the full set on in kubernetes/kubernetes#111910.

Disclaimer: I'm most interested in go_gc_heap_live_bytes out of the list, but it seems like providing the overall list is a net improvement overall.

@Jefftree

Jefftree commented Aug 5, 2026

Copy link
Copy Markdown
Member Author

/cc @ahrtr @fuweid @serathius @ivanvc

Noticed this while working on kubernetes scalability measurements. I think this could also help with etcd specific benchmarking?

@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 8.33333% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.67%. Comparing base (faafe77) to head (390688e).

Files with missing lines Patch % Lines
server/etcdserver/metrics.go 0.00% 9 Missing ⚠️
server/embed/etcd.go 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
server/embed/config.go 79.46% <100.00%> (ø)
server/embed/etcd.go 75.90% <0.00%> (-0.27%) ⬇️
server/etcdserver/metrics.go 67.27% <0.00%> (-13.17%) ⬇️

... and 19 files with indirect coverage changes

@@            Coverage Diff             @@
##             main   #22248      +/-   ##
==========================================
- Coverage   69.71%   69.67%   -0.04%     
==========================================
  Files         449      449              
  Lines       38187    38198      +11     
==========================================
- Hits        26622    26615       -7     
- Misses      10141    10156      +15     
- Partials     1424     1427       +3     

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update faafe77...390688e. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@serathius serathius left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

High level makes sense as K8s enabled it

cc @ahrtr @fuweid

Comment on lines +30 to +36
func init() {
if prometheus.Unregister(collectors.NewGoCollector()) {
prometheus.MustRegister(collectors.NewGoCollector(
collectors.WithGoCollectorRuntimeMetrics(collectors.MetricsAll),
))
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Any applications that import the package or even etcd embed package (e.g. embedded use cases, because the embed imports etcdhttp) will automatically add all these metrics. Would be better to guard it under the existing --metrics extensive (preferred) or a new flag something like --metrics-runtime-all.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1 to include this by extensive

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

sounds good, folded behind the --metrics extensive flag.

@kubernetes-prow kubernetes-prow Bot added size/L and removed size/M labels Aug 6, 2026
@Jefftree
Jefftree force-pushed the go-runtime-metrics branch 3 times, most recently from d50c40a to 9ff1918 Compare August 6, 2026 14:26
@Jefftree

Jefftree commented Aug 6, 2026

Copy link
Copy Markdown
Member Author

/retest

@ivanvc ivanvc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM after being guarded by --metrics extensive. Thanks.

// EnableAllRuntimeMetrics swaps client_golang's default Go collector for one
// exposing the full runtime/metrics set (scheduler latency, mutex contention,
// GC CPU share).
func EnableAllRuntimeMetrics(lg *zap.Logger) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

server/etcdserver/metrics.go should be a better place to add this function

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

moved.

Signed-off-by: Jefftree <jeffrey.ying86@live.com>
@Jefftree
Jefftree force-pushed the go-runtime-metrics branch from 879890b to 390688e Compare August 12, 2026 22:53
@Jefftree

Copy link
Copy Markdown
Member Author

/retest

@ahrtr
ahrtr merged commit 214d0ff into etcd-io:main Aug 13, 2026
34 checks passed
@kubernetes-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ahrtr, ivanvc, Jefftree, serathius

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [ahrtr,ivanvc,serathius]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

5 participants