Skip to content

Commit

Permalink
publisher: add label to CT log error metric for http status code (#4391)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandshoemaker authored and Daniel McCarney committed Aug 8, 2019
1 parent 652cb6b commit 62db2d0
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
16 changes: 11 additions & 5 deletions publisher/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func initMetrics(stats metrics.Scope) *pubMetrics {
Help: "Time taken to submit a certificate to a CT log",
Buckets: metrics.InternetFacingBuckets,
},
[]string{"log", "status"},
[]string{"log", "status", "httpStatus"},
)
stats.MustRegister(submissionLatency)

Expand Down Expand Up @@ -306,15 +306,21 @@ func (pub *Impl) singleLogSubmit(
if canceled.Is(err) {
status = "canceled"
}
httpStatus := ""
if rspError, ok := err.(ctClient.RspError); ok && rspError.StatusCode != 0 {
httpStatus = fmt.Sprintf("%d", rspError.StatusCode)
}
pub.metrics.submissionLatency.With(prometheus.Labels{
"log": ctLog.uri,
"status": status,
"log": ctLog.uri,
"status": status,
"httpStatus": httpStatus,
}).Observe(took)
return nil, err
}
pub.metrics.submissionLatency.With(prometheus.Labels{
"log": ctLog.uri,
"status": "success",
"log": ctLog.uri,
"status": "success",
"httpStatus": "",
}).Observe(took)

// Generate log entry so we can verify the signature in the returned SCT
Expand Down
48 changes: 48 additions & 0 deletions publisher/publisher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"time"

ct "github.com/google/certificate-transparency-go"
"github.com/prometheus/client_golang/prometheus"

blog "github.com/letsencrypt/boulder/log"
"github.com/letsencrypt/boulder/metrics"
Expand Down Expand Up @@ -432,3 +433,50 @@ func TestLogErrorBody(t *testing.T) {
test.AssertError(t, err, "SubmitToSingleCTWithResult didn't fail")
test.AssertEquals(t, len(log.GetAllMatching("well this isn't good now is it")), 1)
}

func TestHTTPStatusMetric(t *testing.T) {
pub, leaf, k := setup(t)

badSrv := errorBodyLogSrv()
defer badSrv.Close()
port, err := getPort(badSrv.URL)
test.AssertNotError(t, err, "Failed to get test server port")
logURI := fmt.Sprintf("http://localhost:%d", port)

pkDER, err := x509.MarshalPKIXPublicKey(&k.PublicKey)
test.AssertNotError(t, err, "Failed to marshal key")
pkB64 := base64.StdEncoding.EncodeToString(pkDER)
_, err = pub.SubmitToSingleCTWithResult(context.Background(), &pubpb.Request{
LogURL: &logURI,
LogPublicKey: &pkB64,
Der: leaf.Raw,
})
test.AssertError(t, err, "SubmitToSingleCTWithResult didn't fail")
test.AssertEquals(t, test.CountHistogramSamples(pub.metrics.submissionLatency.With(prometheus.Labels{
"log": logURI,
"status": "error",
"httpStatus": "400",
})), 1)

pub, leaf, k = setup(t)
pkDER, err = x509.MarshalPKIXPublicKey(&k.PublicKey)
test.AssertNotError(t, err, "Failed to marshal key")
pkB64 = base64.StdEncoding.EncodeToString(pkDER)
workingSrv := logSrv(k)
defer workingSrv.Close()
port, err = getPort(workingSrv.URL)
test.AssertNotError(t, err, "Failed to get test server port")
logURI = fmt.Sprintf("http://localhost:%d", port)

_, err = pub.SubmitToSingleCTWithResult(context.Background(), &pubpb.Request{
LogURL: &logURI,
LogPublicKey: &pkB64,
Der: leaf.Raw,
})
test.AssertNotError(t, err, "SubmitToSingleCTWithResult failed")
test.AssertEquals(t, test.CountHistogramSamples(pub.metrics.submissionLatency.With(prometheus.Labels{
"log": logURI,
"status": "success",
"httpStatus": "",
})), 1)
}

0 comments on commit 62db2d0

Please sign in to comment.