Skip to content

feat(metrics): prometheus compatible metrics endpoint - #176

Open
stevensbkang wants to merge 4 commits into
developfrom
feat/ks-52/prometheus-metrics-endpoint
Open

feat(metrics): prometheus compatible metrics endpoint#176
stevensbkang wants to merge 4 commits into
developfrom
feat/ks-52/prometheus-metrics-endpoint

Conversation

@stevensbkang

Copy link
Copy Markdown
Member

No description provided.

Replace the three static config-mirror gauges with a certificate
collector that reports the validity window of the kubesolo PKI.

container_mode, load_balancer_enabled and portainer_edge_enabled only
echoed flags back to the scraper and never changed after startup, so
they carried no operational signal. full_mode is removed for the same
reason plus a harder one: develop dropped Embedded.FullMode when --full
became a deprecated no-op, so the gauge no longer compiled.

In their place, certificate_expiry_timestamp_seconds and
certificate_valid cover ca, apiserver, controller-manager, kubelet,
admin, webhook and the request-header pair, plus the d2k server/client
certs when --d2k is set. Nothing upstream covers these:
apiserver_client_certificate_expiration_seconds measures client certs
presented to the apiserver rather than its own serving cert, and the
kubelet_certificate_manager_* gauges only register when kubelet runs a
rotating cert manager, which kubesolo does not.

Certificates are parsed at scrape time rather than cached at startup.
InvalidateIfIPChanged re-signs leaf certs on node IP change or expiry,
so a cached value would report the pre-rotation expiry until restart.
The cost is eight small file reads per scrape.

Expiry is an absolute timestamp rather than seconds-remaining so the
value does not decay between scrapes; compute the delta with
`- time()`. An unreadable or corrupt cert reports certificate_valid 0
instead of dropping both series, so the failure is visible without
absent() alerting.

Note ca and request-header-ca behave differently from the six leaf
certs: removeLeafCerts preserves both CA directories across
regeneration, so a CA nearing expiry needs manual intervention while a
leaf is self-healing. Alert thresholds should differ accordingly
@linear

linear Bot commented Jul 30, 2026

Copy link
Copy Markdown

KS-52

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

Note

PR image published: portainerci/kubesolo:pr-176

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds an optional Prometheus-compatible metrics endpoint to kubesolo, enabling operators to scrape a lightweight /metrics HTTP endpoint for control-plane component health, build info, certificate validity, and kine DB sizing.

Changes:

  • Introduces a new pkg/components/metrics component implementing an HTTP server, collectors, and periodic health probes.
  • Adds metrics configuration to types.Embedded plus defaults/constants for bind address, probe interval, and kine DB filename.
  • Wires new CLI flags and startup logic in cmd/kubesolo/main.go to enable/launch the metrics service.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
types/types.go Adds Metrics config to the embedded runtime configuration and defines MetricsConfig.
types/const.go Introduces defaults for metrics bind/probe interval and a shared kine DB filename constant.
pkg/components/metrics/service.go Defines the metrics service structure and constructor.
pkg/components/metrics/server.go Implements the /metrics + /healthz HTTP server lifecycle.
pkg/components/metrics/probe.go Implements component health probing (HTTP/TCP/file) and CoreDNS readiness via the Kubernetes API.
pkg/components/metrics/metrics.go Orchestrates registry creation, readiness watching, probing loop, and shutdown.
pkg/components/metrics/collectors.go Registers Prometheus collectors/gauges including build info, uptime, kine DB size, and component gauges.
pkg/components/metrics/certs.go Adds a scrape-time collector for certificate expiry/validity.
pkg/components/metrics/certs_test.go Adds unit tests for certificate parsing/collector behavior.
internal/config/flags/flags.go Adds --metrics-server and --metrics-bind-address flags (and env vars).
go.mod Promotes github.com/prometheus/client_golang to a direct dependency.
cmd/kubesolo/main.go Wires metrics config into Embedded and starts the metrics service during startup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/kubesolo/main.go
@stevensbkang stevensbkang changed the title feat(metrics): prometheud compatible metrics endpoint feat(metrics): prometheus compatible metrics endpoint Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants