Skip to content

Commit

Permalink
fix: extend supported gRPC version range to 1.7 (googleapis#586)
Browse files Browse the repository at this point in the history
  • Loading branch information
kjin authored Oct 31, 2017
1 parent 45e78c9 commit 3e30d28
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 20 deletions.
35 changes: 27 additions & 8 deletions src/plugins/plugin-grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ function patchMetadata(metadata, api) {
Metadata = metadata;
}

function unpatchMetadata(metadata) {
// patchMetadata doesn't modify the module exports of metadata.js.
// So it's safe to provide a no-op unpatch function.
}

function patchClient(client, api) {
/**
* Wraps a callback so that the current span for this trace is also ended when
Expand Down Expand Up @@ -469,26 +474,40 @@ function unpatchServer(server) {

// # Exports

var SUPPORTED_VERSIONS = '0.13 - 1';

module.exports = [
{
file: 'src/node/src/client.js',
versions: SUPPORTED_VERSIONS,
versions: '0.13 - 1.6',
patch: patchClient,
unpatch: unpatchClient
},
{
file: 'src/node/src/metadata.js',
versions: SUPPORTED_VERSIONS,
versions: '0.13 - 1.6',
patch: patchMetadata,
// patchMetadata doesn't modify the module exports of metadata.js.
// So it's safe to have provide a no-op unpatch function.
unpatch: function unpatchMetadata() {}
unpatch: unpatchMetadata
},
{
file: 'src/node/src/server.js',
versions: SUPPORTED_VERSIONS,
versions: '0.13 - 1.6',
patch: patchServer,
unpatch: unpatchServer
},
{
file: 'src/client.js',
versions: '1.7',
patch: patchClient,
unpatch: unpatchClient
},
{
file: 'src/metadata.js',
versions: '1.7',
patch: patchMetadata,
unpatch: unpatchMetadata
},
{
file: 'src/server.js',
versions: '1.7',
patch: patchServer,
unpatch: unpatchServer
}
Expand Down
8 changes: 8 additions & 0 deletions src/trace-plugin-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ export function activate(logger: Logger, config: PluginLoaderConfig): void {
originalModuleLoad(instrumentation.file, module, false);
patchSet = {};
if (semver.valid(version)) {
// strip version of pre-release tags.
// warn if they exist.
if (!!semver.prerelease(version)) {
const originalVersion = version;
version = version.split('-')[0];
logger.warn(`${moduleRoot}: Using patch for version ${
version} for pre-release version ${originalVersion}`);
}
plugin.forEach((patch) => {
if (!patch.versions ||
semver.satisfies(version, patch.versions)) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "grpc1",
"name": "grpc1.6",
"version": "1.0.0",
"main": "index.js",
"dependencies": {
"grpc": "^1.0.0"
"grpc": "^1.6.0"
}
}
1 change: 1 addition & 0 deletions test/plugins/fixtures/grpc1.7/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('grpc');
8 changes: 8 additions & 0 deletions test/plugins/fixtures/grpc1.7/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "grpc1.7",
"version": "1.0.0",
"main": "index.js",
"dependencies": {
"grpc": "1.7.0-pre1"
}
}
6 changes: 4 additions & 2 deletions test/plugins/test-trace-grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ var shimmer = require('shimmer');
var common = require('./common'/*.js*/);

var versions = {
grpc1: './fixtures/grpc1'
grpc1_6: './fixtures/grpc1.6',
grpc1_7: './fixtures/grpc1.7'
};

var protoFile = __dirname + '/../fixtures/test-grpc.proto';
Expand Down Expand Up @@ -281,7 +282,8 @@ Object.keys(versions).forEach(function(version) {
agent = require('../..').start({
projectId: '0',
samplingRate: 0,
enhancedDatabaseReporting: true
enhancedDatabaseReporting: true,
forceNewAgent_: true
});

grpc = require(versions[version]);
Expand Down
18 changes: 10 additions & 8 deletions test/test-grpc-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ var assert = require('assert');
var http = require('http');

var versions = {
grpc1: './plugins/fixtures/grpc1'
grpc1_6: './plugins/fixtures/grpc1.6',
grpc1_7: './plugins/fixtures/grpc1.7'
};

var grpcPort = 50051;
Expand All @@ -48,18 +49,19 @@ function requestAndSendHTTPStatus(res, expectedReqs) {
}, expectedReqs);
}

// Trace agent must be started out of the loop over gRPC versions,
// because express can't be re-patched.
var agent = require('..').start({
projectId: '0',
samplingRate: 0
});
var express = require('./plugins/fixtures/express4');

Object.keys(versions).forEach(function(version) {
var agent;
var express;
var grpc;
var httpLogCount;
describe('express + ' + version, function() {
before(function(done) {
agent = require('..').start({
projectId: '0',
samplingRate: 0
});
express = require('./plugins/fixtures/express4');
grpc = require(versions[version]);

common.replaceWarnLogger(function(msg) {
Expand Down

0 comments on commit 3e30d28

Please sign in to comment.