feat(identity): register accounts and resend verification mail
This commit is contained in:
1 parent
5e202ac972
commit
4436f626a3
55 files changed
+3227
-88
No files matched your search
@@ -39,6 +39,10 @@ type mailMetrics struct {
|
||||
// senderCancelled counts deliveries that the sending worker ended without
|
||||
// sending, by cancel reason, a closed set from the domain.
|
||||
senderCancelled *client.CounterVec
|
||||
// identityRateLimited counts registration and resend requests that the
|
||||
// identity limiter refused, by scope: address or client. No address,
|
||||
// email, or key is ever a label.
|
||||
identityRateLimited *client.CounterVec
|
||||
}
|
||||
|
||||
// deliveryKinds and deliveryStatuses list the series that always exist, so a
|
||||
@@ -89,6 +93,10 @@ func newMailMetrics() mailMetrics {
|
||||
Name: "lincodex_mail_sender_cancelled_total",
|
||||
Help: "Deliveries that the mail sending worker of this process ended without sending, by cancel reason. content_invalid and processing_failed mean a broken row or a defect.",
|
||||
}, []string{"reason"}),
|
||||
identityRateLimited: client.NewCounterVec(client.CounterOpts{
|
||||
Name: "lincodex_identity_rate_limit_refusals_total",
|
||||
Help: "Registration and verification resend requests refused with 429 by the identity limiter, by scope: address (per email address) or client (per network address). A large share of client refusals hints at a broken proxy chain, where many clients share one address; a rise of address refusals can mean a targeted lockout of one address.",
|
||||
}, []string{"scope"}),
|
||||
senderRunning: client.NewGauge(client.GaugeOpts{
|
||||
Name: "lincodex_mail_sender_running",
|
||||
Help: "1 while the mail sending loop of this process runs, 0 while it does not, for example with EMAIL_PROVIDER=disabled or after shutdown began.",
|
||||
@@ -99,14 +107,32 @@ func newMailMetrics() mailMetrics {
|
||||
for _, reason := range domain.DeliveryCancelReasons() {
|
||||
metrics.senderCancelled.WithLabelValues(string(reason))
|
||||
}
|
||||
for _, scope := range []string{IdentityScopeAddress, IdentityScopeClient} {
|
||||
metrics.identityRateLimited.WithLabelValues(scope)
|
||||
}
|
||||
return metrics
|
||||
}
|
||||
|
||||
// The scopes of the identity rate limit refusal counter.
|
||||
const (
|
||||
IdentityScopeAddress = "address"
|
||||
IdentityScopeClient = "client"
|
||||
)
|
||||
|
||||
// ObserveIdentityRateLimited counts one refused identity request. A scope
|
||||
// outside the two known ones counts as address, so the label stays bounded.
|
||||
func (metrics *Metrics) ObserveIdentityRateLimited(scope string) {
|
||||
if scope != IdentityScopeClient {
|
||||
scope = IdentityScopeAddress
|
||||
}
|
||||
metrics.mail.identityRateLimited.WithLabelValues(scope).Inc()
|
||||
}
|
||||
|
||||
func (mail mailMetrics) collectors() []client.Collector {
|
||||
return []client.Collector{
|
||||
mail.deliveries, mail.oldestDuePendingAge, mail.lastSuccess,
|
||||
mail.quotaUsed, mail.quotaLimit, mail.quotaProviderExhausted,
|
||||
mail.senderRunning, mail.senderCancelled,
|
||||
mail.senderRunning, mail.senderCancelled, mail.identityRateLimited,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,3 +39,16 @@ func TestMetricsHandlerCountsCancelledMailByABoundedReason(t *testing.T) {
|
||||
t.Fatal("an arbitrary reason became a label")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIdentityRateLimitRefusalsAreCountedByBoundedScope(t *testing.T) {
|
||||
metrics := New()
|
||||
metrics.ObserveIdentityRateLimited(IdentityScopeClient)
|
||||
metrics.ObserveIdentityRateLimited(IdentityScopeAddress)
|
||||
metrics.ObserveIdentityRateLimited("203.0.113.9")
|
||||
body := scrape(t, metrics)
|
||||
requireSeries(t, body, `lincodex_identity_rate_limit_refusals_total{scope="client"} 1`)
|
||||
requireSeries(t, body, `lincodex_identity_rate_limit_refusals_total{scope="address"} 2`)
|
||||
if strings.Contains(body, "203.0.113.9") {
|
||||
t.Fatal("an unknown scope became a label value")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user