forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Task Manager] Log at different levels based on the state (elastic#10…
…1751) (elastic#102402) * Log at different levels based on the state * Fix types and add tests * Remove unnecessary code * Add more descriptive message * Partially fix failing tests * Move into separate function * Get rid of customStatus in favor of moving the logging logic to a separate, mockable function * Remove debug logging * Do not log as an error if the stats are empty * PR feedback * Add docker whitelist * alpha order * English is hard * Removing extra newline * PR feedback around ignoring capacity estimation * Move json utils
- Loading branch information
1 parent
df5c56d
commit b16513a
Showing
17 changed files
with
576 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
x-pack/plugins/task_manager/server/lib/calculate_health_status.mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
const createCalculateHealthStatusMock = () => { | ||
return jest.fn(); | ||
}; | ||
|
||
export const calculateHealthStatusMock = { | ||
create: createCalculateHealthStatusMock, | ||
}; |
79 changes: 79 additions & 0 deletions
79
x-pack/plugins/task_manager/server/lib/calculate_health_status.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { isString } from 'lodash'; | ||
import { JsonValue } from '@kbn/common-utils'; | ||
import { HealthStatus, RawMonitoringStats } from '../monitoring'; | ||
import { TaskManagerConfig } from '../config'; | ||
|
||
export function calculateHealthStatus( | ||
summarizedStats: RawMonitoringStats, | ||
config: TaskManagerConfig | ||
): HealthStatus { | ||
const now = Date.now(); | ||
|
||
// if "hot" health stats are any more stale than monitored_stats_required_freshness (pollInterval +1s buffer by default) | ||
// consider the system unhealthy | ||
const requiredHotStatsFreshness: number = config.monitored_stats_required_freshness; | ||
|
||
// if "cold" health stats are any more stale than the configured refresh (+ a buffer), consider the system unhealthy | ||
const requiredColdStatsFreshness: number = config.monitored_aggregated_stats_refresh_rate * 1.5; | ||
|
||
/** | ||
* If the monitored stats aren't fresh, return a red status | ||
*/ | ||
const healthStatus = | ||
hasStatus(summarizedStats.stats, HealthStatus.Error) || | ||
hasExpiredHotTimestamps(summarizedStats, now, requiredHotStatsFreshness) || | ||
hasExpiredColdTimestamps(summarizedStats, now, requiredColdStatsFreshness) | ||
? HealthStatus.Error | ||
: hasStatus(summarizedStats.stats, HealthStatus.Warning) | ||
? HealthStatus.Warning | ||
: HealthStatus.OK; | ||
return healthStatus; | ||
} | ||
|
||
function hasStatus(stats: RawMonitoringStats['stats'], status: HealthStatus): boolean { | ||
return Object.values(stats) | ||
.map((stat) => stat?.status === status) | ||
.includes(true); | ||
} | ||
|
||
/** | ||
* If certain "hot" stats are not fresh, then the _health api will should return a Red status | ||
* @param monitoringStats The monitored stats | ||
* @param now The time to compare against | ||
* @param requiredFreshness How fresh should these stats be | ||
*/ | ||
function hasExpiredHotTimestamps( | ||
monitoringStats: RawMonitoringStats, | ||
now: number, | ||
requiredFreshness: number | ||
): boolean { | ||
const diff = | ||
now - | ||
getOldestTimestamp( | ||
monitoringStats.last_update, | ||
monitoringStats.stats.runtime?.value.polling.last_successful_poll | ||
); | ||
return diff > requiredFreshness; | ||
} | ||
|
||
function hasExpiredColdTimestamps( | ||
monitoringStats: RawMonitoringStats, | ||
now: number, | ||
requiredFreshness: number | ||
): boolean { | ||
return now - getOldestTimestamp(monitoringStats.stats.workload?.timestamp) > requiredFreshness; | ||
} | ||
|
||
function getOldestTimestamp(...timestamps: Array<JsonValue | undefined>): number { | ||
const validTimestamps = timestamps | ||
.map((timestamp) => (isString(timestamp) ? Date.parse(timestamp) : NaN)) | ||
.filter((timestamp) => !isNaN(timestamp)); | ||
return validTimestamps.length ? Math.min(...validTimestamps) : 0; | ||
} |
14 changes: 14 additions & 0 deletions
14
x-pack/plugins/task_manager/server/lib/log_health_metrics.mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
const createLogHealthMetricsMock = () => { | ||
return jest.fn(); | ||
}; | ||
|
||
export const logHealthMetricsMock = { | ||
create: createLogHealthMetricsMock, | ||
}; |
Oops, something went wrong.