Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Introduce Backups #794

Merged
merged 55 commits into from
Sep 10, 2020
Merged

Conversation

stephenplusplus
Copy link
Contributor

@stephenplusplus stephenplusplus commented Sep 2, 2020

API Changes

Access or create Backup objects through a Cluster reference

cluster.backup(id) // references a pre-existing "Backup" object (no remote calls)
cluster.createBackup({ id: 'backup-id', table: 'table-id' }) // creates and returns a "Backup" object
cluster.getBackups() // returns "Backup" objects
cluster.getBackupsStream() // returns "Backup" objects as a readable stream

Access Backup objects through an Instance reference

instance.createTableFromBackup({ table: 'table-id', backup: 'backup-id' }, gaxOptions)
instance.getBackups() // returns "Backup" objects
instance.getBackupsStream() // returns "Backup" objects as a readable stream

Create a Backup through a Table reference

table.createBackup(id, metadata) // creates and returns a "Backup" object

Once you have a reference to a Backup object:

All methods below besides "restore()" are common CRUD methods defined throughout our API

backup.create({ table: 'table-id', metadata: {...} })
backup.delete()
backup.get()
backup.getMetadata()
backup.restore('table-id')
backup.setMetadata({...})

References

To Dos

  • Source code
  • TypeScript annotations
  • JSDoc parameters
  • Unit tests
    • Backup
    • Cluster
    • Index
    • Instance
    • Table
  • System tests

This PR splits the work from #761 into three parts-- source code, tests, and then documentation and samples to come in a follow-up PR. This should make reviewing easier, as well as lets us lock in the source code changes before attempting to adapt the previously written tests and samples.

Currently, this PR has only the source code. Most of it was carried from #761, but there were some structural changes to follow our conventions:

- Backup(id, cluster, fields)
+ Backup(cluster, id)

get backup.expireDate()
get backup.startDate()
get backup.endDate()

- backup.create(table, metadata)
+ backup.create({table, metadata})
backup.delete()
backup.get()
+ backup.getMetadata()
backup.restore(tableId, gaxOptions)
- backup.update(metadata, gaxOptions)
+ backup.setMetadata(metadata, gaxOptions)

+ cluster.backup(id)
+ cluster.createBackup({id, table}, gaxOptions)
cluster.getBackups(options)
cluster.getBackupsStream(options)

- instance.backup(id, cluster, fields)
- instance.createTableFromBackup(tableId, backup, gaxOptions)
+ instance.createTableFromBackup({table, backup}, gaxOptions)
+ instance.getBackups(options, callback)
+ instance.getBackupsStream(options, callback)

- table.backup(id, metadata, gaxOptions)
+ table.createBackup(id, metadata, gaxOptions)

@AVaksman could you please review this when you get a chance? I will likely need special attention to the TypeScript, making sure I'm properly compliant with our conventions and use cases I may have missed. Thank you!

@stephenplusplus stephenplusplus added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Sep 2, 2020
@stephenplusplus stephenplusplus requested a review from a team as a code owner September 2, 2020 17:13
@google-cla google-cla bot added the cla: no This human has *not* signed the Contributor License Agreement. label Sep 2, 2020
@product-auto-label product-auto-label bot added the api: bigtable Issues related to the googleapis/nodejs-bigtable API. label Sep 3, 2020
@stephenplusplus
Copy link
Contributor Author

@AVaksman thank you very much for the thorough review! I've made the changes (thank you for all of the suggestions) and left just one thing: #794 (comment).

gaxOpts: options.gaxOptions,
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(err, ...resp: any[]) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

The proper type for this is likely represented in the generated types from protobufjs - would be nice to use those please :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AVaksman could you advise here? This was taken from your suggestion on the other PR. I'm fighting a lot of TypeScript errors when I tamper with this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I took a stab at it as a part of an existing PR #731 where I am differentiating bigtable.request signature between NormalCallback, LROCallback and PaginatedCallback

export type RequestCallback<T = void, R = void> = T extends void
  ? LROCallback
  : R extends void
  ? NormalCallback<T>
  : PagedCallback<T, R>;

export interface NormalCallback<TResponse> {
  (err: ServiceError | null, res?: TResponse): void;
}

export interface PagedCallback<Item, Response> {
  (
    err: ServiceError | null,
    results?: Item[] | null,
    nextQuery?: {} | null,
    response?: Response | null
  ): void;
}

export interface LROCallback {
  (
    err: ServiceError | null,
    operation?: Operation,
    apiResponse?: IOperation
  ): void;
}

Then here the something like this would work

this.bigtable.request<
      google.bigtable.admin.v2.IBackup,
      google.bigtable.admin.v2.IListBackupsResponse
    >(
      {
        client: 'BigtableInstanceAdminClient',
        method: 'listAppProfiles',
        reqOpts,
        gaxOpts,
      },
      (err, IBackups, nextPageRequest, apiResponse) => {
        if (err) {
          callback(err);
          return;
        }
        const backups = IBackups!.map(backup => {
          const backupInstance = this.backup(backup.name!.split('/').pop()!);
          backupInstance.metadata = backup;
          return backupInstance;
        });
        const nextQuery = nextPageRequest!
          ? extend({}, options, nextPageRequest!)
          : null;
        callback(null, appProfiles, nextQuery, apiResponse!);
      }
    );

Is this an overkill?
bigtable.request signature changes could be done in a separate PR in a non breaking way.
WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

If agree, I can do the bigtable.request PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Curious for @JustinBeckwith's thoughts. Whatever makes sense to you guys :)

For now, should I leave the code as-is? Also, please LMK if everything else looks correct so far and I'll get the tests going.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am ok with leaving this as is for now, and coming back around to improve the under types here later. I'm ok with it because I don't think they affect the public types. Not a big deal.

@googleapis googleapis deleted a comment from google-cla bot Sep 3, 2020
@googleapis googleapis deleted a comment from google-cla bot Sep 3, 2020
@googleapis googleapis deleted a comment from google-cla bot Sep 3, 2020
@googleapis googleapis deleted a comment from google-cla bot Sep 3, 2020
@googleapis googleapis deleted a comment from google-cla bot Sep 3, 2020
@googleapis googleapis deleted a comment from google-cla bot Sep 3, 2020
@google-cla
Copy link

google-cla bot commented Sep 3, 2020

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@googleapis googleapis deleted a comment from google-cla bot Sep 3, 2020
@google-cla
Copy link

google-cla bot commented Sep 3, 2020

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@googleapis googleapis deleted a comment from google-cla bot Sep 3, 2020
@google-cla
Copy link

google-cla bot commented Sep 3, 2020

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

2 similar comments
@google-cla
Copy link

google-cla bot commented Sep 3, 2020

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@google-cla
Copy link

google-cla bot commented Sep 3, 2020

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@googleapis googleapis deleted a comment from google-cla bot Sep 3, 2020
@google-cla
Copy link

google-cla bot commented Sep 3, 2020

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

3 similar comments
@google-cla
Copy link

google-cla bot commented Sep 3, 2020

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@google-cla
Copy link

google-cla bot commented Sep 3, 2020

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@google-cla
Copy link

google-cla bot commented Sep 3, 2020

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@stephenplusplus
Copy link
Contributor Author

Looks like you can't delete old @google-cla posts-- it'll just post it again 🤣

@AVaksman
Copy link
Contributor

AVaksman commented Sep 3, 2020

I've seen commenting "@googlebot I consent." have helped, @stephenplusplus

@google-cla
Copy link

google-cla bot commented Sep 3, 2020

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

1 similar comment
@google-cla
Copy link

google-cla bot commented Sep 3, 2020

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@google-cla
Copy link

google-cla bot commented Sep 9, 2020

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@google-cla
Copy link

google-cla bot commented Sep 9, 2020

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@JustinBeckwith JustinBeckwith added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Sep 9, 2020
/**
* An expression for specifying the sort order of the results of the request.
* The string value should specify one or more fields in
* {@link google.bigtable.admin.v2.Backup|Backup}. The full syntax is
Copy link
Contributor

Choose a reason for hiding this comment

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

Curiosity - have you generated the docs locally to make sure these links get rendered right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, well I don't actually know where that gets rendered. That's part of interface GetBackupsOptions, and I can't find where it went. It's not linked to where we use it from the getBackups() methods :. All of the other links from descriptions seem to work, though!

},
};

if (reqOpts.backup.expireTime instanceof Date) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There used to be all kinds of nuance on when it was ok to use instanceof Date, and you had to do weird tricks to detect date objects. It looks like is now does exactly what you're doing here though:
https://github.com/sindresorhus/is/blob/master/source/index.ts

So I'm good with it :)

gaxOpts: options.gaxOptions,
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(err, ...resp: any[]) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am ok with leaving this as is for now, and coming back around to improve the under types here later. I'm ok with it because I don't think they affect the public types. Not a big deal.

const callback =
typeof optionsOrCallback === 'function' ? optionsOrCallback : cb!;

options = extend(true, {}, options);
Copy link
Contributor

Choose a reason for hiding this comment

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

I spent a year trying to remove extend in favor of Object.assign, and I just want to say out loud that @stephenplusplus was right all along and I was wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hahaha, stdlib got so close on this one!

@stephenplusplus stephenplusplus merged commit 7979e39 into googleapis:master Sep 10, 2020
# for free to join this conversation on GitHub. Already have an account? # 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.

5 participants