feat(metrics): prometheus compatible metrics endpoint - #176
Open
stevensbkang wants to merge 4 commits into
Open
Conversation
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
|
Note PR image published: |
There was a problem hiding this comment.
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/metricscomponent implementing an HTTP server, collectors, and periodic health probes. - Adds metrics configuration to
types.Embeddedplus defaults/constants for bind address, probe interval, and kine DB filename. - Wires new CLI flags and startup logic in
cmd/kubesolo/main.goto 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.
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.
No description provided.