Skip to content

Commit

Permalink
chore: disable initial showCommands from telemetry MONGOSH-1652 (#1755)
Browse files Browse the repository at this point in the history
* chore: use _untrackedShow for startup banners

* chore: test that _untrackedShow passes telemetry option

* chore: test disabling telemetry on mongo.show

* chore: remove .only

* chore: fix linting issues

* chore: fix sent errors

* chore: remove offending imports
  • Loading branch information
kmruiz authored Nov 28, 2023
1 parent cf5c0f2 commit 33b0332
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 7 deletions.
6 changes: 3 additions & 3 deletions packages/cli-repl/src/mongosh-repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,9 @@ class MongoshNodeRepl implements EvaluationListener {
// https://github.com/mongodb/mongo/blob/a6df396047a77b90bf1ce9463eecffbee16fb864/src/mongo/shell/mongo_main.cpp#L1003-L1026
const { shellApi } = instanceState;
const banners = await Promise.all([
(async () => await shellApi.show('startupWarnings'))(),
(async () => await shellApi.show('automationNotices'))(),
(async () => await shellApi.show('nonGenuineMongoDBCheck'))(),
(async () => await shellApi._untrackedShow('startupWarnings'))(),
(async () => await shellApi._untrackedShow('automationNotices'))(),
(async () => await shellApi._untrackedShow('nonGenuineMongoDBCheck'))(),
]);
for (const banner of banners) {
if (banner.value) {
Expand Down
18 changes: 18 additions & 0 deletions packages/shell-api/src/mongo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,24 @@ describe('Mongo', function () {
instanceState.currentDb = database;
});
describe('show', function () {
it('should send telemetry by default', async function () {
serviceProvider.listDatabases.resolves({ ok: 1, databases: [] });
await mongo.show('dbs');

expect(bus.emit).to.have.been.calledWith('mongosh:show', {
method: 'show dbs',
});
});

it('should not send telemetry when disabled', async function () {
serviceProvider.listDatabases.resolves({ ok: 1, databases: [] });
await mongo.show('dbs', undefined, false);

expect(bus.emit).to.not.have.been.calledWith('mongosh:show', {
method: 'show dbs',
});
});

['databases', 'dbs'].forEach((t) => {
describe(t, function () {
it('calls serviceProvider.listDatabases on the admin database', async function () {
Expand Down
14 changes: 10 additions & 4 deletions packages/shell-api/src/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,19 @@ export default class Mongo extends ShellApiClass {

@returnsPromise
@apiVersions([1])
async show(cmd: string, arg?: string): Promise<CommandResult> {
async show(
cmd: string,
arg?: string,
tracked = true
): Promise<CommandResult> {
const db = this._instanceState.currentDb;
// legacy shell:
// https://github.com/mongodb/mongo/blob/a6df396047a77b90bf1ce9463eecffbee16fb864/src/mongo/shell/utils.js#L900-L1226
this._instanceState.messageBus.emit('mongosh:show', {
method: `show ${cmd}`,
});

tracked &&
this._instanceState.messageBus.emit('mongosh:show', {
method: `show ${cmd}`,
});

switch (cmd) {
case 'databases':
Expand Down
12 changes: 12 additions & 0 deletions packages/shell-api/src/shell-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,18 @@ describe('ShellApi', function () {
expect(mongo.show).to.have.been.calledWith('databases');
});
});
describe('_untrackedShow', function () {
beforeEach(async function () {
await instanceState.shellApi._untrackedShow('databases');
});
it('calls show with arg and without telemetry', function () {
expect(mongo.show).to.have.been.calledWith(
'databases',
undefined,
false
);
});
});
describe('it', function () {
it('returns empty result if no current cursor', async function () {
instanceState.currentCursor = null;
Expand Down
7 changes: 7 additions & 0 deletions packages/shell-api/src/shell-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ export default class ShellApi extends ShellApiClass {
return await this._instanceState.currentDb._mongo.show(cmd, arg);
}

@directShellCommand
@returnsPromise
@shellCommandCompleter(showCompleter)
async _untrackedShow(cmd: string, arg?: string): Promise<CommandResult> {
return await this._instanceState.currentDb._mongo.show(cmd, arg, false);
}

@directShellCommand
@returnsPromise
@platforms(['CLI'])
Expand Down

0 comments on commit 33b0332

Please sign in to comment.