Skip to content

Commit

Permalink
Add basic stats interface
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandshoemaker authored and cbroglie committed Aug 29, 2018
1 parent 7e13f60 commit 33259b0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cli/ocspserve/ocspserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func ocspServerMain(args []string, c cli.Config) error {
}

log.Info("Registering OCSP responder handler")
http.Handle(c.Path, ocsp.NewResponder(src))
http.Handle(c.Path, ocsp.NewResponder(src, nil))

addr := fmt.Sprintf("%s:%d", c.Address, c.Port)
log.Info("Now listening on ", addr)
Expand Down
27 changes: 25 additions & 2 deletions ocsp/responder.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,25 @@ func NewSourceFromDB(DBConfigFile string) (Source, error) {
return src, nil
}

// Stats is a basic interface that allows users to record information
// about returned responses
type Stats interface {
ResponseStatus(ocsp.ResponseStatus)
}

// A Responder object provides the HTTP logic to expose a
// Source of OCSP responses.
type Responder struct {
Source Source
stats Stats
clk clock.Clock
}

// NewResponder instantiates a Responder with the give Source.
func NewResponder(source Source) *Responder {
func NewResponder(source Source, stats Stats) *Responder {
return &Responder{
Source: source,
stats: stats,
clk: clock.New(),
}
}
Expand Down Expand Up @@ -282,6 +290,9 @@ func (rs Responder) ServeHTTP(response http.ResponseWriter, request *http.Reques
log.Debugf("Error decoding request body: %s", b64Body)
response.WriteHeader(http.StatusBadRequest)
response.Write(malformedRequestErrorResponse)
if rs.stats != nil {
rs.stats.ResponseStatus(ocsp.Malformed)
}
return
}

Expand All @@ -292,20 +303,29 @@ func (rs Responder) ServeHTTP(response http.ResponseWriter, request *http.Reques
log.Infof("No response found for request: serial %x, request body %s",
ocspRequest.SerialNumber, b64Body)
response.Write(unauthorizedErrorResponse)
if rs.stats != nil {
rs.stats.ResponseStatus(ocsp.Unauthorized)
}
return
}
log.Infof("Error retrieving response for request: serial %x, request body %s, error: %s",
ocspRequest.SerialNumber, b64Body, err)
response.WriteHeader(http.StatusInternalServerError)
response.Write(internalErrorErrorResponse)
if rs.stats != nil {
rs.stats.ResponseStatus(ocsp.InternalError)
}
return
}

parsedResponse, err := ocsp.ParseResponse(ocspResponse, nil)
if err != nil {
log.Errorf("Error parsing response for serial %x: %s",
ocspRequest.SerialNumber, err)
response.Write(unauthorizedErrorResponse)
response.Write(internalErrorErrorResponse)
if rs.stats != nil {
rs.stats.ResponseStatus(ocsp.InternalError)
}
return
}

Expand Down Expand Up @@ -346,4 +366,7 @@ func (rs Responder) ServeHTTP(response http.ResponseWriter, request *http.Reques
}
response.WriteHeader(http.StatusOK)
response.Write(ocspResponse)
if rs.stats != nil {
rs.stats.ResponseStatus(ocsp.Success)
}
}
Binary file modified ocsp/testdata/sqlite_test.db
Binary file not shown.

0 comments on commit 33259b0

Please sign in to comment.