Skip to content

fix(types)!: improve types for instance.ts#731

Closed
AVaksman wants to merge 30 commits intogoogleapis:mainfrom
AVaksman:update_types_instance
Closed

fix(types)!: improve types for instance.ts#731
AVaksman wants to merge 30 commits intogoogleapis:mainfrom
AVaksman:update_types_instance

Conversation

@AVaksman
Copy link
Contributor

@AVaksman AVaksman commented May 18, 2020

BREAKING CHANGE: GetAppProfilesCallback: expose nextQuery; appProfile.create(): options are required; createClusterResponse/Callback: expose gaxOperation; cluster.create(): options are required; SetInstanceMetadataOptions: only has displayName, type and labels properties; SetInstanceMetadataCallback/Response: expose gaxOperation; GetTablesOptions: only expose name and replication view options

This is a continuation of #720

  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label May 18, 2020
@AVaksman AVaksman added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label May 18, 2020
@codecov
Copy link

codecov bot commented May 19, 2020

Codecov Report

Merging #731 (10d248f) into master (c7d202b) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #731      +/-   ##
==========================================
+ Coverage   99.22%   99.24%   +0.01%     
==========================================
  Files          18       18              
  Lines       17424    17521      +97     
  Branches     1025      949      -76     
==========================================
+ Hits        17289    17388      +99     
+ Misses        132      130       -2     
  Partials        3        3              
Impacted Files Coverage Δ
src/app-profile.ts 100.00% <100.00%> (+0.40%) ⬆️
src/cluster.ts 99.72% <100.00%> (-0.01%) ⬇️
src/family.ts 99.58% <100.00%> (ø)
src/index.ts 100.00% <100.00%> (ø)
src/instance.ts 100.00% <100.00%> (ø)
src/table.ts 99.89% <100.00%> (+<0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 05cff6a...10d248f. Read the comment docs.

@AVaksman AVaksman marked this pull request as ready for review June 2, 2020 18:25
@AVaksman AVaksman added the status: blocked Resolving the issue is dependent on other work. label Jun 2, 2020
@AVaksman
Copy link
Contributor Author

AVaksman commented Jun 2, 2020

Blocked by #720

@AVaksman
Copy link
Contributor Author

AVaksman commented Jun 2, 2020

  • GetAppProfilesCallback
    • expose nextQuery in GetAppProfileCallback
    • expose failedLocations in GetAppProfileCallback
    • switch apiResponse to IListAppProfilesResponse
  • appProfile.create()/instance.createAppProfile()
    • turned options into a required param as routing is required
  • CreateClusterResponse - update to return Cluster object (not proto ICluster)
  • CreateClusterCallback - update to include Cluster and gaxOperation properties
  • Cluster.create()/instance.createCluster() - turned options into a required param as location and nodes are required params and are not set by default
  • RequestCallback supports LROCallback, NormalCallback, PagedCallback
  • SetInstanceMetadataOptions are now providing only updatable properties displayName, type, labels (vs properties of full proto IInstance interface)
  • SetInstanceMetadataCallback/Response updated to return gaxOperation and IOperation
    The usage is
    const [op] = await instance.setInstanceMetadata({displayName: 'newOne'});
    await op.promise();
  • Paged requests now accept pageSize and pageToken params (also these params a passed as part of reqOpts and not gaxOpts into Gapic)
  • GetTablesOptions only expose name and replication view options (removed schema and full and added replication view options).

@AVaksman AVaksman force-pushed the update_types_instance branch 2 times, most recently from 218c06c to 5e1284b Compare June 9, 2020 17:35
@AVaksman AVaksman force-pushed the update_types_instance branch 2 times, most recently from d9039e8 to 345d413 Compare June 15, 2020 06:29
@AVaksman AVaksman requested a review from stephenplusplus June 15, 2020 06:48
@AVaksman AVaksman removed do not merge Indicates a pull request not ready for merge, due to either quality or timing. status: blocked Resolving the issue is dependent on other work. labels Jun 15, 2020
if (apiResponse) {
failedLocations = apiResponse.failedLocations!;
}
callback(
Copy link
Contributor

Choose a reason for hiding this comment

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

This is tricky, since we let failedLocations be on its own in the last PR, as well as BigQuery's insertErrors, I believe, which is a similar concept. However, we are also breaking consistency from all of our other paginated methods, which use err, objects, nextQuery, apiResponse. I think we should find a way to get this down to the usual callback length by either combining appProfiles and failedLocations, or just documenting where the user can find the failed locations in the apiResponse. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The inconsistency comes from the fact that next_page_token is deprecated from listClusters/InstancesResponse, which makes nextQuery obsolete for those functions. However next_page_token is supported in all other paginated responses.

I think, for consistency purposes, we can add nextQuery property to getClusters/Instances response signature (it will alway be empty) and bring the response to a consistent across the repo form of err, objects, failedLocations, nextQuery, apiResponse.
Otherwise documenting where failed locations could be found consistency wise I think is a better option. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

The inconsistency comes from the fact that next_page_token is deprecated from listClusters/InstancesResponse, which makes nextQuery obsolete for those functions.

Yeah, and that's fine, so nothing we can do there. Having a new callback parameter "failedLocations" was a good idea 👍

But just so I understand here, this method does have pagination, right? "nextPageRequest" is basically "nextQuery"?

Otherwise documenting where failed locations could be found consistency wise I think is a better option.

I would lean towards the documentation option. I think it would mislead users to return the defunct nextQuery.

Copy link
Contributor Author

@AVaksman AVaksman Jun 15, 2020

Choose a reason for hiding this comment

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

"nextPageRequest" is basically "nextQuery"?

nextPageRequest is the IListObjectsRequest in this case IListAppProfilesRequest.
The nextPageRequest is only returned when there are more results available.

I would lean towards the documentation option. I think it would mislead users to return the defunct nextQuery.

Empty object for nextQuery/nextPageRequest also signals that there are no more results to be returned. I won't disrupt the workflow
something like

      const gaxOptions = {autoPaginate: false};
      let allObjects: = [];
      let getObjectsOptions = {
        pageSize: 1,
        pageToken: '',
        gaxOptions,
      };
      while (true) {
        const [objects, , next] = await instance.getObjects(
          getObjectsOptions
        );
        allObjects = [...allObjects, ...objects];
        if (!next) {
          break;
        }
        getObjectsOptions = Object.assign(
          {},
          {gaxOptions},
          {pageSize: next.pageSize!, pageToken: next.pageToken!}
        );
      }

WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

The nextPageRequest is only returned when there are more results available.

Will the user just provide that argument directly, like they do our nextQuery object?:

getAppProfiles(config, function(err, appProfiles, nextQuery) {
  if (nextQuery) {
    getAppProfile(nextQuery, function(err, nextAppProfiles, nextNextQuery) {})
  }
})

Our nextQuery object should always be an extension of the user-provided c onfig with the appropriate settings for cursoring. We should stick to that system, if we're not already, by passing the IListAppProfilesRequest back.

Empty object for nextQuery/nextPageRequest also signals that there are no more results to be returned.

That's true, but it's misleading to make users write code anticipating more results could exist, when we know they wouldn't ever. That's also a little confusing to maintain down the road. The main thing I'm avoiding is the high number of response arguments. We've usually tried to consolidate the response pattern:

  • error
  • the most logical thing the user expects
  • the full API response for whenever they need something else

For query methods, we added in "nextQuery" to make cursoring easier:

  • error
  • the most logical thing the user expects
  • an object ready to pass to the API to continue getting results
  • the full API response for whenever they need something else

So, I'm hesitant to squeeze one more in there, as if it's not "the most logical thing the user expects", then we've historically pointed them to "the full API response for whenever they need something else".

One more thought-- if the user runs this with autoPagination: true (which is on by default), doesn't that abolish all apiResponses? In this sample:

getAppProfiles()
  .then(result => {
    const appProfiles = result[0];
    if (result[1]) {
      // These locations contain instances which could not be retrieved.
      const failedLocations = result[1];
    }
  })

What actually is failedLocations? An array of arrays of strings?

My vote would go to documenting how to find failedLocations in the API response, but more input on this one could be useful.

Copy link
Contributor Author

@AVaksman AVaksman Jul 6, 2020

Choose a reason for hiding this comment

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

Our nextQuery object should always be an extension of the user-provided config with the appropriate settings for cursoring. We should stick to that system, if we're not already, by passing the IListAppProfilesRequest back.

Combined IListAppProfilesRequest with user-provided config, now below sample will work.

getAppProfiles(config, function(err, appProfiles, nextQuery) {
  if (nextQuery) {
    getAppProfile(nextQuery, function(err, nextAppProfiles, nextNextQuery) {})
  }
})

My vote would go to documenting how to find failedLocations in the API response, but more input on this one could be useful.

Removed failedLocations from the response and documented in the callback section instead.

Final take in regards to getInstances and getClusters response/callback. Both methods deprecated next_page_token. How shall the callback look {err, resources, failedLocations, fullResponse} or just {err, resources, fullResponse} and document where to find failedLocations if any?

PTAL

Copy link
Contributor

Choose a reason for hiding this comment

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

How shall the callback look {err, resources, failedLocations, fullResponse} or just {err, resources, fullResponse} and document where to find failedLocations if any?

Very good question. I think there's a good case for both options. Have we released yet with those changes, where if we change the response signature, we'd be breaking? If we have to break, I'd probably just leave those alone. If not, I would choose (err, resources, apiResponse):

  • 👍 Simple signature
  • 👍 Consistent with most of our methods, where we return "error, thing you want, everything you could ever want"
  • 👎 Have to find failedLocations inside of apiResponse

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, will revert to same in bigtable.getInstances()

* Get Table objects for all the tables in your Cloud Bigtable instance.
*
* @param {object} [options] Query object.
* @param {boolean} [options.autoPaginate=true] Have pagination handled
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry if I have overlooked this before, but is autoPaginate not a top-level option anymore? Does the user have to provide this through options.gaxOptions.autoPaginate? I think we should allow options.autoPaginate, in the same way we special-case options.pageSize,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I followed example that was done in the Spanner repo googleapis/nodejs-spanner#855 (comment)

WDYT?

Copy link
Contributor

@stephenplusplus stephenplusplus Jul 7, 2020

Choose a reason for hiding this comment

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

That was a pretty big PR to review, and it looks like I had too many streams of conversations to figure out how they all pieced together :\ . In that case, did we get rid of "options.autoPaginate", but keep "options.pageSize"? That simply doesn't make sense, as they are both related options, and in order to give meaning to "pageSize", setting "autoPaginate" to "false" is required. Fortunately, we should be able to add that property back in to Spanner relatively easily, or alternatively, remove all other top-level pagination options.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So for here let's go with the top level autoPaginate option and have API handle it the same way as pageSize and pageToken

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, sounds good to me. Thank you!

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 top level autoPaginate to getAppProfiles and getTables.

@AVaksman AVaksman requested a review from a team as a code owner July 7, 2020 18:31
@AVaksman AVaksman added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jul 15, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jul 15, 2020
@AVaksman AVaksman added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jul 16, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jul 16, 2020
@AVaksman AVaksman added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jul 16, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jul 16, 2020
@AVaksman AVaksman added kokoro:force-run Add this label to force Kokoro to re-run the tests. and removed kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Jul 29, 2020
@product-auto-label product-auto-label bot added the api: bigtable Issues related to the googleapis/nodejs-bigtable API. label Aug 21, 2020
@AVaksman AVaksman force-pushed the update_types_instance branch from 67d17e3 to 6f05a47 Compare November 24, 2020 21:15
@AVaksman AVaksman requested a review from a team November 24, 2020 21:15
@crwilcox
Copy link
Contributor

@AVaksman I find it a bit odd to have a breaking change in typing? Is this usual?

@AVaksman
Copy link
Contributor Author

AVaksman commented Nov 25, 2020

@AVaksman I find it a bit odd to have a breaking change in typing? Is this usual?

I believe it is a one-off here.
Most of the breaking corrections in this PR has to do with paginated and LRO function signatures.

@AVaksman AVaksman added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 28, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 28, 2020
@bcoe bcoe added the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 2, 2021
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 2, 2021
@crwilcox crwilcox closed this Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigtable Issues related to the googleapis/nodejs-bigtable API. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants