Skip to content

Commit

Permalink
Preserve existing functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisronline committed Jun 22, 2021
1 parent c0deeea commit afc2551
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
18 changes: 18 additions & 0 deletions x-pack/plugins/task_manager/server/lib/log_health_metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,24 @@ describe('logHealthMetrics', () => {
expect(firstDebug).toMatchObject(health);
});

it('should log as debug if status is OK even if not enabled', () => {
const logger = loggingSystemMock.create().get();
const config = getTaskManagerConfig({
monitored_stats_health_verbose_log: {
enabled: false,
warn_delayed_task_start_in_seconds: 60,
},
});
const health = getMockMonitoredHealth();

logHealthMetrics(health, logger, config);

const firstDebug = JSON.parse(
(logger as jest.Mocked<Logger>).debug.mock.calls[0][0].replace('Latest Monitored Stats: ', '')
);
expect(firstDebug).toMatchObject(health);
});

it('should log as warn if status is Warn', () => {
const logger = loggingSystemMock.create().get();
const config = getTaskManagerConfig({
Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/task_manager/server/lib/log_health_metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function logHealthMetrics(
logLevel = LogLevel.Error;
}

const message = `Latest Monitored Stats: ${JSON.stringify(monitoredHealth)}`;
if (enabled) {
const driftInSeconds = (monitoredHealth.stats.runtime?.value.drift.p99 ?? 0) / 1000;
if (
Expand All @@ -53,8 +54,6 @@ export function logHealthMetrics(
);
logLevel = LogLevel.Warn;
}

const message = `Latest Monitored Stats: ${JSON.stringify(monitoredHealth)}`;
switch (logLevel) {
case LogLevel.Warn:
logger.warn(message);
Expand All @@ -66,6 +65,8 @@ export function logHealthMetrics(
logger.debug(message);
}
} else {
// This is legacy support - we used to always show this
logger.debug(message);
if (logLevel !== LogLevel.Debug && lastLogLevel === LogLevel.Debug) {
logger.warn(
`Detected potential performance issue with Task Manager. Set 'xpack.task_manager.monitored_stats_health_verbose_log.enabled: true' in your Kibana.yml to enable debug logging`
Expand Down

0 comments on commit afc2551

Please sign in to comment.