mirror of https://github.com/grpc/grpc-node.git
Merge pull request #1607 from murgatroid99/grpc-js_xds_separate_package
grpc-js: Separate xds code into a separate plugin package
This commit is contained in:
commit
57428bf6fa
|
@ -1,15 +1,15 @@
|
|||
[submodule "packages/grpc-tools/deps/protobuf"]
|
||||
path = packages/grpc-tools/deps/protobuf
|
||||
url = https://github.com/protocolbuffers/protobuf
|
||||
[submodule "packages/grpc-js/deps/envoy-api"]
|
||||
path = packages/grpc-js/deps/envoy-api
|
||||
[submodule "packages/grpc-js-xds/deps/envoy-api"]
|
||||
path = packages/grpc-js-xds/deps/envoy-api
|
||||
url = https://github.com/envoyproxy/data-plane-api.git
|
||||
[submodule "packages/grpc-js/deps/udpa"]
|
||||
path = packages/grpc-js/deps/udpa
|
||||
[submodule "packages/grpc-js-xds/deps/udpa"]
|
||||
path = packages/grpc-js-xds/deps/udpa
|
||||
url = https://github.com/cncf/udpa.git
|
||||
[submodule "packages/grpc-js/deps/googleapis"]
|
||||
path = packages/grpc-js/deps/googleapis
|
||||
[submodule "packages/grpc-js-xds/deps/googleapis"]
|
||||
path = packages/grpc-js-xds/deps/googleapis
|
||||
url = https://github.com/googleapis/googleapis.git
|
||||
[submodule "packages/grpc-js/deps/protoc-gen-validate"]
|
||||
path = packages/grpc-js/deps/protoc-gen-validate
|
||||
[submodule "packages/grpc-js-xds/deps/protoc-gen-validate"]
|
||||
path = packages/grpc-js-xds/deps/protoc-gen-validate
|
||||
url = https://github.com/envoyproxy/protoc-gen-validate.git
|
||||
|
|
11
gulpfile.ts
11
gulpfile.ts
|
@ -18,28 +18,29 @@
|
|||
import * as gulp from 'gulp';
|
||||
import * as healthCheck from './packages/grpc-health-check/gulpfile';
|
||||
import * as jsCore from './packages/grpc-js/gulpfile';
|
||||
import * as jsXds from './packages/grpc-js-xds/gulpfile';
|
||||
import * as protobuf from './packages/proto-loader/gulpfile';
|
||||
import * as internalTest from './test/gulpfile';
|
||||
|
||||
const installAll = gulp.series(jsCore.install, healthCheck.install, protobuf.install, internalTest.install);
|
||||
const installAll = gulp.series(jsCore.install, healthCheck.install, protobuf.install, internalTest.install, jsXds.install);
|
||||
|
||||
const lint = gulp.parallel(jsCore.lint);
|
||||
|
||||
const build = gulp.series(jsCore.compile, protobuf.compile);
|
||||
const build = gulp.series(jsCore.compile, protobuf.compile, jsXds.compile);
|
||||
|
||||
const setup = gulp.series(installAll);
|
||||
|
||||
const setupPureJSInterop = gulp.series(jsCore.install, protobuf.install, internalTest.install);
|
||||
|
||||
const clean = gulp.series(jsCore.clean, protobuf.clean);
|
||||
const clean = gulp.series(jsCore.clean, protobuf.clean, jsXds.clean);
|
||||
|
||||
const cleanAll = gulp.series(jsCore.cleanAll, internalTest.cleanAll, protobuf.cleanAll);
|
||||
const cleanAll = gulp.series(jsXds.cleanAll, jsCore.cleanAll, internalTest.cleanAll, protobuf.cleanAll);
|
||||
|
||||
const nativeTestOnly = gulp.parallel(healthCheck.test);
|
||||
|
||||
const nativeTest = gulp.series(build, nativeTestOnly);
|
||||
|
||||
const testOnly = gulp.parallel(jsCore.test, nativeTestOnly, protobuf.test);
|
||||
const testOnly = gulp.parallel(jsCore.test, nativeTestOnly, protobuf.test, jsXds.test);
|
||||
|
||||
const test = gulp.series(build, testOnly, internalTest.test);
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"extends": "./node_modules/gts/"
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
...require('gts/.prettierrc.json')
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
# @grpc/grpc-js xDS plugin
|
||||
|
||||
This package provides support for the `xds://` URL scheme to the `@grpc/grpc-js` library. The latest version of this package is compatible with `@grpc/grpc-js` version 1.2.x.
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
npm install @grpc/grpc-js-xds
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```ts
|
||||
import * as grpcJsXds from '@grpc/grpc-js-xds';
|
||||
grpcJsXds.register();
|
||||
|
||||
// ...get a @grpc/grpc-js Client class as usual
|
||||
|
||||
const client = new MyServiceClient('xds:///example.com:123');
|
||||
```
|
||||
|
||||
## Supported Features
|
||||
|
||||
- [xDS-Based Global Load Balancing](https://github.com/grpc/proposal/blob/master/A27-xds-global-load-balancing.md)
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright 2020 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
import * as gulp from 'gulp';
|
||||
|
||||
import * as mocha from 'gulp-mocha';
|
||||
import * as path from 'path';
|
||||
import * as execa from 'execa';
|
||||
import * as semver from 'semver';
|
||||
|
||||
Error.stackTraceLimit = Infinity;
|
||||
|
||||
const jsCoreDir = __dirname;
|
||||
const outDir = path.resolve(jsCoreDir, 'build');
|
||||
|
||||
const pkgPath = path.resolve(jsCoreDir, 'package.json');
|
||||
const supportedVersionRange = require(pkgPath).engines.node;
|
||||
const versionNotSupported = () => {
|
||||
console.log(`Skipping grpc-js-xds task for Node ${process.version}`);
|
||||
return () => { return Promise.resolve(); };
|
||||
};
|
||||
const identity = (value: any): any => value;
|
||||
const checkTask = semver.satisfies(process.version, supportedVersionRange) ?
|
||||
identity : versionNotSupported;
|
||||
|
||||
const execNpmVerb = (verb: string, ...args: string[]) =>
|
||||
execa('npm', [verb, ...args], {cwd: jsCoreDir, stdio: 'inherit'});
|
||||
const execNpmCommand = execNpmVerb.bind(null, 'run');
|
||||
|
||||
const install = checkTask(() => execNpmVerb('install', '--unsafe-perm'));
|
||||
|
||||
/**
|
||||
* Runs tslint on files in src/, with linting rules defined in tslint.json.
|
||||
*/
|
||||
const lint = checkTask(() => execNpmCommand('check'));
|
||||
|
||||
const cleanFiles = checkTask(() => execNpmCommand('clean'));
|
||||
|
||||
const clean = gulp.series(install, cleanFiles);
|
||||
|
||||
const cleanAll = gulp.parallel(clean);
|
||||
|
||||
/**
|
||||
* Transpiles TypeScript files in src/ to JavaScript according to the settings
|
||||
* found in tsconfig.json.
|
||||
*/
|
||||
const compile = checkTask(() => execNpmCommand('compile'));
|
||||
|
||||
const runTests = checkTask(() => {
|
||||
return gulp.src(`${outDir}/test/**/*.js`)
|
||||
.pipe(mocha({reporter: 'mocha-jenkins-reporter',
|
||||
require: ['ts-node/register']}));
|
||||
});
|
||||
|
||||
const test = gulp.series(install, runTests);
|
||||
|
||||
export {
|
||||
install,
|
||||
lint,
|
||||
clean,
|
||||
cleanAll,
|
||||
compile,
|
||||
test
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
// Original file: proto/grpc/testing/test.proto
|
||||
|
||||
import * as grpc from '../../../../src'
|
||||
import * as grpc from '@grpc/grpc-js'
|
||||
import { LoadBalancerStatsRequest as _grpc_testing_LoadBalancerStatsRequest, LoadBalancerStatsRequest__Output as _grpc_testing_LoadBalancerStatsRequest__Output } from '../../grpc/testing/LoadBalancerStatsRequest';
|
||||
import { LoadBalancerStatsResponse as _grpc_testing_LoadBalancerStatsResponse, LoadBalancerStatsResponse__Output as _grpc_testing_LoadBalancerStatsResponse__Output } from '../../grpc/testing/LoadBalancerStatsResponse';
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Original file: proto/grpc/testing/test.proto
|
||||
|
||||
import * as grpc from '../../../../src'
|
||||
import * as grpc from '@grpc/grpc-js'
|
||||
import { Empty as _grpc_testing_Empty, Empty__Output as _grpc_testing_Empty__Output } from '../../grpc/testing/Empty';
|
||||
import { ReconnectInfo as _grpc_testing_ReconnectInfo, ReconnectInfo__Output as _grpc_testing_ReconnectInfo__Output } from '../../grpc/testing/ReconnectInfo';
|
||||
import { ReconnectParams as _grpc_testing_ReconnectParams, ReconnectParams__Output as _grpc_testing_ReconnectParams__Output } from '../../grpc/testing/ReconnectParams';
|
|
@ -1,6 +1,6 @@
|
|||
// Original file: proto/grpc/testing/test.proto
|
||||
|
||||
import * as grpc from '../../../../src'
|
||||
import * as grpc from '@grpc/grpc-js'
|
||||
import { Empty as _grpc_testing_Empty, Empty__Output as _grpc_testing_Empty__Output } from '../../grpc/testing/Empty';
|
||||
import { SimpleRequest as _grpc_testing_SimpleRequest, SimpleRequest__Output as _grpc_testing_SimpleRequest__Output } from '../../grpc/testing/SimpleRequest';
|
||||
import { SimpleResponse as _grpc_testing_SimpleResponse, SimpleResponse__Output as _grpc_testing_SimpleResponse__Output } from '../../grpc/testing/SimpleResponse';
|
|
@ -1,6 +1,6 @@
|
|||
// Original file: proto/grpc/testing/test.proto
|
||||
|
||||
import * as grpc from '../../../../src'
|
||||
import * as grpc from '@grpc/grpc-js'
|
||||
import { Empty as _grpc_testing_Empty, Empty__Output as _grpc_testing_Empty__Output } from '../../grpc/testing/Empty';
|
||||
|
||||
/**
|
|
@ -1,6 +1,6 @@
|
|||
// Original file: proto/grpc/testing/test.proto
|
||||
|
||||
import * as grpc from '../../../../src'
|
||||
import * as grpc from '@grpc/grpc-js'
|
||||
import { Empty as _grpc_testing_Empty, Empty__Output as _grpc_testing_Empty__Output } from '../../grpc/testing/Empty';
|
||||
|
||||
/**
|
|
@ -1,4 +1,4 @@
|
|||
import * as grpc from '../../src';
|
||||
import * as grpc from '@grpc/grpc-js';
|
||||
import { ServiceDefinition, EnumTypeDefinition, MessageTypeDefinition } from '@grpc/proto-loader';
|
||||
|
||||
import { LoadBalancerStatsServiceClient as _grpc_testing_LoadBalancerStatsServiceClient } from './grpc/testing/LoadBalancerStatsService';
|
|
@ -15,7 +15,9 @@
|
|||
*
|
||||
*/
|
||||
|
||||
import * as grpc from '../src';
|
||||
import * as grpc from '@grpc/grpc-js';
|
||||
|
||||
import * as grpc_xds from '../src';
|
||||
|
||||
import { ProtoGrpcType } from './generated/test';
|
||||
|
||||
|
@ -25,6 +27,8 @@ import { LoadBalancerStatsResponse } from './generated/grpc/testing/LoadBalancer
|
|||
import * as yargs from 'yargs';
|
||||
import { LoadBalancerStatsServiceHandlers } from './generated/grpc/testing/LoadBalancerStatsService';
|
||||
|
||||
grpc_xds.register();
|
||||
|
||||
const packageDefinition = protoLoader.loadSync('grpc/testing/test.proto', {
|
||||
keepCase: true,
|
||||
defaults: true,
|
|
@ -0,0 +1,53 @@
|
|||
{
|
||||
"name": "@grpc/grpc-js-xds",
|
||||
"version": "1.0.0",
|
||||
"description": "Plugin for @grpc/grpc-js. Adds the xds:// URL scheme and associated features.",
|
||||
"main": "build/src/index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"check": "gts check",
|
||||
"clean": "gts clean",
|
||||
"compile": "tsc",
|
||||
"fix": "gts fix",
|
||||
"prepare": "npm run compile",
|
||||
"pretest": "npm run compile",
|
||||
"posttest": "npm run check",
|
||||
"generate-types": "proto-loader-gen-types --keepCase --longs String --enums String --defaults --oneofs --json --includeComments --includeDirs deps/envoy-api/ deps/udpa/ deps/googleapis/ deps/protoc-gen-validate/ -O src/generated/ --grpcLib @grpc/grpc-js envoy/service/discovery/v2/ads.proto envoy/service/load_stats/v2/lrs.proto envoy/api/v2/listener.proto envoy/api/v2/route.proto envoy/api/v2/cluster.proto envoy/api/v2/endpoint.proto envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.proto",
|
||||
"generate-interop-types": "proto-loader-gen-types --keep-case --longs String --enums String --defaults --oneofs --json --includeComments --includeDirs proto/ -O interop/generated --grpcLib @grpc/grpc-js grpc/testing/test.proto"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/grpc/grpc-node.git"
|
||||
},
|
||||
"keywords": [
|
||||
"grpc"
|
||||
],
|
||||
"author": {
|
||||
"name": "Google Inc."
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/grpc/grpc-node/issues"
|
||||
},
|
||||
"homepage": "https://github.com/grpc/grpc-node#readme",
|
||||
"devDependencies": {
|
||||
"@grpc/grpc-js": "file:../grpc-js",
|
||||
"gts": "^2.0.2",
|
||||
"typescript": "^3.8.3",
|
||||
"@types/gulp": "^4.0.6",
|
||||
"@types/gulp-mocha": "0.0.32",
|
||||
"@types/mocha": "^5.2.6",
|
||||
"@types/node": "^13.11.1",
|
||||
"@types/yargs": "^15.0.5",
|
||||
"yargs": "^15.4.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@grpc/proto-loader": "^0.6.0-pre14"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@grpc/grpc-js": "~1.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.10.0"
|
||||
}
|
||||
}
|
6
packages/grpc-js/scripts/xds.sh → packages/grpc-js-xds/scripts/xds.sh
Executable file → Normal file
6
packages/grpc-js/scripts/xds.sh → packages/grpc-js-xds/scripts/xds.sh
Executable file → Normal file
|
@ -34,6 +34,10 @@ echo "source $NVM_DIR/nvm.sh" > ~/.profile
|
|||
echo "source $NVM_DIR/nvm.sh" > ~/.shrc
|
||||
export ENV=~/.shrc
|
||||
|
||||
cd $base/../grpc-js
|
||||
npm install
|
||||
|
||||
# grpc-js-xds has a dev dependency on "../grpc-js", so it should pull that in automatically
|
||||
cd $base
|
||||
git submodule update --init --recursive
|
||||
npm install
|
||||
|
@ -54,7 +58,7 @@ GRPC_NODE_TRACE=xds_client,xds_resolver,cds_balancer,eds_balancer,priority,weigh
|
|||
--path_to_server_binary=/java_server/grpc-java/interop-testing/build/install/grpc-interop-testing/bin/xds-test-server \
|
||||
--gcp_suffix=$(date '+%s') \
|
||||
--verbose \
|
||||
--client_cmd="$(which node) grpc-node/packages/grpc-js/build/interop/xds-interop-client \
|
||||
--client_cmd="$(which node) grpc-node/packages/grpc-js-xds/build/interop/xds-interop-client \
|
||||
--server=xds:///{server_uri} \
|
||||
--stats_port={stats_port} \
|
||||
--qps={qps} \
|
|
@ -1,4 +1,4 @@
|
|||
import * as grpc from '../index';
|
||||
import * as grpc from '@grpc/grpc-js';
|
||||
import { ServiceDefinition, EnumTypeDefinition, MessageTypeDefinition } from '@grpc/proto-loader';
|
||||
|
||||
import { AggregatedDiscoveryServiceClient as _envoy_service_discovery_v2_AggregatedDiscoveryServiceClient } from './envoy/service/discovery/v2/AggregatedDiscoveryService';
|
||||
|
@ -6,7 +6,7 @@ import { AggregatedDiscoveryServiceClient as _envoy_service_discovery_v2_Aggrega
|
|||
type ConstructorArguments<Constructor> = Constructor extends new (...args: infer Args) => any ? Args: never;
|
||||
type SubtypeConstructor<Constructor, Subtype> = {
|
||||
new(...args: ConstructorArguments<Constructor>): Subtype;
|
||||
}
|
||||
};
|
||||
|
||||
export interface ProtoGrpcType {
|
||||
envoy: {
|
|
@ -1,11 +1,11 @@
|
|||
import * as grpc from '../index';
|
||||
import * as grpc from '@grpc/grpc-js';
|
||||
import { ServiceDefinition, EnumTypeDefinition, MessageTypeDefinition } from '@grpc/proto-loader';
|
||||
|
||||
|
||||
type ConstructorArguments<Constructor> = Constructor extends new (...args: infer Args) => any ? Args: never;
|
||||
type SubtypeConstructor<Constructor, Subtype> = {
|
||||
new(...args: ConstructorArguments<Constructor>): Subtype;
|
||||
}
|
||||
};
|
||||
|
||||
export interface ProtoGrpcType {
|
||||
envoy: {
|
|
@ -1,11 +1,11 @@
|
|||
import * as grpc from '../index';
|
||||
import * as grpc from '@grpc/grpc-js';
|
||||
import { ServiceDefinition, EnumTypeDefinition, MessageTypeDefinition } from '@grpc/proto-loader';
|
||||
|
||||
|
||||
type ConstructorArguments<Constructor> = Constructor extends new (...args: infer Args) => any ? Args: never;
|
||||
type SubtypeConstructor<Constructor, Subtype> = {
|
||||
new(...args: ConstructorArguments<Constructor>): Subtype;
|
||||
}
|
||||
};
|
||||
|
||||
export interface ProtoGrpcType {
|
||||
envoy: {
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue