-
Notifications
You must be signed in to change notification settings - Fork 511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add info logging for 400s, error for 500s, adjust timestamp error level on GetCurrent #798
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,7 @@ func atomicUpdateHandler(ctx context.Context, w http.ResponseWriter, r *http.Req | |
|
||
reader, err := r.MultipartReader() | ||
if err != nil { | ||
logger.Info("400 POST unable to parse TUF data") | ||
return errors.ErrMalformedUpload.WithDetail(nil) | ||
} | ||
var updates []storage.MetaUpdate | ||
|
@@ -71,8 +72,10 @@ func atomicUpdateHandler(ctx context.Context, w http.ResponseWriter, r *http.Req | |
} | ||
role := strings.TrimSuffix(part.FileName(), ".json") | ||
if role == "" { | ||
logger.Info("400 POST empty role") | ||
return errors.ErrNoFilename.WithDetail(nil) | ||
} else if !data.ValidRole(role) { | ||
logger.Infof("400 POST invalid role: %s", role) | ||
return errors.ErrInvalidRole.WithDetail(role) | ||
} | ||
meta := &data.SignedMeta{} | ||
|
@@ -81,6 +84,7 @@ func atomicUpdateHandler(ctx context.Context, w http.ResponseWriter, r *http.Req | |
dec := json.NewDecoder(io.TeeReader(part, inBuf)) | ||
err = dec.Decode(meta) | ||
if err != nil { | ||
logger.Info("400 POST malformed update JSON") | ||
return errors.ErrMalformedJSON.WithDetail(nil) | ||
} | ||
version := meta.Signed.Version | ||
|
@@ -94,6 +98,7 @@ func atomicUpdateHandler(ctx context.Context, w http.ResponseWriter, r *http.Req | |
if err != nil { | ||
serializable, serializableError := validation.NewSerializableError(err) | ||
if serializableError != nil { | ||
logger.Info("400 POST error validating update") | ||
return errors.ErrInvalidUpdate.WithDetail(nil) | ||
} | ||
return errors.ErrInvalidUpdate.WithDetail(serializable) | ||
|
@@ -102,6 +107,7 @@ func atomicUpdateHandler(ctx context.Context, w http.ResponseWriter, r *http.Req | |
if err != nil { | ||
// If we have an old version error, surface to user with error code | ||
if _, ok := err.(storage.ErrOldVersion); ok { | ||
logger.Info("400 POST old version error") | ||
return errors.ErrOldVersion.WithDetail(err) | ||
} | ||
// More generic storage update error, possibly due to attempted rollback | ||
|
@@ -124,13 +130,17 @@ func getHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, var | |
tufRole := vars["tufRole"] | ||
s := ctx.Value("metaStore") | ||
|
||
logger := ctxu.GetLoggerWithField(ctx, gun, "gun") | ||
|
||
store, ok := s.(storage.MetaStore) | ||
if !ok { | ||
logger.Error("500 GET: no storage exists") | ||
return errors.ErrNoStorage.WithDetail(nil) | ||
} | ||
|
||
lastModified, output, err := getRole(ctx, store, gun, tufRole, checksum) | ||
if err != nil { | ||
logger.Infof("404 GET %s role", tufRole) | ||
return err | ||
} | ||
if lastModified != nil { | ||
|
@@ -152,6 +162,7 @@ func DeleteHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) | |
s := ctx.Value("metaStore") | ||
store, ok := s.(storage.MetaStore) | ||
if !ok { | ||
logrus.Error("500 DELETE repository: no storage exists") | ||
return errors.ErrNoStorage.WithDetail(nil) | ||
} | ||
vars := mux.Vars(r) | ||
|
@@ -176,15 +187,18 @@ func GetKeyHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) | |
func getKeyHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { | ||
gun, ok := vars["imageName"] | ||
if !ok || gun == "" { | ||
logrus.Info("400 GET no gun in request") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we can for this one because we don't have the gun yet, but totally for the other Edit: actually we can just push up 194, the information in the log will be the same |
||
return errors.ErrUnknown.WithDetail("no gun") | ||
} | ||
|
||
logger := ctxu.GetLoggerWithField(ctx, gun, "gun") | ||
|
||
role, ok := vars["tufRole"] | ||
if !ok || role == "" { | ||
logger.Info("400 GET no role in request") | ||
return errors.ErrUnknown.WithDetail("no role") | ||
} | ||
|
||
logger := ctxu.GetLoggerWithField(ctx, gun, "gun") | ||
|
||
s := ctx.Value("metaStore") | ||
store, ok := s.(storage.MetaStore) | ||
if !ok || store == nil { | ||
|
@@ -215,7 +229,7 @@ func getKeyHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, | |
case data.CanonicalSnapshotRole: | ||
key, err = snapshot.GetOrCreateSnapshotKey(gun, store, crypto, keyAlgorithm) | ||
default: | ||
logger.Errorf("400 GET %s key: %v", role, err) | ||
logger.Infof("400 GET %s key: %v", role, err) | ||
return errors.ErrInvalidRole.WithDetail(role) | ||
} | ||
if err != nil { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ import ( | |
"net/http" | ||
"time" | ||
|
||
"github.com/Sirupsen/logrus" | ||
ctxu "github.com/docker/distribution/context" | ||
"github.com/docker/distribution/registry/api/errcode" | ||
"github.com/docker/distribution/registry/auth" | ||
|
@@ -79,9 +78,19 @@ func (root *rootHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |
ctx = authCtx | ||
} | ||
if err := root.handler(ctx, w, r); err != nil { | ||
if httpErr, ok := err.(errcode.ErrorCoder); ok { | ||
// info level logging for non-5XX http errors | ||
httpErrCode := httpErr.ErrorCode().Descriptor().HTTPStatusCode | ||
if (httpErrCode < http.StatusOK || httpErrCode >= http.StatusMultipleChoices) && httpErrCode < http.StatusInternalServerError { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't have an
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point, added! |
||
log.Info(httpErr) | ||
} else if httpErrCode >= http.StatusInternalServerError { | ||
// error level logging for 5XX http errors | ||
log.Error(httpErr) | ||
} | ||
} | ||
e := errcode.ServeJSON(w, err) | ||
if e != nil { | ||
logrus.Error(e) | ||
log.Error(e) | ||
} | ||
return | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be
logger.Error
? (would need to pull the logger out of the context like other handlers)