Skip to content

Commit

Permalink
fix(NA): log rotation watchers usage (#60956) (#61024)
Browse files Browse the repository at this point in the history
* fix(NA): log rotation watchers usage

* docs(NA): add old value to the example

* chore(NA): change warning messages
  • Loading branch information
mistic authored Mar 24, 2020
1 parent 2eecaf4 commit 192d348
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
4 changes: 2 additions & 2 deletions docs/setup/settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ that feature would not take any effect.

`logging.rotate.everyBytes:`:: [experimental] *Default: 10485760* The maximum size of a log file (that is `not an exact` limit). After the
limit is reached, a new log file is generated. The default size limit is 10485760 (10 MB) and
this option should be in the range of 102400 (100KB) to 1073741824 (1GB).
this option should be in the range of 1048576 (1 MB) to 1073741824 (1 GB).

`logging.rotate.keepFiles:`:: [experimental] *Default: 7* The number of most recent rotated log files to keep
on disk. Older files are deleted during log rotation. The default value is 7. The `logging.rotate.keepFiles`
Expand All @@ -210,7 +210,7 @@ option has to be in the range of 2 to 1024 files.
the `logging.rotate.usePolling` is enabled. That option has to be in the range of 5000 to 3600000 milliseconds.

`logging.rotate.usePolling:`:: [experimental] *Default: false* By default we try to understand the best way to monitoring
the log file. However, there is some systems where it could not be always accurate. In those cases, if needed,
the log file and warning about it. Please be aware there are some systems where watch api is not accurate. In those cases, in order to get the feature working,
the `polling` method could be used enabling that option.

`logging.silent:`:: *Default: false* Set the value of this setting to `true` to
Expand Down
4 changes: 2 additions & 2 deletions src/legacy/server/config/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ export default () =>
.keys({
enabled: Joi.boolean().default(false),
everyBytes: Joi.number()
// > 100KB
.greater(102399)
// > 1MB
.greater(1048576)
// < 1GB
.less(1073741825)
// 10MB
Expand Down
10 changes: 6 additions & 4 deletions src/legacy/server/logging/rotate/log_rotator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ describe('LogRotator', () => {
expect(logRotator.running).toBe(true);
expect(logRotator.usePolling).toBe(false);

const usePolling = await logRotator._shouldUsePolling();
expect(usePolling).toBe(false);
const shouldUsePolling = await logRotator._shouldUsePolling();
expect(shouldUsePolling).toBe(false);

await logRotator.stop();
});
Expand All @@ -231,7 +231,8 @@ describe('LogRotator', () => {
await logRotator.start();

expect(logRotator.running).toBe(true);
expect(logRotator.usePolling).toBe(true);
expect(logRotator.usePolling).toBe(false);
expect(logRotator.shouldUsePolling).toBe(true);

await logRotator.stop();
});
Expand All @@ -257,7 +258,8 @@ describe('LogRotator', () => {
await logRotator.start();

expect(logRotator.running).toBe(true);
expect(logRotator.usePolling).toBe(true);
expect(logRotator.usePolling).toBe(false);
expect(logRotator.shouldUsePolling).toBe(true);

await logRotator.stop();
jest.useRealTimers();
Expand Down
16 changes: 13 additions & 3 deletions src/legacy/server/logging/rotate/log_rotator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class LogRotator {
public usePolling: boolean;
public pollingInterval: number;
private stalkerUsePollingPolicyTestTimeout: NodeJS.Timeout | null;
public shouldUsePolling: boolean;

constructor(config: KibanaConfig, server: Server) {
this.config = config;
Expand All @@ -64,6 +65,7 @@ export class LogRotator {
this.stalker = null;
this.usePolling = config.get('logging.rotate.usePolling');
this.pollingInterval = config.get('logging.rotate.pollingInterval');
this.shouldUsePolling = false;
this.stalkerUsePollingPolicyTestTimeout = null;
}

Expand Down Expand Up @@ -150,12 +152,20 @@ export class LogRotator {
}

async _startLogFileSizeMonitor() {
this.usePolling = await this._shouldUsePolling();
this.usePolling = this.config.get('logging.rotate.usePolling');
this.shouldUsePolling = await this._shouldUsePolling();

if (this.usePolling && this.usePolling !== this.config.get('logging.rotate.usePolling')) {
if (this.usePolling && !this.shouldUsePolling) {
this.log(
['warning', 'logging:rotate'],
'The current environment does not support `fs.watch`. Falling back to polling using `fs.watchFile`'
'Looks like your current environment support a faster algorithm then polling. You can try to disable `usePolling`'
);
}

if (!this.usePolling && this.shouldUsePolling) {
this.log(
['error', 'logging:rotate'],
'Looks like within your current environment you need to use polling in order to enable log rotator. Please enable `usePolling`'
);
}

Expand Down

0 comments on commit 192d348

Please sign in to comment.