diff --git a/src/index.ts b/src/index.ts index 6b9dbd398..224ea7a66 100644 --- a/src/index.ts +++ b/src/index.ts @@ -40,6 +40,8 @@ const gapic = Object.freeze({ v1: require('./v1'), }); +const gcpApiConfig = require('./spanner_grpc_config.json'); + /*! * DO NOT DELETE THE FOLLOWING NAMESPACE DEFINITIONS */ @@ -206,6 +208,9 @@ class Spanner extends Service { }, options || {}); + // Enable grpc-gcp support + options = Object.assign({'grpc_gcp.apiConfig': gcpApiConfig}, options); + const config = { baseUrl: options.servicePath || gapic.v1.SpannerClient.servicePath, protosDir: path.resolve(__dirname, '../protos'), diff --git a/src/spanner_grpc_config.json b/src/spanner_grpc_config.json new file mode 100644 index 000000000..2c274439e --- /dev/null +++ b/src/spanner_grpc_config.json @@ -0,0 +1,92 @@ +{ + "channelPool": { + "maxSize": 10, + "maxConcurrentStreamsLowWatermark": 100 + }, + "method": [ + { + "name": [ "/google.spanner.v1.Spanner/CreateSession" ], + "affinity": { + "command": "BIND", + "affinityKey": "name" + } + }, + { + "name": [ "/google.spanner.v1.Spanner/GetSession" ], + "affinity": { + "command": "BOUND", + "affinityKey": "name" + } + }, + { + "name": [ "/google.spanner.v1.Spanner/DeleteSession" ], + "affinity": { + "command": "UNBIND", + "affinityKey": "name" + } + }, + { + "name": [ "/google.spanner.v1.Spanner/ExecuteSql" ], + "affinity": { + "command": "BOUND", + "affinityKey": "session" + } + }, + { + "name": [ "/google.spanner.v1.Spanner/ExecuteStreamingSql" ], + "affinity": { + "command": "BOUND", + "affinityKey": "session" + } + }, + { + "name": [ "/google.spanner.v1.Spanner/Read" ], + "affinity": { + "command": "BOUND", + "affinityKey": "session" + } + }, + { + "name": [ "/google.spanner.v1.Spanner/StreamingRead" ], + "affinity": { + "command": "BOUND", + "affinityKey": "session" + } + }, + { + "name": [ "/google.spanner.v1.Spanner/BeginTransaction" ], + "affinity": { + "command": "BOUND", + "affinityKey": "session" + } + }, + { + "name": [ "/google.spanner.v1.Spanner/Commit" ], + "affinity": { + "command": "BOUND", + "affinityKey": "session" + } + }, + { + "name": [ "/google.spanner.v1.Spanner/Rollback" ], + "affinity": { + "command": "BOUND", + "affinityKey": "session" + } + }, + { + "name": [ "/google.spanner.v1.Spanner/PartitionQuery" ], + "affinity": { + "command": "BOUND", + "affinityKey": "session" + } + }, + { + "name": [ "/google.spanner.v1.Spanner/PartitionRead" ], + "affinity": { + "command": "BOUND", + "affinityKey": "session" + } + } + ] +} \ No newline at end of file diff --git a/test/index.ts b/test/index.ts index 43bb3196c..06cd59b00 100644 --- a/test/index.ts +++ b/test/index.ts @@ -27,6 +27,8 @@ import * as pfy from '@google-cloud/promisify'; import * as sinon from 'sinon'; import * as spnr from '../src'; +const apiConfig = require('../src/spanner_grpc_config.json'); + function getFake(obj: {}) { return obj as { calledWith_: IArguments; @@ -187,6 +189,7 @@ describe('Spanner', () => { libName: 'gccl', libVersion: require('../../package.json').version, scopes: [], + 'grpc_gcp.apiConfig': apiConfig, }); assert.deepStrictEqual( @@ -205,6 +208,7 @@ describe('Spanner', () => { libName: 'gccl', libVersion: require('../../package.json').version, scopes: expectedScopes, + 'grpc_gcp.apiConfig': apiConfig, }); assert.deepStrictEqual( @@ -235,6 +239,7 @@ describe('Spanner', () => { libName: 'gccl', libVersion: require('../../package.json').version, scopes: [], + 'grpc_gcp.apiConfig': apiConfig, })); }); diff --git a/tsconfig.json b/tsconfig.json index 9f712fda3..bb3365e5b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,12 +3,14 @@ "compilerOptions": { "rootDir": ".", "outDir": "build", - "noImplicitAny": false + "noImplicitAny": false, + "resolveJsonModule": true }, "include": [ "src/*.ts", "src/v1/*.d.ts", "src/**/*.js", + "src/**/*.json", "test/*.ts", "system-test/*.ts", ]