Skip to content

Fix metrics implementation and add monitoring docs - #52

Merged
netops2devops merged 1 commit into
mainfrom
topic/metrics
Aug 13, 2026
Merged

Fix metrics implementation and add monitoring docs#52
netops2devops merged 1 commit into
mainfrom
topic/metrics

Conversation

@netops2devops

Copy link
Copy Markdown
Contributor
  • Fix config validation bug where Validate() wrote to an unused field, causing metrics to silently not start even when port and dataSource were configured

  • Remove dead metrics (certificatesRenewedTotal, acmeErrorsTotal) and fix double-registration against the default Prometheus registry by replacing promauto with explicit registry-scoped registration

  • Wire all previously defined-but-never-observed histograms (certificateRequestDuration, acmeRoundtripDuration, certificateExpirationTime) and lastSuccessfulCertificateTimestamp gauge at their correct call sites in CreateCertificate and RevokeCertificate

  • Add a background health probe for the external CA directory URL that sets externalcas_external_ca_up to 1 or 0 every 30 seconds (was permanently 0)

  • Register Go runtime and process collectors into the isolated registry so goroutines, GC, heap, CPU, and FD metrics appear on /metrics

  • Add contrib/develop/monitoring.md documenting the full metrics reference, Prometheus/Grafana setup on the test bridge network, PromQL organized by panel type, alert rules, and renewal detection approach

  • Add contrib/develop/grafana-dashboard.json, an importable Grafana 13 dashboard with five rows covering health overview, operation rates, latency percentiles, certificate inventory with expiry coloring, and Go runtime panels

  externalcas/config.go:
  - Fix Validate() writing to unused acmeProxyConfig.metricsEnabled field;
    now correctly sets Metrics.Enabled so StartMetricsServer gates on it
  - Remove the now-unused metricsEnabled bool field from acmeProxyConfig

  externalcas/metrics.go:
  - Remove certificatesRenewedTotal (renewal is indistinguishable from
    first issuance at the CAS plugin layer)
  - Remove acmeErrorsTotal (had no call sites)
  - Remove comment block referencing client hostname/IP/ACME client
    (not available at CAS layer)
  - Replace promauto.New* with prometheus.New* to eliminate silent
    double-registration against the default global registry
  - Isolate all metrics to a dedicated registry; register Go runtime
    (go_goroutines, GC, heap) and process (RSS, CPU, FDs) collectors
    into it so they appear on /metrics
  - Add runCAHealthProbe: probes caURL immediately on startup then every
    30s, sets externalcas_external_ca_up to 1 (2xx) or 0 (error/non-2xx)
  - StartMetricsServer now accepts caURL string to pass to the probe

  externalcas/external.go:
  - Observe certificateRequestDuration and acmeRoundtripDuration histograms
    on both success and failure paths of CreateCertificate and
    RevokeCertificate (were defined but never called)
  - Observe certificateExpirationTime (cert lifetime in seconds) on
    successful issuance
  - Call lastSuccessfulCertificateTimestamp.SetToCurrentTime() on
    successful issuance (was always 0)
  - Wrap ACME account registration calls to observe
    acmeRoundtripDuration{acme_operation="register"}
  - Pass cfg.CaURL into StartMetricsServer

  contrib/develop/monitoring.md:
  - Document setup of Prometheus and Grafana on acme-proxy-testbridge
  - Full metrics reference split into three sections: per-certificate
    custom collector, aggregate in-process metrics, Go runtime/process
  - PromQL organized by Grafana panel type across five dashboard rows
  - Alert rule expressions for CA down, cert expiry, failure rate, and
    no recent issuance
  - Notes on renewal detection via PromQL (count by CN/SAN - 1)

  contrib/develop/prometheus.yml:
  - Scrape config targeting acme-proxy.duckdns.org:9234

  contrib/develop/grafana-dashboard.json:
  - Importable Grafana dashboard with datasource template variable
  - Five rows: health overview (Stat), operations (time series),
    latency P50/P95/P99, certificate inventory (Table with
    color-coded days remaining), Go runtime panels

Signed-off-by: Kapil Agrawal <7047165+netops2devops@users.noreply.github.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 38 lines in your changes missing coverage. Please review.
✅ Project coverage is 44.17%. Comparing base (4dd5153) to head (842d000).

Files with missing lines Patch % Lines
externalcas/metrics.go 47.36% 20 Missing ⚠️
externalcas/external.go 0.00% 17 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #52      +/-   ##
==========================================
- Coverage   47.08%   44.17%   -2.92%     
==========================================
  Files           6        6              
  Lines         446      489      +43     
==========================================
+ Hits          210      216       +6     
- Misses        225      262      +37     
  Partials       11       11              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

@netops2devops netops2devops added fix Bug Fix enhancement New feature or request docs Improvements or additions to documentation and removed enhancement New feature or request labels Aug 13, 2026
@netops2devops
netops2devops merged commit 5d875a0 into main Aug 13, 2026
7 checks passed
@netops2devops
netops2devops deleted the topic/metrics branch August 19, 2026 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation fix Bug Fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants