Skip to content

Metrics are not updated with newly added ct logs #96

@d-Rickyy-b

Description

@d-Rickyy-b

Discussed in #95

Originally posted by NBouchia February 24, 2026

The Gauge metrics certstreamservergo_certs_by_log_total are initialized only once (global boolean ctLogMetricsInitialized) and does not get updated when new URLs are added to Google’s log_list.json. Is that an accurate interpretation of the code?

internal/metrics/prometheus.go

// WritePrometheus provides an easy way to write metrics to a writer.
func WritePrometheus(w io.Writer, exposeProcessMetrics bool) {
	ctLogMetricsInitMutex.Lock()
	if !ctLogMetricsInitialized {
		initCtLogMetrics()
	}
	ctLogMetricsInitMutex.Unlock()

	getSkippedCertMetrics()

	metrics.WritePrometheus(w, exposeProcessMetrics)
}

// For having metrics regarding each individual CT log, we need to register them manually.
// initCtLogMetrics fetches all the CT Logs and registers one metric per log.
func initCtLogMetrics() {
	logs := certificatetransparency.GetLogOperators()

	for operator, urls := range logs {
		operator := operator // Copy variable to new scope

		for i := 0; i < len(urls); i++ {
			url := urls[i]
			name := fmt.Sprintf("certstreamservergo_certs_by_log_total{url=\"%s\",operator=\"%s\"}", url, operator)
			metrics.NewGauge(name, func() float64 {
				return float64(getCertCountForLog(operator, url))
			})
		}
	}

	if len(logs) > 0 {
		ctLogMetricsInitialized = true
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions