Skip to content
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

feat(storage): json downloads #7158

Merged
merged 21 commits into from
Feb 15, 2023
Merged

Conversation

BrennaEpp
Copy link
Contributor

No description provided.

@product-auto-label product-auto-label bot added size: l Pull request size is large. api: storage Issues related to the Cloud Storage API. labels Dec 12, 2022
@product-auto-label product-auto-label bot added the stale: old Pull request is old and needs attention. label Jan 12, 2023
storage/http_client.go Show resolved Hide resolved
storage/integration_test.go Show resolved Hide resolved
storage/integration_test.go Outdated Show resolved Hide resolved
storage/storage.go Show resolved Hide resolved
storage/storage.go Outdated Show resolved Hide resolved
storage/http_client.go Outdated Show resolved Hide resolved
call.Header().Set("Range", fmt.Sprintf("bytes=%d-%d", start, params.offset+params.length-1))
}
// We wait to assign conditions here because the generation number can change in between reopen() runs.
if err := applyConds("NewReader", params.gen, params.conds, call); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably add a test to verify that preconditions including ifGenerationNotMatch are passed through as expected

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added an integration test for the conditions on reader

storage/http_client.go Outdated Show resolved Hide resolved

// If a generation hasn't been specified, and this is the first response we get, let's record the
// generation. In future requests we'll use this generation as a precondition to avoid data races.
if params.gen < 0 && res.Header.Get("X-Goog-Generation") != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to get this from the header, or is it populated in the apiary response somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As we discussed the other day, it indeed must be from the header as apiary doesn't add it explicitly to the response anywhere.

reopen: reopen,
body: body,
},
}, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if it's possible to deduplicate some of this code with what you have for XML. I don't have a great idea of how to do this off the top of my head, but worth thinking about maybe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gave it a go at splitting it up, PTAL

@product-auto-label product-auto-label bot added size: xl Pull request size is extra large. and removed size: l Pull request size is large. labels Jan 30, 2023
Copy link
Contributor

@tritone tritone left a comment

Choose a reason for hiding this comment

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

Generally looking good, a few more minor things

storage/http_client.go Outdated Show resolved Hide resolved
storage/integration_test.go Outdated Show resolved Hide resolved
storage/integration_test.go Show resolved Hide resolved
storage/integration_test.go Outdated Show resolved Hide resolved
storage/integration_test.go Outdated Show resolved Hide resolved
storage/option.go Show resolved Hide resolved
storage/reader_test.go Show resolved Hide resolved
client.config.readAPIWasSet = false
client.config.useJSONforReads = false
}()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

In the !ok case we should return an error probably?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hm maybe, did we have a plan for running these tests with GRPC too?

storage/storage.go Show resolved Hide resolved
@BrennaEpp BrennaEpp marked this pull request as ready for review February 7, 2023 07:44
@BrennaEpp BrennaEpp requested review from a team as code owners February 7, 2023 07:44
@product-auto-label product-auto-label bot added stale: extraold Pull request is critically old and needs prioritization. and removed stale: old Pull request is old and needs attention. labels Feb 11, 2023
Copy link
Contributor

@tritone tritone left a comment

Choose a reason for hiding this comment

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

Couple more small things, in general the refactor looks good and I'm comfortable going ahead and merging this

storage/grpc_client.go Outdated Show resolved Hide resolved

// TestIntegration_JSONReaderConditions tests only JSON reads as some conditions
// do not work with XML.
func TestIntegration_JSONReaderConditions(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding this!

reopen := readerReopen(ctx, req.Header, params, s,
func() (*http.Response, error) { return c.hc.Do(req) },
func() error { return setConditionsHeaders(req.Header, params.conds) },
func(gen int64) { req.URL.RawQuery = fmt.Sprintf("generation=%d", params.gen) })
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the function gen int64 arg isn't actually needed/used, you can just remove it for clarity (and use params.gen directly for JSON as well).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API. size: xl Pull request size is extra large. stale: extraold Pull request is critically old and needs prioritization.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants