Skip to content
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

grpc-js: Fix handling of grpc.enable_channelz option #1961

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/grpc-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@grpc/grpc-js",
"version": "1.4.2",
"version": "1.4.3",
"description": "gRPC Library for Node - pure JS implementation",
"homepage": "https://grpc.io/",
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",
Expand Down
11 changes: 9 additions & 2 deletions packages/grpc-js/src/subchannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,7 @@ export class Subchannel {
headersString
);
const streamSession = this.session;
let statsTracker: SubchannelCallStatsTracker;
if (this.channelzEnabled) {
this.callTracker.addCallStarted();
callStream.addStatusWatcher(status => {
Expand All @@ -851,16 +852,22 @@ export class Subchannel {
}
}
});
callStream.attachHttp2Stream(http2Stream, this, extraFilters, {
statsTracker = {
addMessageSent: () => {
this.messagesSent += 1;
this.lastMessageSentTimestamp = new Date();
},
addMessageReceived: () => {
this.messagesReceived += 1;
}
});
}
} else {
statsTracker = {
addMessageSent: () => {},
addMessageReceived: () => {}
}
}
callStream.attachHttp2Stream(http2Stream, this, extraFilters, statsTracker);
}

/**
Expand Down
32 changes: 32 additions & 0 deletions packages/grpc-js/test/test-channelz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,36 @@ describe('Channelz', () => {
});
});
});
});

describe('Disabling channelz', () => {
let testServer: grpc.Server;
let testClient: ServiceClient;
beforeEach((done) => {
testServer = new grpc.Server({'grpc.enable_channelz': 0});
testServer.addService(TestServiceClient.service, testServiceImpl);
testServer.bindAsync('localhost:0', grpc.ServerCredentials.createInsecure(), (error, port) => {
if (error) {
done(error);
return;
}
testServer.start();
testClient = new TestServiceClient(`localhost:${port}`, grpc.credentials.createInsecure(), {'grpc.enable_channelz': 0});
done();
});
});

afterEach(() => {
testClient.close();
testServer.forceShutdown();
});

it('Should still work', (done) => {
const deadline = new Date();
deadline.setSeconds(deadline.getSeconds() + 1);
testClient.unary({}, {deadline}, (error: grpc.ServiceError, value: unknown) => {
assert.ifError(error);
done();
});
});
});