From 7dcbf69536eba2d7133067c56e959873f00b4d0b Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Fri, 20 May 2022 19:44:13 -0700 Subject: [PATCH] Add sendDelay metric (#6130) Fixes #6125 --- cmd/expiration-mailer/main.go | 16 ++++++++++++++++ cmd/expiration-mailer/main_test.go | 2 ++ 2 files changed, 18 insertions(+) diff --git a/cmd/expiration-mailer/main.go b/cmd/expiration-mailer/main.go index 48ca31349..a286ed05f 100644 --- a/cmd/expiration-mailer/main.go +++ b/cmd/expiration-mailer/main.go @@ -58,6 +58,7 @@ type mailer struct { } type mailerStats struct { + sendDelay *prometheus.GaugeVec nagsAtCapacity *prometheus.GaugeVec errorCount *prometheus.CounterVec sendLatency prometheus.Histogram @@ -389,6 +390,12 @@ func (m *mailer) findExpiringCertificates(ctx context.Context) error { continue // nothing to do } + // Report the send delay metric. Note: this is the worst-case send delay + // of any certificate in this batch because it's based on the first (oldest). + sendDelay := expiresIn - certs[0].Expires.Sub(m.clk.Now()) + m.stats.sendDelay.With(prometheus.Labels{"nag_group": expiresIn.String()}).Set( + float64(sendDelay.Truncate(time.Second).Seconds())) + processingStarted := m.clk.Now() err = m.processCerts(ctx, certs) if err != nil { @@ -455,6 +462,14 @@ type Config struct { } func initStats(stats prometheus.Registerer) mailerStats { + sendDelay := prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "send_delay", + Help: "For the last batch of certificates, difference between the idealized send time and actual send time. Will always be nonzero, bigger numbers are worse", + }, + []string{"nag_group"}) + stats.MustRegister(sendDelay) + nagsAtCapacity := prometheus.NewGaugeVec( prometheus.GaugeOpts{ Name: "nags_at_capacity", @@ -510,6 +525,7 @@ func initStats(stats prometheus.Registerer) mailerStats { stats.MustRegister(accountsNeedingMail) return mailerStats{ + sendDelay: sendDelay, nagsAtCapacity: nagsAtCapacity, errorCount: errorCount, sendLatency: sendLatency, diff --git a/cmd/expiration-mailer/main_test.go b/cmd/expiration-mailer/main_test.go index 8b2ee87ea..be4362990 100644 --- a/cmd/expiration-mailer/main_test.go +++ b/cmd/expiration-mailer/main_test.go @@ -338,6 +338,8 @@ func TestFindExpiringCertificates(t *testing.T) { err = testCtx.m.findExpiringCertificates(context.Background()) test.AssertNotError(t, err, "Failed to find expiring certs") test.AssertEquals(t, len(testCtx.mc.Messages), 0) + test.AssertMetricWithLabelsEquals(t, testCtx.m.stats.sendDelay, prometheus.Labels{"nag_group": "48h0m0s"}, 90000) + test.AssertMetricWithLabelsEquals(t, testCtx.m.stats.sendDelay, prometheus.Labels{"nag_group": "192h0m0s"}, 82800) } func makeRegistration(sac sapb.StorageAuthorityClient, id int64, jsonKey []byte, contacts []string) (*corepb.Registration, error) {