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: Multi cluster routing #1007

Merged
merged 55 commits into from May 10, 2022

Conversation

danieljbruce
Copy link
Contributor

This PR allows users of the client library to provide a list of clusters in an API request so that routing of requests will stay restricted to that group of clusters.

@danieljbruce danieljbruce requested review from a team as code owners February 1, 2022 21:20
@product-auto-label product-auto-label bot added the api: bigtable Issues related to the googleapis/nodejs-bigtable API. label Feb 1, 2022
@danieljbruce danieljbruce changed the title Multi cluster routing feat: Multi cluster routing Feb 1, 2022
@kolea2 kolea2 changed the base branch from multi-cluster-routing to main February 3, 2022 21:30
.slice(1, 3)
.map(clusterId => instance.cluster(clusterId));
const options = {
routing: clusterSubset,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's fine (and a little easier to read) if you just hardcode 2/3 of the cluster ids

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. I'll go make this change.

import {Bigtable} from '../src';
import assert = require('assert');

describe('📦 App Profile', () => {
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 a great start! Let's add a few more tests

  1. create an app profile with single cluster routing
  2. create an app profile with multi cluster routing (no cluster ids)
  3. create an app profile with single cluster routing and update it to multi cluster routing with ids

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 these tests. In the process of adding these tests it looks like a lot of restructuring was required in order to eliminate duplicate code fragments so let me know if you have any questions regarding the changes.

import {Cluster} from '../src/cluster';
import * as inst from '../src/instance';

export const PREFIX = 'gcloud-tests-';
Copy link
Contributor

Choose a reason for hiding this comment

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

is this cleanup from somewhere else? Should it be removed there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These variables were moved into a file called common.js because now two files use them. app-profile.ts is one of them and the other is instance.ts.


export const PREFIX = 'gcloud-tests-';

export function generateId(resourceType: string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

same question here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These variables were moved into a file called common.js because now two files use them. app-profile.ts is one of them and the other is instance.ts.

@@ -29,7 +29,7 @@ export interface AppProfileOptions {
* value is required when creating the app profile and optional when setting
* the metadata.
*/
routing?: 'any' | Cluster;
routing?: 'any' | Cluster | Array<Cluster>;
Copy link
Contributor

Choose a reason for hiding this comment

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

The Java client uses a set instead of an array. Is there a compelling reason to have an array here? If no, can we switch to a set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds like a good plan. I can change to a set. The only reason we would want to use an array is if we want for some reason for the order to be preserved every time we make a call to get the clusters in an app profile. I can't see why we would care about that though so a set is fine.

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 only consideration is that in the response object we get an array so maybe we want an array input for consistency, but probably it doesn't matter.

@bcoe bcoe added the owlbot:run Add this label to trigger the Owlbot post processor. label Mar 16, 2022
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Mar 16, 2022
@bcoe bcoe added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 16, 2022
@bcoe
Copy link
Contributor

bcoe commented Mar 16, 2022

Just an FYI, if you're working on a branch from a fork, add owlbot:run and kokoro:force-run to kick off tests/post-processing.

@danieljbruce danieljbruce added the owlbot:run Add this label to trigger the Owlbot post processor. label Mar 22, 2022
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Mar 22, 2022
Copy link
Contributor

@kolea2 kolea2 left a comment

Choose a reason for hiding this comment

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

lgtm after last small comment

test/instance.ts Outdated
@@ -263,6 +256,23 @@ describe('Bigtable/Instance', () => {
};
instance.createAppProfile(APP_PROFILE_ID, options, assert.ifError);
});

it('a set of clusters', done => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit - update this description

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 updated this to say a set of cluster objects, but I think you might have wanted something else. In this describe block our description string says, "should respect the routing option with" and then each it describes what we pass into the routing option. In this case, on the line that says, const options = {routing: new Set(clusters)}; we are setting the routing option to a set of clusters.

@product-auto-label product-auto-label bot added the size: l Pull request size is large. label Apr 14, 2022
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 14, 2022
Copy link
Contributor

@kolea2 kolea2 left a comment

Choose a reason for hiding this comment

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

lgtm, would appreciate if @bcoe could also sign off before merging :) thanks!

) {
// Runs if routing is a set and every element in it is a cluster
appProfile.multiClusterRoutingUseAny = {
clusterIds: [...options.routing].map(
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@bcoe bcoe left a comment

Choose a reason for hiding this comment

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

Left a couple non-blocking recommendations.

export const PREFIX = 'gcloud-tests-';

export function generateId(resourceType: string) {
return PREFIX + resourceType + '-' + uuid.v1().substr(0, 8);
Copy link
Contributor

Choose a reason for hiding this comment

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

I would add a timestamp to resource names, so that we can easily cleanup stale resources in the future:

Date.now()

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'll create a separate issue for this since I tried it and there was more cleanup for the sake of getting this PR in and keeping things separate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@danieljbruce danieljbruce added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 10, 2022
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 10, 2022
@danieljbruce danieljbruce added the owlbot:run Add this label to trigger the Owlbot post processor. label May 10, 2022
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label May 10, 2022
@danieljbruce danieljbruce merged commit 3468cd9 into googleapis:main May 10, 2022
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. size: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants