Skip to content

Commit de8401e

Browse files
authored
Add signature count and error metrics to crlImpl (#7533)
Add the "signatureCount" and "signErrorCount" metrics, which are already incremented by the certificateAuthorityImpl and ocspImpl after all signing operations, to the crlImpl. Note that in the process of writing this PR I discovered that the method for determining whether to increment the signErrorCount metric is broken. Rather than diverge the crlImpl's version of that code from the identical code in the other two files, I have duplicated the broken code and will fix it in all three places in a follow-up. Fixes #7532
1 parent 0eb87b8 commit de8401e

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

ca/ca_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ func setup(t *testing.T) *testCtx {
239239
},
240240
100,
241241
blog.NewMock(),
242+
signatureCount,
243+
signErrorCount,
242244
)
243245
test.AssertNotError(t, err, "Failed to create crl impl")
244246

ca/crl.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import (
1010

1111
"google.golang.org/grpc"
1212

13+
"github.com/miekg/pkcs11"
14+
"github.com/prometheus/client_golang/prometheus"
15+
1316
capb "github.com/letsencrypt/boulder/ca/proto"
1417
"github.com/letsencrypt/boulder/core"
1518
corepb "github.com/letsencrypt/boulder/core/proto"
@@ -20,10 +23,12 @@ import (
2023

2124
type crlImpl struct {
2225
capb.UnsafeCRLGeneratorServer
23-
issuers map[issuance.NameID]*issuance.Issuer
24-
profile *issuance.CRLProfile
25-
maxLogLen int
26-
log blog.Logger
26+
issuers map[issuance.NameID]*issuance.Issuer
27+
profile *issuance.CRLProfile
28+
maxLogLen int
29+
log blog.Logger
30+
signatureCount *prometheus.CounterVec
31+
signErrorCount *prometheus.CounterVec
2732
}
2833

2934
var _ capb.CRLGeneratorServer = (*crlImpl)(nil)
@@ -36,7 +41,10 @@ func NewCRLImpl(
3641
issuers []*issuance.Issuer,
3742
profileConfig issuance.CRLProfileConfig,
3843
maxLogLen int,
39-
logger blog.Logger) (*crlImpl, error) {
44+
logger blog.Logger,
45+
signatureCount *prometheus.CounterVec,
46+
signErrorCount *prometheus.CounterVec,
47+
) (*crlImpl, error) {
4048
issuersByNameID := make(map[issuance.NameID]*issuance.Issuer, len(issuers))
4149
for _, issuer := range issuers {
4250
issuersByNameID[issuer.NameID()] = issuer
@@ -48,10 +56,12 @@ func NewCRLImpl(
4856
}
4957

5058
return &crlImpl{
51-
issuers: issuersByNameID,
52-
profile: profile,
53-
maxLogLen: maxLogLen,
54-
log: logger,
59+
issuers: issuersByNameID,
60+
profile: profile,
61+
maxLogLen: maxLogLen,
62+
log: logger,
63+
signatureCount: signatureCount,
64+
signErrorCount: signErrorCount,
5565
}, nil
5666
}
5767

@@ -134,8 +144,13 @@ func (ci *crlImpl) GenerateCRL(stream grpc.BidiStreamingServer[capb.GenerateCRLR
134144

135145
crlBytes, err := issuer.IssueCRL(ci.profile, req)
136146
if err != nil {
147+
var pkcs11Error *pkcs11.Error
148+
if errors.As(err, &pkcs11Error) {
149+
ci.signErrorCount.WithLabelValues("HSM").Inc()
150+
}
137151
return fmt.Errorf("signing crl: %w", err)
138152
}
153+
ci.signatureCount.With(prometheus.Labels{"purpose": "crl", "issuer": issuer.Name()}).Inc()
139154

140155
hash := sha256.Sum256(crlBytes)
141156
ci.log.AuditInfof(

cmd/boulder-ca/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ func main() {
287287
c.CA.Issuance.CRLProfile,
288288
c.CA.OCSPLogMaxLength,
289289
logger,
290+
signatureCount,
291+
signErrorCount,
290292
)
291293
cmd.FailOnError(err, "Failed to create CRL impl")
292294

0 commit comments

Comments
 (0)