Skip to content

Commit

Permalink
suppress noisy mongo cmds (#619)
Browse files Browse the repository at this point in the history
* suppress noisy mongo cmds

* stabilize tests
  • Loading branch information
Mark Wolff committed Apr 27, 2020
1 parent 34352e6 commit d5ada35
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
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);
});
});
});

0 comments on commit d5ada35

Please sign in to comment.