From 5cff5230b4920ca886abeec5af47b5452684357d Mon Sep 17 00:00:00 2001 From: Shuaiyi Liu Date: Fri, 1 Sep 2023 23:20:57 +0000 Subject: [PATCH 1/2] Log ensureArtifact ConflictErr Signed-off-by: Shuaiyi Liu --- src/controller/artifact/controller.go | 1 + src/controller/artifact/controller_test.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/controller/artifact/controller.go b/src/controller/artifact/controller.go index 5a11a8e1ce6..4162bfdc616 100644 --- a/src/controller/artifact/controller.go +++ b/src/controller/artifact/controller.go @@ -227,6 +227,7 @@ func (c *controller) ensureArtifact(ctx context.Context, repository, digest stri if !errors.IsConflictErr(err) { return false, nil, err } + log.Debugf("failed to create artifact: %v", err) // if got conflict error, try to get the artifact again artifact, err = c.artMgr.GetByDigest(ctx, repository, digest) if err != nil { diff --git a/src/controller/artifact/controller_test.go b/src/controller/artifact/controller_test.go index 167dc84e537..ce58b5d280b 100644 --- a/src/controller/artifact/controller_test.go +++ b/src/controller/artifact/controller_test.go @@ -237,6 +237,21 @@ func (c *controllerTestSuite) TestEnsureArtifact() { c.Require().Nil(err) c.True(created) c.Equal(int64(1), art.ID) + + // reset the mock + c.SetupTest() + + // the artifact doesn't exist and get a conflict error on creating the artifact and fail to get again + c.repoMgr.On("GetByName", mock.Anything, mock.Anything).Return(&repomodel.RepoRecord{ + ProjectID: 1, + }, nil) + c.artMgr.On("GetByDigest", mock.Anything, mock.Anything, mock.Anything).Return(nil, errors.NotFoundError(nil)) + c.artMgr.On("Create", mock.Anything, mock.Anything).Return(int64(1), errors.ConflictError(nil)) + c.abstractor.On("AbstractMetadata").Return(nil) + created, art, err = c.ctl.ensureArtifact(orm.NewContext(nil, &ormtesting.FakeOrmer{}), "library/hello-world", digest) + c.Require().Error(err, errors.NotFoundError(nil)) + c.False(created) + c.Require().Nil(art) } func (c *controllerTestSuite) TestEnsure() { From e273496a4119314fd53af340692e262ca4f5033e Mon Sep 17 00:00:00 2001 From: Shuaiyi Liu Date: Fri, 1 Sep 2023 23:20:57 +0000 Subject: [PATCH 2/2] Log ensureArtifact ConflictErr Signed-off-by: Shuaiyi Liu --- src/controller/artifact/controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controller/artifact/controller.go b/src/controller/artifact/controller.go index 4162bfdc616..0e710c064ee 100644 --- a/src/controller/artifact/controller.go +++ b/src/controller/artifact/controller.go @@ -227,7 +227,7 @@ func (c *controller) ensureArtifact(ctx context.Context, repository, digest stri if !errors.IsConflictErr(err) { return false, nil, err } - log.Debugf("failed to create artifact: %v", err) + log.Debugf("failed to create artifact %s@%s: %v", repository, digest, err) // if got conflict error, try to get the artifact again artifact, err = c.artMgr.GetByDigest(ctx, repository, digest) if err != nil {