feat(datastore): add support for request tags#13732
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for passing and merging RequestOptions (such as request tags) in Datastore queries and aggregation queries, allowing both instance-level and request-level tags to be propagated. The feedback highlights a critical issue where instance-level tags are ignored when query-level RequestOptions are not explicitly provided in QueryResultsImpl and AggregationQueryRequestProtoPreparer. Additionally, the reviewer suggests simplifying the varargs withRequestTags overload in Datastore by delegating to the List version, and adding a test case to verify that instance-level tags are correctly populated and sent with queries.
f124116 to
aab1fd3
Compare
|
ci / lint is failing. Could you please take a look? |
Fixed |
ae79a99 to
d61b477
Compare
d61b477 to
75e872b
Compare
| */ | ||
| @BetaApi | ||
| Transaction newTransaction( | ||
| TransactionOptions options, DatastoreExecutionOptions executionOptions); |
There was a problem hiding this comment.
Thanks for being open for using DatastoreExecutionOptions. IIRC, the original commits only needed RequestOptions for run and runAggregation, right?
Do all the other RPCs also need RequestOptions functionality?
| * @param requestTags the list of request tags to set | ||
| * @return the builder object | ||
| */ | ||
| public Builder setRequestTags(ImmutableList<String> requestTags) { |
There was a problem hiding this comment.
nit: Can the parameter be of List to be as general as possible?
We can copy the contents over to an immutablelist ourselves to ensure they don't change.
| ExplainOptions explainOptions, | ||
| List<ReadOption> readOptions, | ||
| RequestOptions requestOptions) { |
There was a problem hiding this comment.
nit: We can probably replace these three params with DatastoreExecutionOptions and assign the vars from there
this.explainOptions = datastoreExecutionOptions.getExplainOptions()
| public static <Q extends Query<?>> QueryConfig<Q> create( | ||
| Q query, | ||
| ExplainOptions explainOptions, | ||
| List<ReadOption> readOptions, | ||
| RequestOptions requestOptions) { | ||
| return QueryConfig.<Q>newBuilder() | ||
| .setQuery(query) | ||
| .setExplainOptions(explainOptions) | ||
| .setReadOptions(readOptions) | ||
| .setRequestOptions(requestOptions) | ||
| .build(); | ||
| } |
There was a problem hiding this comment.
nit: Do we need to expose this variant of create if we have:
createWithExecutionOptions(Q query, DatastoreExecutionOptions executionOptions) {?
Can we just have the call this by building the DatastoreExecutionOptions with the required options?
| public Builder<Q> setReadOptions(List<ReadOption> readOptions) { | ||
| this.readOptions = readOptions; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder<Q> setExplainOptions(ExplainOptions explainOptions) { | ||
| this.explainOptions = explainOptions; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder<Q> setRequestOptions(RequestOptions requestOptions) { | ||
| this.requestOptions = requestOptions; | ||
| return this; | ||
| } |
There was a problem hiding this comment.
nit: Same here, can the caller just call something like setDatastoreExecutionOptions which has all the required options?
| public Builder setReadOptions(ReadOption... readOptions) { | ||
| this.readOptions = readOptions != null ? Arrays.asList(readOptions) : Collections.emptyList(); | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setReadOptions(List<ReadOption> readOptions) { | ||
| this.readOptions = readOptions != null ? readOptions : Collections.emptyList(); | ||
| return this; | ||
| } |
There was a problem hiding this comment.
(I may have asked this earlier, but forgot)
What is the need to expose both the varargs and List options in Datastore? Can we only expose the List<?> option for users to pass in? For existing methods that have varargs, we can just pack it into a list and set it here
This PR introduced sending request tags for different datastore requests. The tags can be passed using 2 mechanisms: