Skip to content

testing: replace legacy gopkg.in/check.v1 - #4185

Merged
milosgajdos merged 5 commits into
distribution:mainfrom
Juneezee:test/replace-gocheck
Dec 13, 2023
Merged

milosgajdos merged 5 commits into
distribution:mainfrom
Juneezee:test/replace-gocheck

Conversation

@Juneezee

@Juneezee Juneezee commented Dec 7, 2023

Copy link
Copy Markdown
Contributor

This PR replaces the legacy gopkg.in/check.v1 testing dependency with github.com/stretchr/testify.

Closes #3884.

Comment on lines 511 to +499
awriter, err := suite.StorageDriver.Writer(suite.ctx, filename, true)
c.Assert(err, check.IsNil)
suite.Require().NoError(err)

@Juneezee Juneezee Dec 7, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestWriteZeroByteStreamThenAppend is currently failing for S3 driver. The filename does exist but suite.StorageDriver.Writer returns s3aws: Path not found error.

=== RUN   TestS3DriverSuite/TestWriteZeroByteContentThenAppend
    testsuites.go:561: 
        	Error Trace:	/home/runner/work/distribution/distribution/registry/storage/driver/testsuites/testsuites.go:561
        	Error:      	Received unexpected error:
        	            	s3aws: Path not found: /kj90ph.80.nh8il2_o0_wieqfycj/u2
        	Test:       	TestS3DriverSuite/TestWriteZeroByteContentThenAppend

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Juneezee this looks to have this same root cause as the issue we resolved here: https://gitlab.com/gitlab-org/container-registry/-/merge_requests/20, namely:

The registry S3 storage driver uses multipart uploads for streaming. Multipart uploads require at least 1 chunk, so it doesn’t work for 0B files (0 chunks).

The same is true for instantiating the writer when append is set to true.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GitLab container registry "resolved" it by skipping a benchmark. This is a unit test. All the other storage drivers pass this test. Code which consumes the storage driver interface may therefore depend on the behaviour asserted by this test. The s3 driver is not upholding the contract, therefore the driver contains a bug which needs fixing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, S3 should conform to expectations here, the linked MR demonstrates a likely root cause, even if it wasn't addressed at the time.

@milosgajdos milosgajdos Dec 9, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've played around with this on my personal AWS account and it has revived an unpleasant AWS S3 memory for me 🫠

When you initiate a multipart upload to S3, it first creates an upload "record" but does not actually upload any object data. Those are uploaded as parts. So for an empty 0 byte file, no object content is uploaded, just the metadata for the initiated upload record is stored. We actually handle this edge case in the S3 driver by uploading an empty part. I'm wondering if that's actually the problem here, but I'm not sure 🤷‍♂️

What's happening inTestWriteZeroByteStreamThenAppend test is:

  1. We create a multipart upload when the non-appendMode writer is created:
    if !appendMode {
    // TODO (brianbland): cancel other uploads at this path
    resp, err := d.S3.CreateMultipartUploadWithContext(ctx, &s3.CreateMultipartUploadInput{
    Bucket: aws.String(d.Bucket),
    Key: aws.String(key),
    ContentType: d.getContentType(),
    ACL: d.getACL(),
    ServerSideEncryption: d.getEncryptionMode(),
    SSEKMSKeyId: d.getSSEKMSKeyID(),
    StorageClass: d.getStorageClass(),
    })
  2. We then commit and write the empty part (Commit and Close calls actually lead to this call
    _, err = w.driver.S3.CompleteMultipartUploadWithContext(w.ctx, &s3.CompleteMultipartUploadInput{
    )
  3. We then try to list multipart uploads when we create the appendMode writer here:
    resp, err := d.S3.ListMultipartUploadsWithContext(ctx, listMultipartUploadsInput)
    That call returns no Uploads because there are no pending uploads since the one we had created earlier has been successfully completed via the Commit. The Write call actually breaks here:
    if len(resp.Uploads) == 0 {
    break
    }
    which then ends up with the Not Found path error returned here:
    return nil, storagedriver.PathNotFoundError{Path: path}

I feel like I'm missing some S3 multipart uploads knowledge despite trawling through their docs. I wrote a simple Go program that verifies that completed uploads are not returned in the list multipart uploads, only the ongoing ones:
see this gist (just remove the svc.CompleteMultipartUploadWithContext call and you'll see your pending upload returned in the list call -- make sure you change the key to something that's not uploaded yet)

If this is really the correct behaviour then I struggle to see how the TestWriteZeroByteStreamThenAppend can ever pass 🤔 I also might be overlooking something, so more heads looking into this would be helpful 😄

@deleteriousEffect deleteriousEffect Dec 13, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the diff I pasted above, all tests pass. Can push to this branch once we've agreed on what we should return.

Nice! I would argue that the behavior of appending after commit is implementation dependent rather than "true" undefined behavior, so I'm in favor of an error specific to S3.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went with this: 4baddbc

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks good except for the comment mentioning ErrUnsupportedMethod: 4baddbc#diff-42ab115e8f2c28fa837e174c081ffe3542e13f5fbd58271f06b179c1123c7905R685

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arrrrgh, that was in the original code I never cleaned up after we discussed it. Ok should be fixed now 3f3e61e

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this LGTM 🚀

Comment thread configuration/parser_test.go Resolved

@corhere corhere left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

Comment thread registry/storage/driver/gcs/gcs_test.go Resolved
@Juneezee

Juneezee commented Dec 8, 2023

Copy link
Copy Markdown
Contributor Author

Thanks for all the helpful comments ❤️ !

@corhere corhere left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No skipping tests for a specific driver. The area of the s3 driver related to the failing test was recently touched: #4066. This failure is a real bug that needs fixing, and possibly a recent regression.

Comment thread registry/storage/driver/gcs/gcs_test.go Resolved
Comment on lines 511 to +499
awriter, err := suite.StorageDriver.Writer(suite.ctx, filename, true)
c.Assert(err, check.IsNil)
suite.Require().NoError(err)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GitLab container registry "resolved" it by skipping a benchmark. This is a unit test. All the other storage drivers pass this test. Code which consumes the storage driver interface may therefore depend on the behaviour asserted by this test. The s3 driver is not upholding the contract, therefore the driver contains a bug which needs fixing.

@Juneezee
Juneezee requested a review from corhere December 8, 2023 03:49
@Juneezee

Copy link
Copy Markdown
Contributor Author

I will rebase and resolve conflicts when this PR is ready to merge.

@milosgajdos

Copy link
Copy Markdown
Member

Arrrrrrrrrrgh conflicts

Juneezee and others added 4 commits December 13, 2023 09:22
This commit replaces the legacy `gopkg.in/check.v1` testing dependency
with `github.com/stretchr/testify`.

Closes #3884.

Signed-off-by: Eng Zer Jun <[email protected]>
This commit apply the following suggestions:

	1. #4185 (comment)
	2. #4185 (comment)
	3. #4185 (comment)
	4. #4185 (comment)

Signed-off-by: Eng Zer Jun <[email protected]>
This commit apply the following suggestions:

	1. #4185 (comment)
	2. #4185 (comment)
	3. #4185 (comment)
	4. #4185 (comment)

Signed-off-by: Eng Zer Jun <[email protected]>
This commit updates (writer).Writer() method in S3 storage driver to
handle the case where an append is attempted to a zer-size content.

S3 does not allow appending to already committed content, so we are
optiing to provide the following case as a narrowed down behaviour:
Writer can only append to zero byte content - in that case, a new S3
MultipartUpload is created that will be used for overriding the already
committed zero size content.

Appending to non-zero size content fails with error.

Co-authored-by: Cory Snider <[email protected]>
Signed-off-by: Milos Gajdos <[email protected]>
@milosgajdos

Copy link
Copy Markdown
Member

Alright, PTAL @corhere @deleteriousEffect @thaJeztah

@milosgajdos

Copy link
Copy Markdown
Member

@corhere we can't merge this without your approval. Anything you want to add to this?

@corhere corhere left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@milosgajdos
milosgajdos merged commit b8fb08e into distribution:main Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

testing: replace legacy gopkg.in/check.v1

4 participants