Repository navigation
Conversation
Add a shared pkg/util/profiling helper used by both binaries:
-pprof-address flag (env OPERATOR_PPROF_ADDRESS / METRICS_EXPORTER_PPROF_ADDRESS),
disabled by default, served from a dedicated mux on its own listener,
warning logged when enabled and when bound to a non-loopback address.
The metrics-exporter metrics/CHI-list listener now serves a private mux
instead of http.DefaultServeMux, so the net/http/pprof init() registration
never reaches port 8888 (the operator metrics port already did this).
Helm: operator.pprof.{enabled,address} and metrics.pprof.{enabled,address},
default off, generated via dev/generate_helm_chart.sh.
Fixes #2016
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s-exporter-pprof # Conflicts: # CHANGELOG.md
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix #2016
Summary
Adds an opt-in Go pprof endpoint to both
clickhouse-operatorandmetrics-exporter, so OOMs like the one in #2016 can be profiled. Both binaries use the same mechanism, from one shared helper (pkg/util/profiling):-pprof-address host:port. It is empty by default, which means disabled.OPERATOR_PPROF_ADDRESSandMETRICS_EXPORTER_PPROF_ADDRESS. The constants are inpkg/apis/deployment/env_vars.go. If both the flag and the env var are set, the flag wins.http.NewServeMux(). The handlers are registered explicitly:pprof.Index(which also serves heap, goroutine, allocs, block, mutex and threadcreate),Cmdline,Profile,SymbolandTrace. The server shuts down when the process context is cancelled.cmd/operator/app/main.go. The controller-runtime managers keepPprofBindAddressunset, which means disabled, so there is no second mechanism inside each manager./metrics+/chilistener(s) now serve a private mux instead ofhttp.DefaultServeMux. This is required becausenet/http/pprof'sinit()registers on DefaultServeMux, whether it is imported blank or named. The operator metrics port already had this fix (0.27.2). Both paths are still registered on one mux served by both listeners, so behaviour is unchanged when-metrics-endpointand-chi-list-endpointdiffer.How to enable
Helm:
Without Helm, set
OPERATOR_PPROF_ADDRESS/METRICS_EXPORTER_PPROF_ADDRESSin the containerenv, or pass-pprof-address. Both containers share the pod network, so they need different ports. The docs are indocs/monitoring_setup.md#profiling-the-operator-and-metrics-exporter-pprof, and the Helm README values table is regenerated.Security
clickhouse-operator-metricsService are unaffected: they return 404 for/debug/pprof/*, and tests check this.kubectl port-forward. Any other address logs a warning./chilistener, so the IPC Secure-mode middleware cannot be bypassed through it.Relation to #2017
#2017 was an earlier attempt at the same feature. Its review (#2017 (review)) is addressed as follows:
net/http/pprofimport registers on DefaultServeMux, which is served via anilhandler on 9999/8888 (info disclosure, DoS, IPC Secure-mode bypass)rest_server.gonow serves a private mux;operator/machinery.goalready did. pprof has its own listener. Tests check that both metrics muxes return 404 for/debug/pprof/*. As a precondition, they also check that DefaultServeMux does serve it, which provesnet/http/pprofis linked and the test means something.nilnet/http/pprofis kept, and the:8888/:9999servers use explicit non-nilmuxes.-debug/-fips-info-pprof-addressis empty by default, in both binaries. There is an env override (for the Helm and manifestenv) and Helm*.pprof.enabled: false.profile/traceunless separately gatedport-forwardorexecaccess to the pod.go build ./...,go vetandgo testpass on all touched packages (see the test plan).Test plan
go build ./...go veton./cmd/... ./pkg/metrics/... ./pkg/util/profiling ./pkg/apis/deploymentgo teston the same packages. New tests:pkg/util/profiling: flag/env precedence, loopback detection, every pprof route on the dedicated mux returns 200,Startserves and then shuts down on context cancel, an empty address does nothing.pkg/metrics/clickhouseandpkg/metrics/operator: the metrics mux serves/metrics(and/chi) and returns 404 for/debug/pprof/*; the pprof mux serves it.-hof both binaries lists-pprof-address.helm lintpasses. The defaulthelm templaterenders no*_PPROF_ADDRESS. Withoperator.pprof.enabled=true,metrics.pprof.enabled=trueboth env vars render, also alongside user-suppliedmetrics.env.dev/generate_helm_chart.sh(source changes are in the script,values.yamland the hand-maintainedvalues.schema.json). The local yq version also rewrote CRD files, adding!!merge/ blank-line differences unrelated to this change. Those were reverted, so only the Deployment template and the README come from the generator.port-forward.Pre-existing failures that this change does not touch:
pkg/controller/chi,pkg/controller/chkandpkg/controller/common/statefulsetdo not build because vet reports "non-constant format string".pkg/model/chbackupandpkg/model/clickhouse(TestEnforceVerifiedLegacyTLS) have failing tests.Fixes #2016
🤖 Generated with Claude Code