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

suppress noisy mongo cmds #619

Merged
merged 3 commits into from Apr 27, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion AutoCollection/diagnostic-channel/mongodb.sub.ts
Expand Up @@ -10,6 +10,7 @@ let clients: TelemetryClient[] = [];
export const subscriber = (event: IStandardEvent<mongodb.IMongoData>) => {
if (event.data.event.commandName === "ismaster") {
// suppress noisy ismaster commands
return;
}
clients.forEach((client) => {
const dbName = (event.data.startedData && event.data.startedData.databaseName) || "Unknown database";
Expand Down Expand Up @@ -39,4 +40,4 @@ export function enable(enabled: boolean, client: TelemetryClient) {
channel.unsubscribe("mongodb", subscriber);
}
}
}
}
50 changes: 27 additions & 23 deletions Tests/AutoCollection/Performance.tests.ts
Expand Up @@ -41,39 +41,43 @@ describe("AutoCollection/Performance", () => {
performance1["_trackNetwork"]();
performance2["_trackNetwork"]();
Performance.countRequest(5000, true);

const prev1 = performance1["_lastIntervalRequestExecutionTime"];
const prev2 = performance2["_lastIntervalRequestExecutionTime"];
assert.deepEqual(prev1, prev2);
assert.deepEqual(prev1, 1000 + 2000);
assert.equal(Performance["_intervalRequestExecutionTime"], 1000 + 2000 + 5000);
assert.equal(stub1.callCount, 2, "calls trackMetric for the 2 standard metrics");
assert.equal(stub2.callCount, 3, "calls trackMetric for the 3 live metric counters");
assert.equal(stub2.args[1][0].value, stub1.args[1][0].value);
assert.equal(stub1.args[1][0].value, (1000 + 2000) / 2, "request duration average should be 1500");

stub1.reset();
stub2.reset();

// Add to end of event loop
setTimeout(() => {
// need to wait at least 1 ms so trackNetwork has valid elapsedMs value
performance1["_trackNetwork"]();
performance2["_trackNetwork"]();
assert.equal(Performance["_intervalRequestExecutionTime"], 1000 + 2000 + 5000);
assert.equal(stub1.callCount, 2, "calls trackMetric for the 2 standard metrics");
assert.equal(stub2.callCount, 3, "calls trackMetric for the 3 live metric counters");
assert.equal(stub2.args[1][0].value, stub1.args[1][0].value);
assert.equal(stub1.args[1][0].value, (5000) / 1, "request duration average should be 5000");
assert.equal(stub1.args[1][0].value, (1000 + 2000) / 2, "request duration average should be 1500");

stub1.reset();
stub2.reset();

setTimeout(() => {
// need to wait at least 1 ms so trackNetwork has valid elapsedMs value
performance1["_trackNetwork"]();
performance2["_trackNetwork"]();
assert.equal(stub1.callCount, 2, "calls trackMetric for the 2 standard metrics");
assert.equal(stub2.callCount, 3, "calls trackMetric for the 3 live metric counters");
assert.equal(stub2.args[1][0].value, stub1.args[1][0].value);
assert.equal(stub1.args[1][0].value, (5000) / 1, "request duration average should be 5000");

appInsights.setAutoCollectPerformance(true); // set back to default of true so tests expecting the default can pass
Performance.INSTANCE.dispose();
performance1.dispose();
performance2.dispose();
stub1.restore()
stub2.restore();
setIntervalStub.restore();
clearIntervalSpy.restore();
done();
}, 1);
}, 1)

appInsights.setAutoCollectPerformance(true); // set back to default of true so tests expecting the default can pass
Performance.INSTANCE.dispose();
performance1.dispose();
performance2.dispose();
stub1.restore()
stub2.restore();
setIntervalStub.restore();
clearIntervalSpy.restore();
done();
}, 1);
});
});
});