Skip to content

Commit

Permalink
grpc-js: Fix handling of grpc.enable_channelz option
Browse files Browse the repository at this point in the history
  • Loading branch information
murgatroid99 committed Nov 5, 2021
1 parent 78466ac commit bb26dcf
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
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();
});
});
});

0 comments on commit bb26dcf

Please sign in to comment.