-
Notifications
You must be signed in to change notification settings - Fork 98
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
Support for gRPC time tracing #267
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -208,6 +208,3 @@ module.exports = { | |
findModulePath: findModulePath, | ||
findModuleVersion: findModuleVersion | ||
}; | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
syntax = "proto3"; | ||
|
||
package nodetest; | ||
|
||
service Tester { | ||
rpc TestUnary (TestRequest) returns (TestReply) {} | ||
rpc TestClientStream (stream TestRequest) returns (TestReply) {} | ||
rpc TestServerStream (TestRequest) returns (stream TestReply) {} | ||
rpc TestBidiStream (stream TestRequest) returns (stream TestReply) {} | ||
} | ||
|
||
message TestRequest { | ||
int32 n = 1; | ||
} | ||
|
||
message TestReply { | ||
int32 n = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,4 @@ message TestRequest { | |
|
||
message TestReply { | ||
string message = 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,239 @@ | ||
/** | ||
* Copyright 2016 Google Inc. All Rights Reserved. | ||
* | ||
* 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. | ||
*/ | ||
'use strict'; | ||
|
||
if (process.platform === 'win32') { | ||
// Skip grpc due to https://github.com/nodejs/node/issues/4932 | ||
process.exit(0); | ||
} | ||
|
||
var common = require('./common.js'); | ||
var assert = require('assert'); | ||
var traceLabels = require('../../lib/trace-labels.js'); | ||
|
||
var versions = { | ||
grpc013: require('./fixtures/grpc0.13'), | ||
grpc014: require('./fixtures/grpc0.14') | ||
}; | ||
var protoFile = __dirname + '/../fixtures/test-grpc.proto'; | ||
var grpcPort = 50051; | ||
var client, server; | ||
|
||
Object.keys(versions).forEach(function(version) { | ||
var grpc = versions[version]; | ||
|
||
function startServer(proto) { | ||
var _server = new grpc.Server(); | ||
_server.addProtoService(proto.Tester.service, { | ||
testUnary: function(call, cb) { | ||
setTimeout(function() { | ||
cb(null, {n: call.request.n}); | ||
}, common.serverWait); | ||
}, | ||
testClientStream: function(call, cb) { | ||
var sum = 0; | ||
call.on('data', function(data) { | ||
sum += data.n; | ||
}); | ||
call.on('end', function() { | ||
setTimeout(function() { | ||
cb(null, {n: sum}); | ||
}, common.serverWait); | ||
}); | ||
}, | ||
testServerStream: function(stream) { | ||
for (var i = 0; i < 10; ++i) { | ||
stream.write({n: i}); | ||
} | ||
setTimeout(function() { | ||
stream.end(); | ||
}, common.serverWait); | ||
}, | ||
testBidiStream: function(stream) { | ||
stream.on('data', function(data) { | ||
stream.write({n: data.n}); | ||
}); | ||
stream.on('end', function() { | ||
setTimeout(function() { | ||
stream.end(); | ||
}, common.serverWait); | ||
}); | ||
} | ||
}); | ||
_server.bind('localhost:' + grpcPort, | ||
grpc.ServerCredentials.createInsecure()); | ||
_server.start(); | ||
return _server; | ||
} | ||
|
||
function createClient(proto) { | ||
return new proto.Tester('localhost:' + grpcPort, | ||
grpc.credentials.createInsecure()); | ||
} | ||
|
||
describe(version, function() { | ||
before(function() { | ||
var proto = grpc.load(protoFile).nodetest; | ||
server = startServer(proto); | ||
client = createClient(proto); | ||
}); | ||
|
||
after(function() { | ||
server.forceShutdown(); | ||
}); | ||
|
||
afterEach(function() { | ||
common.cleanTraces(); | ||
}); | ||
|
||
it('should accurately measure time for unary requests', function(done) { | ||
common.runInTransaction(function(endTransaction) { | ||
client.testUnary({n: 42}, function(err, result) { | ||
endTransaction(); | ||
assert.ifError(err); | ||
assert.strictEqual(result.n, 42); | ||
var trace = common.getMatchingSpan(grpcPredicate); | ||
assert(trace); | ||
common.assertDurationCorrect(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should accurately measure time for client requests', function(done) { | ||
common.runInTransaction(function(endTransaction) { | ||
var stream = client.testClientStream(function(err, result) { | ||
endTransaction(); | ||
assert.ifError(err); | ||
assert.strictEqual(result.n, 45); | ||
var trace = common.getMatchingSpan(grpcPredicate); | ||
assert(trace); | ||
common.assertDurationCorrect(); | ||
done(); | ||
}); | ||
for (var i = 0; i < 10; ++i) { | ||
stream.write({n: i}); | ||
} | ||
stream.end(); | ||
}); | ||
}); | ||
|
||
it('should accurately measure time for server requests', function(done) { | ||
common.runInTransaction(function(endTransaction) { | ||
var stream = client.testServerStream(); | ||
var sum = 0; | ||
stream.on('data', function(data) { | ||
sum += data.n; | ||
}); | ||
stream.on('status', function(status) { | ||
endTransaction(); | ||
assert.strictEqual(status.code, grpc.status.OK); | ||
assert.strictEqual(sum, 45); | ||
var trace = common.getMatchingSpan(grpcPredicate); | ||
assert(trace); | ||
common.assertDurationCorrect(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should accurately measure time for bidi requests', function(done) { | ||
common.runInTransaction(function(endTransaction) { | ||
var stream = client.testBidiStream(); | ||
var sum = 0; | ||
stream.on('data', function(data) { | ||
sum += data.n; | ||
}); | ||
for (var i = 0; i < 10; ++i) { | ||
stream.write({n: i}); | ||
} | ||
stream.end(); | ||
stream.on('status', function(status) { | ||
endTransaction(); | ||
assert.strictEqual(status.code, grpc.status.OK); | ||
assert.strictEqual(sum, 45); | ||
var trace = common.getMatchingSpan(grpcPredicate); | ||
assert(trace); | ||
common.assertDurationCorrect(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should not break if no parent transaction', function(done) { | ||
client.testUnary({n: 42}, function(err, result) { | ||
assert.ifError(err); | ||
assert.strictEqual(result.n, 42); | ||
assert.strictEqual(common.getTraces().length, 0); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should remove trace frames from stack', function(done) { | ||
common.runInTransaction(function(endTransaction) { | ||
client.testUnary({n: 42}, function(err, result) { | ||
endTransaction(); | ||
assert.ifError(err); | ||
assert.strictEqual(result.n, 42); | ||
var trace = common.getMatchingSpan(grpcPredicate); | ||
var labels = trace.labels; | ||
var stack = JSON.parse(labels[traceLabels.STACK_TRACE_DETAILS_KEY]); | ||
assert.notStrictEqual(-1, | ||
stack.stack_frame[0].method_name.indexOf('clientMethodTrace')); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
if (version === 'grpc013') { | ||
it('should work for old argument orders (unary)', function(done) { | ||
common.runInTransaction(function(endTransaction) { | ||
client.testUnary({n: 42}, function(err, result) { | ||
endTransaction(); | ||
assert.ifError(err); | ||
assert.strictEqual(result.n, 42); | ||
var trace = common.getMatchingSpan(grpcPredicate); | ||
assert(trace); | ||
common.assertDurationCorrect(); | ||
done(); | ||
}, null, {}); | ||
}); | ||
}); | ||
|
||
it('should work for old argument orders (stream)', function(done) { | ||
common.runInTransaction(function(endTransaction) { | ||
var stream = client.testClientStream(function(err, result) { | ||
endTransaction(); | ||
assert.ifError(err); | ||
assert.strictEqual(result.n, 45); | ||
var trace = common.getMatchingSpan(grpcPredicate); | ||
assert(trace); | ||
common.assertDurationCorrect(); | ||
done(); | ||
}, null, {}); | ||
for (var i = 0; i < 10; ++i) { | ||
stream.write({n: i}); | ||
} | ||
stream.end(); | ||
}); | ||
}); | ||
} | ||
}); | ||
}); | ||
|
||
function grpcPredicate(span) { | ||
return span.name.indexOf('grpc-') === 0; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.