99
1010 "github.com/jmhodges/clock"
1111 "github.com/prometheus/client_golang/prometheus"
12+ "github.com/prometheus/client_golang/prometheus/promauto"
1213 "google.golang.org/grpc"
1314 "google.golang.org/protobuf/types/known/emptypb"
1415
@@ -25,19 +26,6 @@ import (
2526
2627const blockedKeysGaugeLimit = 1000
2728
28- var keysToProcess = prometheus .NewGauge (prometheus.GaugeOpts {
29- Name : "bad_keys_to_process" ,
30- Help : fmt .Sprintf ("A gauge of blockedKeys rows to process (max: %d)" , blockedKeysGaugeLimit ),
31- })
32- var keysProcessed = prometheus .NewCounterVec (prometheus.CounterOpts {
33- Name : "bad_keys_processed" ,
34- Help : "A counter of blockedKeys rows processed labelled by processing state" ,
35- }, []string {"state" })
36- var certsRevoked = prometheus .NewCounter (prometheus.CounterOpts {
37- Name : "bad_keys_certs_revoked" ,
38- Help : "A counter of certificates associated with rows in blockedKeys that have been revoked" ,
39- })
40-
4129// revoker is an interface used to reduce the scope of a RA gRPC client
4230// to only the single method we need to use, this makes testing significantly
4331// simpler
@@ -57,6 +45,9 @@ type badKeyRevoker struct {
5745 backoffFactor float64
5846 backoffTicker int
5947 maxExpectedReplicationLag time.Duration
48+ keysToProcess prometheus.Gauge
49+ keysProcessed * prometheus.CounterVec
50+ certsRevoked prometheus.Counter
6051}
6152
6253// uncheckedBlockedKey represents a row in the blockedKeys table
@@ -196,7 +187,7 @@ func (bkr *badKeyRevoker) revokeCerts(certs []unrevokedCertificate) error {
196187 if err != nil {
197188 return err
198189 }
199- certsRevoked .Inc ()
190+ bkr . certsRevoked .Inc ()
200191 }
201192 return nil
202193}
@@ -212,7 +203,7 @@ func (bkr *badKeyRevoker) invoke(ctx context.Context) (bool, error) {
212203
213204 // Set the gauge to the number of rows to be processed (max:
214205 // blockedKeysGaugeLimit).
215- keysToProcess .Set (float64 (uncheckedCount ))
206+ bkr . keysToProcess .Set (float64 (uncheckedCount ))
216207
217208 if uncheckedCount >= blockedKeysGaugeLimit {
218209 bkr .logger .AuditInfof ("found >= %d unchecked blocked keys left to process" , uncheckedCount )
@@ -324,21 +315,31 @@ func main() {
324315 config .BadKeyRevoker .DebugAddr = * debugAddr
325316 }
326317
327- scope , logger , oTelShutdown := cmd .StatsAndLogging (config .Syslog , config .OpenTelemetry , config .BadKeyRevoker .DebugAddr )
318+ stats , logger , oTelShutdown := cmd .StatsAndLogging (config .Syslog , config .OpenTelemetry , config .BadKeyRevoker .DebugAddr )
328319 defer oTelShutdown (context .Background ())
329320 logger .Info (cmd .VersionString ())
330321 clk := clock .New ()
331322
332- scope .MustRegister (keysProcessed )
333- scope .MustRegister (certsRevoked )
334-
335- dbMap , err := sa .InitWrappedDb (config .BadKeyRevoker .DB , scope , logger )
323+ keysToProcess := promauto .With (stats ).NewGauge (prometheus.GaugeOpts {
324+ Name : "bad_keys_to_process" ,
325+ Help : fmt .Sprintf ("A gauge of blockedKeys rows to process (max: %d)" , blockedKeysGaugeLimit ),
326+ })
327+ keysProcessed := promauto .With (stats ).NewCounterVec (prometheus.CounterOpts {
328+ Name : "bad_keys_processed" ,
329+ Help : "A counter of blockedKeys rows processed labelled by processing state" ,
330+ }, []string {"state" })
331+ certsRevoked := promauto .With (stats ).NewCounter (prometheus.CounterOpts {
332+ Name : "bad_keys_certs_revoked" ,
333+ Help : "A counter of certificates associated with rows in blockedKeys that have been revoked" ,
334+ })
335+
336+ dbMap , err := sa .InitWrappedDb (config .BadKeyRevoker .DB , stats , logger )
336337 cmd .FailOnError (err , "While initializing dbMap" )
337338
338- tlsConfig , err := config .BadKeyRevoker .TLS .Load (scope )
339+ tlsConfig , err := config .BadKeyRevoker .TLS .Load (stats )
339340 cmd .FailOnError (err , "TLS config" )
340341
341- conn , err := bgrpc .ClientSetup (config .BadKeyRevoker .RAService , tlsConfig , scope , clk )
342+ conn , err := bgrpc .ClientSetup (config .BadKeyRevoker .RAService , tlsConfig , stats , clk )
342343 cmd .FailOnError (err , "Failed to load credentials and create gRPC connection to RA" )
343344 rac := rapb .NewRegistrationAuthorityClient (conn )
344345
@@ -353,6 +354,9 @@ func main() {
353354 backoffIntervalBase : config .BadKeyRevoker .Interval .Duration ,
354355 backoffFactor : 1.3 ,
355356 maxExpectedReplicationLag : config .BadKeyRevoker .MaxExpectedReplicationLag .Duration ,
357+ keysToProcess : keysToProcess ,
358+ keysProcessed : keysProcessed ,
359+ certsRevoked : certsRevoked ,
356360 }
357361
358362 // If `BackoffIntervalMax` was not set via the config, set it to 60
0 commit comments