Skip to content

Commit

Permalink
feat(cli-repl): add ability to set log retention days MONGOSH-1984
Browse files Browse the repository at this point in the history
  • Loading branch information
gagik committed Feb 7, 2025
1 parent e7859a9 commit 6236c36
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
14 changes: 14 additions & 0 deletions packages/cli-repl/src/cli-repl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ describe('CliRepl', function () {
'updateURL',
'disableLogging',
'logLocation',
'logRetentionDays',
] satisfies (keyof CliUserConfig)[]);
});

Expand Down Expand Up @@ -1443,6 +1444,19 @@ describe('CliRepl', function () {
)
);
});

it('can set log retention days', async function () {
const testRetentionDays = 123;
cliRepl.config.logRetentionDays = testRetentionDays;
await cliRepl.start(await testServer.connectionString(), {});

expect(cliRepl.getConfig('logRetentionDays')).equals(
testRetentionDays
);
expect(cliRepl.logManager?._options.retentionDays).equals(
testRetentionDays
);
});
});

it('times out fast', async function () {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-repl/src/cli-repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export class CliRepl implements MongoshIOProvider {
directory:
(await this.getConfig('logLocation')) ||
this.shellHomeDirectory.localPath('.'),
retentionDays: 30,
retentionDays: await this.getConfig('logRetentionDays'),
maxLogFileCount: +(
process.env.MONGOSH_TEST_ONLY_MAX_LOG_FILE_COUNT || 100
),
Expand Down
6 changes: 6 additions & 0 deletions packages/types/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ describe('config validation', function () {
expect(await validate('historyLength', 0)).to.equal(null);
expect(await validate('historyLength', 1)).to.equal(null);
expect(await validate('historyLength', Infinity)).to.equal(null);
expect(await validate('logRetentionDays', 'foo')).to.equal(
'logRetentionDays must be a positive integer'
);
expect(await validate('logRetentionDays', -1)).to.equal(
'logRetentionDays must be a positive integer'
);
expect(await validate('showStackTraces', 'foo')).to.equal(
'showStackTraces must be a boolean'
);
Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ export class CliUserConfig extends SnippetShellUserConfig {
updateURL = 'https://downloads.mongodb.com/compass/mongosh.json';
disableLogging = false;
logLocation: string | undefined = undefined;
logRetentionDays = 30;
}

export class CliUserConfigValidator extends SnippetShellUserConfigValidator {
Expand All @@ -531,6 +532,7 @@ export class CliUserConfigValidator extends SnippetShellUserConfigValidator {
return null;
case 'inspectDepth':
case 'historyLength':
case 'logRetentionDays':
if (typeof value !== 'number' || value < 0) {
return `${key} must be a positive integer`;
}
Expand Down

0 comments on commit 6236c36

Please sign in to comment.