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

chore: disable initial showCommands from telemetry MONGOSH-1652 #1755

Merged
merged 7 commits into from
Nov 28, 2023
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
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
kmruiz marked this conversation as resolved.
Show resolved Hide resolved
): 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