Skip to content

Commit

Permalink
grpc-js-xds: Implement ring_hash LB policy
Browse files Browse the repository at this point in the history
  • Loading branch information
murgatroid99 committed Sep 8, 2023
1 parent 3096f22 commit 3a43cba
Show file tree
Hide file tree
Showing 30 changed files with 1,081 additions and 204 deletions.
1 change: 1 addition & 0 deletions packages/grpc-js-xds/gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const compile = checkTask(() => execNpmCommand('compile'));
const runTests = checkTask(() => {
process.env.GRPC_EXPERIMENTAL_XDS_FEDERATION = 'true';
process.env.GRPC_EXPERIMENTAL_XDS_CUSTOM_LB_CONFIG = 'true';
process.env.GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH = 'true';
return gulp.src(`${outDir}/test/**/*.js`)
.pipe(mocha({reporter: 'mocha-jenkins-reporter',
require: ['ts-node/register']}));
Expand Down
1 change: 1 addition & 0 deletions packages/grpc-js-xds/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ export const EXPERIMENTAL_OUTLIER_DETECTION = (process.env.GRPC_EXPERIMENTAL_ENA
export const EXPERIMENTAL_RETRY = (process.env.GRPC_XDS_EXPERIMENTAL_ENABLE_RETRY ?? 'true') === 'true';
export const EXPERIMENTAL_FEDERATION = (process.env.GRPC_EXPERIMENTAL_XDS_FEDERATION ?? 'false') === 'true';
export const EXPERIMENTAL_CUSTOM_LB_CONFIG = (process.env.GRPC_EXPERIMENTAL_XDS_CUSTOM_LB_CONFIG ?? 'false') === 'true';
export const EXPERIMENTAL_RING_HASH = (process.env.GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH ?? 'false') === 'true';
4 changes: 2 additions & 2 deletions packages/grpc-js-xds/src/http-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export function validateTopLevelFilter(httpFilter: HttpFilter__Output): boolean
try {
typeUrl = getTopLevelFilterUrl(encodedConfig);
} catch (e) {
trace(httpFilter.name + ' validation failed with error ' + e.message);
trace(httpFilter.name + ' validation failed with error ' + (e as Error).message);
return false;
}
const registryEntry = FILTER_REGISTRY.get(typeUrl);
Expand Down Expand Up @@ -243,4 +243,4 @@ export function createHttpFilter(config: HttpFilterConfig, overrideConfig?: Http
} else {
return null;
}
}
}
2 changes: 2 additions & 0 deletions packages/grpc-js-xds/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import * as load_balancer_priority from './load-balancer-priority';
import * as load_balancer_weighted_target from './load-balancer-weighted-target';
import * as load_balancer_xds_cluster_manager from './load-balancer-xds-cluster-manager';
import * as xds_wrr_locality from './load-balancer-xds-wrr-locality';
import * as ring_hash from './load-balancer-ring-hash';
import * as router_filter from './http-filter/router-filter';
import * as fault_injection_filter from './http-filter/fault-injection-filter';
import * as csds from './csds';
Expand All @@ -41,6 +42,7 @@ export function register() {
load_balancer_weighted_target.setup();
load_balancer_xds_cluster_manager.setup();
xds_wrr_locality.setup();
ring_hash.setup();
router_filter.setup();
fault_injection_filter.setup();
csds.setup();
Expand Down
21 changes: 19 additions & 2 deletions packages/grpc-js-xds/src/load-balancer-priority.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,26 @@ const DEFAULT_FAILOVER_TIME_MS = 10_000;
const DEFAULT_RETENTION_INTERVAL_MS = 15 * 60 * 1000;

export interface LocalityEndpoint extends Endpoint {
/**
* A sequence of strings that determines how to divide endpoints up in priority and
* weighted_target.
*/
localityPath: string[];
/**
* The locality this endpoint is in. Used in wrr_locality and xds_cluster_impl.
*/
locality: Locality__Output;
weight: number;
/**
* The load balancing weight for the entire locality that contains this
* endpoint. Used in xds_wrr_locality.
*/
localityWeight: number;
/**
* The overall load balancing weight for this endpoint, calculated as the
* product of the load balancing weight for this endpoint within its locality
* and the load balancing weight of the locality. Used in ring_hash.
*/
endpointWeight: number;
};

export function isLocalityEndpoint(
Expand Down Expand Up @@ -317,7 +334,7 @@ export class PriorityLoadBalancer implements LoadBalancer {
* so that when the picker calls exitIdle, that in turn calls exitIdle on
* the PriorityChildImpl, which will start the failover timer. */
if (state === ConnectivityState.IDLE) {
picker = new QueuePicker(this);
picker = new QueuePicker(this, picker);
}
this.channelControlHelper.updateState(state, picker);
}
Expand Down

0 comments on commit 3a43cba

Please sign in to comment.