enix / x509-certificate-exporter

A Prometheus exporter to monitor x509 certificates expiration in Kubernetes clusters or standalone
MIT License
631 stars 64 forks source link

missing metric x509_cert_error for non-existent certificate file #312

Open r0bj opened 1 month ago

r0bj commented 1 month ago

I encountered an issue with the x509-certificate-exporter when using the --expose-per-cert-error-metrics option. The following configuration was set:

When the specified file is not present on the filesystem, the exporter logs the following warning:

level=warning msg="no certificate(s) found in "/path/to/certfile.crt"

According to the documentation, the metric x509_cert_error{filename="certfile.crt", filepath="/path/to/certfile.crt"} 1 should be exported, indicating the error. However, this metric is not being exported.

Steps to Reproduce:

  1. Configure the exporter with the following options:
    --expose-per-cert-error-metrics
    --watch-file /path/to/certfile.crt
  2. Ensure the file /path/to/certfile.crt does not exist on the filesystem.
  3. Check the exporter logs for the warning message.
  4. Verify if the metric x509_cert_error is being exported.

Expected Behavior: When the certificate file is not found, the exporter should log the warning and export the metric:

x509_cert_error{filename="certfile.crt", filepath="/path/to/certfile.crt"} 1

BTW, x509_read_errors metric should also be incremented on every certificate failed read attempt but it's not the case.

Actual Behavior: The warning message is logged, but the expected metric is not exported.

Environment: