cloudapi: Add extra logging & improve existing

Use different logging levels depending on situation
Log HTTP 5xx errors to stdout with internal error details when possible
This commit is contained in:
Diaa Sami 2021-09-22 17:39:53 +02:00 committed by Sanne Raymaekers
parent 179009fec4
commit 27ca55372a
2 changed files with 17 additions and 7 deletions

View file

@ -219,7 +219,14 @@ func (s *Server) HTTPErrorHandler(echoError error, c echo.Context) {
apiErr := APIError(code, sec, c)
if sec.httpStatus == http.StatusInternalServerError {
c.Logger().Errorf("Internal server error. Code: %s, OperationId: %s", apiErr.Code, apiErr.OperationId)
internalError, ok := echoError.(*echo.HTTPError)
errMsg := fmt.Sprintf("Internal server error. Code: %s, OperationId: %s", apiErr.Code, apiErr.OperationId)
if ok {
errMsg += fmt.Sprintf(", InternalError: %v", internalError)
}
c.Logger().Error(errMsg)
}
if c.Request().Method == http.MethodHead {
@ -237,6 +244,7 @@ func (s *Server) HTTPErrorHandler(echoError error, c echo.Context) {
he, ok := echoError.(*echo.HTTPError)
if !ok {
c.Logger().Errorf("ErrorNotHTTPError %v", echoError)
doResponse(ErrorNotHTTPError, c)
return
}

View file

@ -147,7 +147,7 @@ func (h *apiHandlers) PostCompose(ctx echo.Context) error {
var bp = blueprint.Blueprint{}
err = bp.Initialize()
if err != nil {
return HTTPError(ErrorFailedToInitializeBlueprint)
return HTTPErrorWithInternal(ErrorFailedToInitializeBlueprint, err)
}
if request.Customizations != nil && request.Customizations.Packages != nil {
for _, p := range *request.Customizations.Packages {
@ -235,7 +235,7 @@ func (h *apiHandlers) PostCompose(ctx echo.Context) error {
imageOptions.OSTree.URL = *ostreeOptions.Url
parent, err = ostree.ResolveRef(imageOptions.OSTree.URL, imageOptions.OSTree.Ref)
if err != nil {
return HTTPError(ErrorInvalidOSTreeRepo)
return HTTPErrorWithInternal(ErrorInvalidOSTreeRepo, err)
}
imageOptions.OSTree.Parent = parent
}
@ -266,7 +266,7 @@ func (h *apiHandlers) PostCompose(ctx echo.Context) error {
manifest, err := imageType.Manifest(blueprintCustoms, imageOptions, repositories, pkgSpecSets, manifestSeed)
if err != nil {
return HTTPError(ErrorFailedToMakeManifest)
return HTTPErrorWithInternal(ErrorFailedToMakeManifest, err)
}
imageRequests[i].manifest = manifest
@ -411,9 +411,11 @@ func (h *apiHandlers) PostCompose(ctx echo.Context) error {
Exports: ir.exports,
})
if err != nil {
return HTTPError(ErrorEnqueueingJob)
return HTTPErrorWithInternal(ErrorEnqueueingJob, err)
}
ctx.Logger().Infof("Job ID %s enqueued for operationID %s", id, ctx.Get("operationID"))
return ctx.JSON(http.StatusCreated, &ComposeId{
ObjectReference: ObjectReference{
Href: "/api/composer/v2/compose",
@ -530,12 +532,12 @@ func (h *apiHandlers) GetComposeMetadata(ctx echo.Context, id string) error {
var result worker.OSBuildJobResult
status, _, err := h.server.workers.JobStatus(jobId, &result)
if err != nil {
return HTTPError(ErrorComposeNotFound)
return HTTPErrorWithInternal(ErrorComposeNotFound, err)
}
var job worker.OSBuildJob
if _, _, _, err = h.server.workers.Job(jobId, &job); err != nil {
return HTTPError(ErrorComposeNotFound)
return HTTPErrorWithInternal(ErrorComposeNotFound, err)
}
if status.Finished.IsZero() {