Skip to content

Commit

Permalink
RA: Fix legacy override utilization metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
beautifulentropy committed Oct 30, 2023
1 parent 50ec478 commit ee548bc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
23 changes: 19 additions & 4 deletions ra/ra.go
Original file line number Diff line number Diff line change
Expand Up @@ -1423,17 +1423,32 @@ func (ra *RegistrationAuthorityImpl) enforceNameCounts(ctx context.Context, name
}

var badNames []string
var metricsData []struct {
overrideKey string
utilization float64
}

// Find the names that have counts at or over the threshold. Range
// over the names slice input to ensure the order of badNames will
// return the badNames in the same order they were input.
for _, name := range names {
threshold, overrideKey := limit.GetThreshold(name, regID)
if overrideKey != "" {
utilization := float64(response.Counts[name]) / float64(threshold)
ra.rlOverrideUsageGauge.WithLabelValues(ratelimit.CertificatesPerName, overrideKey).Set(utilization)
}
if response.Counts[name] >= threshold {
badNames = append(badNames, name)
} else if overrideKey != "" {
// Name is under threshold due to an override.
utilization := float64(response.Counts[name]) / float64(threshold)
metricsData = append(metricsData, struct {
overrideKey string
utilization float64
}{overrideKey, utilization})
}
}

if len(badNames) == 0 {
// All names were under the threshold, emit override utilization metrics.
for _, data := range metricsData {
ra.rlOverrideUsageGauge.WithLabelValues(ratelimit.CertificatesPerName, data.overrideKey).Set(data.utilization)
}
}
return badNames, response.Earliest.AsTime(), nil
Expand Down
6 changes: 3 additions & 3 deletions ratelimit/rate-limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
const (
// CertificatesPerName is the name of the CertificatesPerName rate limit
// when referenced in metric labels.
CertificatesPerName = "certificates_per_domain_per_account"
CertificatesPerName = "certificates_per_domain"

// RegistrationsPerIP is the name of the RegistrationsPerIP rate limit when
// referenced in metric labels.
Expand All @@ -33,11 +33,11 @@ const (

// CertificatesPerFQDNSet is the name of the CertificatesPerFQDNSet rate
// limit when referenced in metric labels.
CertificatesPerFQDNSet = "certificates_per_fqdn_set_per_account"
CertificatesPerFQDNSet = "certificates_per_fqdn_set"

// CertificatesPerFQDNSetFast is the name of the CertificatesPerFQDNSetFast
// rate limit when referenced in metric labels.
CertificatesPerFQDNSetFast = "certificates_per_fqdn_set_per_account_fast"
CertificatesPerFQDNSetFast = "certificates_per_fqdn_set_fast"

// NewOrdersPerAccount is the name of the NewOrdersPerAccount rate limit
// when referenced in metric labels.
Expand Down

0 comments on commit ee548bc

Please sign in to comment.