Skip to content

caddytls: add certificate operation and on-demand ask metrics - #8186

Open
IslamElsayed wants to merge 2 commits into
caddyserver:masterfrom
IslamElsayed:tls-metrics
Open

IslamElsayed wants to merge 2 commits into
caddyserver:masterfrom
IslamElsayed:tls-metrics

Conversation

@IslamElsayed

@IslamElsayed IslamElsayed commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1683: the two counters from the agreed contract. The expiry gauge follows once the CertMagic method it needs is released (caddyserver/certmagic#413).

caddy_tls_certificate_operations_total{operation, issuer, result, error_type}
caddy_tls_on_demand_ask_total{result}
  • operation is obtain or renew, and result is success or failure. On failure, error_type comes from the ACME problem type: rate_limited, challenge_failed (connection, dns, unauthorized, incorrectResponse, tls, caa) or other.
  • issuer is the configured issuer's key. On a failure it's the last issuer tried, whose error is the one returned.
  • The ask counter records allowed, denied or error for every call to the on-demand permission module.
  • No certificate name, SAN, account or ask URL is used as a label.
  • The collectors are created once per process, so counts carry across reloads, and are registered unconditionally with each config's registry.

The counters are fed by the cert_obtained and cert_failed events through onEvent, and are counted before the events app's Emit decides whether anything observes them. On ShouldEmit: CertMagic currently consults ShouldEmitFunc only for tls_get_certificate, so these events already reach onEvent either way. The tls app now reports them as wanted anyway, so the metrics keep working if CertMagic starts gating them.

Tested with unit tests, and with a caddy binary at INFO log level:

  • local_certs: {operation="obtain",issuer="local",result="success"} 1
  • an unreachable ACME CA: {operation="obtain",issuer="127.0.0.1:1-directory",result="failure",error_type="other"} 1
  • on-demand TLS with an ask endpoint: one allowed and one denied

(I used AI assistance, Claude, while preparing this; I reviewed and tested it myself.)

Adds two counters to the tls app, for caddyserver#1683:

    caddy_tls_certificate_operations_total{operation, issuer, result, error_type}
    caddy_tls_on_demand_ask_total{result}

operation is obtain or renew, result is success or failure, and
error_type categorizes a failure by its ACME problem type as
challenge_failed, rate_limited or other. issuer is the configured
issuer's key; on a failure it is the last issuer tried, whose error is
the one returned. The ask counter records allowed, denied or error for
every call to the on-demand permission module. No certificate name,
SAN, account or ask URL is used as a label, since with on-demand TLS
those are chosen by clients.

The counters are fed by the cert_obtained and cert_failed events
CertMagic emits through onEvent, and are counted before the events app
decides whether anything observes them. The tls app also reports these
events as wanted through ShouldEmitFunc, so the metrics keep working
even if CertMagic starts gating them. The collectors are created once
per process and registered unconditionally with each config's registry.
Comment thread modules/caddytls/metrics_test.go Outdated
Exercise TLS.onEvent and the on-demand permission callback built by makeCertMagicConfig, and assert the counter deltas, instead of calling the observers directly.
@steadytao steadytao added the feature ⚙️ New feature or request label Oct 10, 2026
@steadytao steadytao added this to the v2.12.0 milestone Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature ⚙️ New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants