Fix typo in alerting_framework_health field name (#120496)

* Fix type in alerting_framework_health field name

So that it's set in accordance with the documentation
https://www.elastic.co/guide/en/kibana/current/get-alerting-framework-health-api.html

* ENH: Make sure to return the older field as well to avoid breaking existing code

* DOC: Document the typo field "alerting_framework_heath"

* ENH: Add a _deprecated field in the typo field response

* fixed es lint spaces issues

* fixed more spaces issues

* fixed scope issue

* fixed scope issue

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: YulNaumenko <jo.naumenko@gmail.com>
This commit is contained in:
Thomas P 2021-12-23 01:38:40 +01:00 committed by GitHub
parent ec2090931b
commit ac7636c31b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 215 additions and 27 deletions

View file

@ -3450,10 +3450,10 @@
},
{
"parentPluginId": "alerting",
"id": "def-common.AlertingFrameworkHealth.alertingFrameworkHeath",
"id": "def-common.AlertingFrameworkHealth.alertingFrameworkHealth",
"type": "Object",
"tags": [],
"label": "alertingFrameworkHeath",
"label": "alertingFrameworkHealth",
"description": [],
"signature": [
{

View file

@ -74,6 +74,9 @@ The health API response contains the following properties:
| `alerting_framework_health`
| This state property has three substates that identify the health of the alerting framework API: `decryption_health`, `execution_health`, and `read_health`.
| deprecated::`alerting_framework_heath`
| This state property has a typo, use `alerting_framework_health` instead. It has three substates that identify the health of the alerting framework API: `decryption_health`, `execution_health`, and `read_health`.
|===
`alerting_framework_health` consists of the following properties:

View file

@ -45,7 +45,7 @@ The API returns the following:
{
"isSufficientlySecure":true,
"hasPermanentEncryptionKey":true,
"alertingFrameworkHeath":{
"alertingFrameworkHealth":{
"decryptionHealth":{
"status":"ok",
"timestamp":"2021-02-10T23:35:04.949Z"
@ -73,12 +73,12 @@ The health API response contains the following properties:
| `hasPermanentEncryptionKey`
| Return the state `false` if Encrypted Saved Object plugin has not a permanent encryption Key.
| `alertingFrameworkHeath`
| `alertingFrameworkHealth`
| This state property has three substates that identify the health of the alerting framework API: `decryptionHealth`, `executionHealth`, and `readHealth`.
|===
`alertingFrameworkHeath` consists of the following properties:
`alertingFrameworkHealth` consists of the following properties:
[cols="2*<"]
|===

View file

@ -24,7 +24,7 @@ export * from './parse_duration';
export interface AlertingFrameworkHealth {
isSufficientlySecure: boolean;
hasPermanentEncryptionKey: boolean;
alertingFrameworkHeath: AlertsHealth;
alertingFrameworkHealth: AlertsHealth;
}
export const LEGACY_BASE_ALERT_API_PATH = '/api/alerts';

View file

@ -156,6 +156,22 @@ describe('healthRoute', () => {
expect(await handler(context, req, res)).toStrictEqual({
body: {
alerting_framework_heath: {
// Legacy: pre-v8.0 typo
_deprecated: 'This state property has a typo, use "alerting_framework_health" instead.',
decryption_health: {
status: HealthStatus.OK,
timestamp: currentDate,
},
execution_health: {
status: HealthStatus.OK,
timestamp: currentDate,
},
read_health: {
status: HealthStatus.OK,
timestamp: currentDate,
},
},
alerting_framework_health: {
decryption_health: {
status: HealthStatus.OK,
timestamp: currentDate,
@ -198,6 +214,22 @@ describe('healthRoute', () => {
expect(await handler(context, req, res)).toStrictEqual({
body: {
alerting_framework_heath: {
// Legacy: pre-v8.0 typo
_deprecated: 'This state property has a typo, use "alerting_framework_health" instead.',
decryption_health: {
status: HealthStatus.OK,
timestamp: currentDate,
},
execution_health: {
status: HealthStatus.OK,
timestamp: currentDate,
},
read_health: {
status: HealthStatus.OK,
timestamp: currentDate,
},
},
alerting_framework_health: {
decryption_health: {
status: HealthStatus.OK,
timestamp: currentDate,
@ -240,6 +272,22 @@ describe('healthRoute', () => {
expect(await handler(context, req, res)).toStrictEqual({
body: {
alerting_framework_heath: {
// Legacy: pre-v8.0 typo
_deprecated: 'This state property has a typo, use "alerting_framework_health" instead.',
decryption_health: {
status: HealthStatus.OK,
timestamp: currentDate,
},
execution_health: {
status: HealthStatus.OK,
timestamp: currentDate,
},
read_health: {
status: HealthStatus.OK,
timestamp: currentDate,
},
},
alerting_framework_health: {
decryption_health: {
status: HealthStatus.OK,
timestamp: currentDate,
@ -282,6 +330,22 @@ describe('healthRoute', () => {
expect(await handler(context, req, res)).toStrictEqual({
body: {
alerting_framework_heath: {
// Legacy: pre-v8.0 typo
_deprecated: 'This state property has a typo, use "alerting_framework_health" instead.',
decryption_health: {
status: HealthStatus.OK,
timestamp: currentDate,
},
execution_health: {
status: HealthStatus.OK,
timestamp: currentDate,
},
read_health: {
status: HealthStatus.OK,
timestamp: currentDate,
},
},
alerting_framework_health: {
decryption_health: {
status: HealthStatus.OK,
timestamp: currentDate,
@ -324,6 +388,22 @@ describe('healthRoute', () => {
expect(await handler(context, req, res)).toStrictEqual({
body: {
alerting_framework_heath: {
// Legacy: pre-v8.0 typo
_deprecated: 'This state property has a typo, use "alerting_framework_health" instead.',
decryption_health: {
status: HealthStatus.OK,
timestamp: currentDate,
},
execution_health: {
status: HealthStatus.OK,
timestamp: currentDate,
},
read_health: {
status: HealthStatus.OK,
timestamp: currentDate,
},
},
alerting_framework_health: {
decryption_health: {
status: HealthStatus.OK,
timestamp: currentDate,

View file

@ -19,16 +19,23 @@ import { getSecurityHealth } from '../lib/get_security_health';
const rewriteBodyRes: RewriteResponseCase<AlertingFrameworkHealth> = ({
isSufficientlySecure,
hasPermanentEncryptionKey,
alertingFrameworkHeath,
alertingFrameworkHealth,
...rest
}) => ({
...rest,
is_sufficiently_secure: isSufficientlySecure,
has_permanent_encryption_key: hasPermanentEncryptionKey,
alerting_framework_health: {
decryption_health: alertingFrameworkHealth.decryptionHealth,
execution_health: alertingFrameworkHealth.executionHealth,
read_health: alertingFrameworkHealth.readHealth,
},
alerting_framework_heath: {
decryption_health: alertingFrameworkHeath.decryptionHealth,
execution_health: alertingFrameworkHeath.executionHealth,
read_health: alertingFrameworkHeath.readHealth,
// Legacy: pre-v8.0 typo
_deprecated: 'This state property has a typo, use "alerting_framework_health" instead.',
decryption_health: alertingFrameworkHealth.decryptionHealth,
execution_health: alertingFrameworkHealth.executionHealth,
read_health: alertingFrameworkHealth.readHealth,
},
});
@ -48,7 +55,7 @@ export const healthRoute = (
// Verify that user has access to at least one rule type
const ruleTypes = Array.from(await context.alerting.getRulesClient().listAlertTypes());
if (ruleTypes.length > 0) {
const alertingFrameworkHeath = await context.alerting.getFrameworkHealth();
const alertingFrameworkHealth = await context.alerting.getFrameworkHealth();
const securityHealth = await getSecurityHealth(
async () => (licenseState ? licenseState.getIsSecurityEnabled() : null),
@ -58,7 +65,7 @@ export const healthRoute = (
const frameworkHealth: AlertingFrameworkHealth = {
...securityHealth,
alertingFrameworkHeath,
alertingFrameworkHealth,
};
return res.ok({

View file

@ -137,6 +137,22 @@ describe('healthRoute', () => {
expect(await handler(context, req, res)).toStrictEqual({
body: {
alertingFrameworkHeath: {
// Legacy: pre-v8.0 typo
_deprecated: 'This state property has a typo, use "alertingFrameworkHealth" instead.',
decryptionHealth: {
status: HealthStatus.OK,
timestamp: currentDate,
},
executionHealth: {
status: HealthStatus.OK,
timestamp: currentDate,
},
readHealth: {
status: HealthStatus.OK,
timestamp: currentDate,
},
},
alertingFrameworkHealth: {
decryptionHealth: {
status: HealthStatus.OK,
timestamp: currentDate,
@ -179,6 +195,22 @@ describe('healthRoute', () => {
expect(await handler(context, req, res)).toStrictEqual({
body: {
alertingFrameworkHeath: {
// Legacy: pre-v8.0 typo
_deprecated: 'This state property has a typo, use "alertingFrameworkHealth" instead.',
decryptionHealth: {
status: HealthStatus.OK,
timestamp: currentDate,
},
executionHealth: {
status: HealthStatus.OK,
timestamp: currentDate,
},
readHealth: {
status: HealthStatus.OK,
timestamp: currentDate,
},
},
alertingFrameworkHealth: {
decryptionHealth: {
status: HealthStatus.OK,
timestamp: currentDate,
@ -221,6 +253,22 @@ describe('healthRoute', () => {
expect(await handler(context, req, res)).toStrictEqual({
body: {
alertingFrameworkHeath: {
// Legacy: pre-v8.0 typo
_deprecated: 'This state property has a typo, use "alertingFrameworkHealth" instead.',
decryptionHealth: {
status: HealthStatus.OK,
timestamp: currentDate,
},
executionHealth: {
status: HealthStatus.OK,
timestamp: currentDate,
},
readHealth: {
status: HealthStatus.OK,
timestamp: currentDate,
},
},
alertingFrameworkHealth: {
decryptionHealth: {
status: HealthStatus.OK,
timestamp: currentDate,
@ -263,6 +311,22 @@ describe('healthRoute', () => {
expect(await handler(context, req, res)).toStrictEqual({
body: {
alertingFrameworkHeath: {
// Legacy: pre-v8.0 typo
_deprecated: 'This state property has a typo, use "alertingFrameworkHealth" instead.',
decryptionHealth: {
status: HealthStatus.OK,
timestamp: currentDate,
},
executionHealth: {
status: HealthStatus.OK,
timestamp: currentDate,
},
readHealth: {
status: HealthStatus.OK,
timestamp: currentDate,
},
},
alertingFrameworkHealth: {
decryptionHealth: {
status: HealthStatus.OK,
timestamp: currentDate,
@ -305,6 +369,22 @@ describe('healthRoute', () => {
expect(await handler(context, req, res)).toStrictEqual({
body: {
alertingFrameworkHeath: {
// Legacy: pre-v8.0 typo
_deprecated: 'This state property has a typo, use "alertingFrameworkHealth" instead.',
decryptionHealth: {
status: HealthStatus.OK,
timestamp: currentDate,
},
executionHealth: {
status: HealthStatus.OK,
timestamp: currentDate,
},
readHealth: {
status: HealthStatus.OK,
timestamp: currentDate,
},
},
alertingFrameworkHealth: {
decryptionHealth: {
status: HealthStatus.OK,
timestamp: currentDate,

View file

@ -35,7 +35,7 @@ export function healthRoute(
// Verify that user has access to at least one rule type
const ruleTypes = Array.from(await context.alerting.getRulesClient().listAlertTypes());
if (ruleTypes.length > 0) {
const alertingFrameworkHeath = await context.alerting.getFrameworkHealth();
const alertingFrameworkHealth = await context.alerting.getFrameworkHealth();
const securityHealth = await getSecurityHealth(
async () => (licenseState ? licenseState.getIsSecurityEnabled() : null),
@ -45,11 +45,19 @@ export function healthRoute(
const frameworkHealth: AlertingFrameworkHealth = {
...securityHealth,
alertingFrameworkHeath,
alertingFrameworkHealth,
};
return res.ok({
body: frameworkHealth,
body: {
...frameworkHealth,
alertingFrameworkHeath: {
// Legacy: pre-v8.0 typo
...alertingFrameworkHealth,
_deprecated:
'This state property has a typo, use "alertingFrameworkHealth" instead.',
},
},
});
} else {
return res.forbidden({

View file

@ -61,7 +61,7 @@ describe('health check', () => {
useKibanaMock().services.http.get = jest.fn().mockResolvedValue({
is_sufficiently_secure: true,
has_permanent_encryption_key: true,
alerting_framework_heath: {
alerting_framework_health: {
decryption_health: { status: 'ok', timestamp: '2021-04-01T21:29:22.991Z' },
execution_health: { status: 'ok', timestamp: '2021-04-01T21:29:22.991Z' },
read_health: { status: 'ok', timestamp: '2021-04-01T21:29:22.991Z' },
@ -85,7 +85,7 @@ describe('health check', () => {
useKibanaMock().services.http.get = jest.fn().mockImplementation(async () => ({
is_sufficiently_secure: false,
has_permanent_encryption_key: true,
alerting_framework_heath: {
alerting_framework_health: {
decryption_health: { status: 'ok', timestamp: '2021-04-01T21:29:22.991Z' },
execution_health: { status: 'ok', timestamp: '2021-04-01T21:29:22.991Z' },
read_health: { status: 'ok', timestamp: '2021-04-01T21:29:22.991Z' },
@ -121,7 +121,7 @@ describe('health check', () => {
useKibanaMock().services.http.get = jest.fn().mockImplementation(async () => ({
is_sufficiently_secure: true,
has_permanent_encryption_key: false,
alerting_framework_heath: {
alerting_framework_health: {
decryption_health: { status: 'ok', timestamp: '2021-04-01T21:29:22.991Z' },
execution_health: { status: 'ok', timestamp: '2021-04-01T21:29:22.991Z' },
read_health: { status: 'ok', timestamp: '2021-04-01T21:29:22.991Z' },
@ -157,7 +157,7 @@ describe('health check', () => {
useKibanaMock().services.http.get = jest.fn().mockImplementation(async () => ({
is_sufficiently_secure: false,
has_permanent_encryption_key: false,
alerting_framework_heath: {
alerting_framework_health: {
decryption_health: { status: 'ok', timestamp: '2021-04-01T21:29:22.991Z' },
execution_health: { status: 'ok', timestamp: '2021-04-01T21:29:22.991Z' },
read_health: { status: 'ok', timestamp: '2021-04-01T21:29:22.991Z' },

View file

@ -14,7 +14,7 @@ describe('alertingFrameworkHealth', () => {
http.get.mockResolvedValueOnce({
is_sufficiently_secure: true,
has_permanent_encryption_key: true,
alerting_framework_heath: {
alerting_framework_health: {
decryption_health: { status: 'ok', timestamp: '2021-04-01T21:29:22.991Z' },
execution_health: { status: 'ok', timestamp: '2021-04-01T21:29:22.991Z' },
read_health: { status: 'ok', timestamp: '2021-04-01T21:29:22.991Z' },
@ -22,7 +22,7 @@ describe('alertingFrameworkHealth', () => {
});
const result = await alertingFrameworkHealth({ http });
expect(result).toEqual({
alertingFrameworkHeath: {
alertingFrameworkHealth: {
decryptionHealth: { status: 'ok', timestamp: '2021-04-01T21:29:22.991Z' },
executionHealth: { status: 'ok', timestamp: '2021-04-01T21:29:22.991Z' },
readHealth: { status: 'ok', timestamp: '2021-04-01T21:29:22.991Z' },

View file

@ -9,7 +9,7 @@ import { AsApiContract, RewriteRequestCase } from '../../../../../actions/common
import { AlertingFrameworkHealth, AlertsHealth } from '../../../../../alerting/common';
import { BASE_ALERTING_API_PATH } from '../../constants';
const rewriteAlertingFrameworkHeath: RewriteRequestCase<AlertsHealth> = ({
const rewriteAlertingFrameworkHealth: RewriteRequestCase<AlertsHealth> = ({
decryption_health: decryptionHealth,
execution_health: executionHealth,
read_health: readHealth,
@ -24,12 +24,13 @@ const rewriteAlertingFrameworkHeath: RewriteRequestCase<AlertsHealth> = ({
const rewriteBodyRes: RewriteRequestCase<AlertingFrameworkHealth> = ({
is_sufficiently_secure: isSufficientlySecure,
has_permanent_encryption_key: hasPermanentEncryptionKey,
alerting_framework_heath: alertingFrameworkHeath,
// eslint-disable-next-line @typescript-eslint/no-shadow
alerting_framework_health: alertingFrameworkHealth,
...res
}: AsApiContract<AlertingFrameworkHealth>) => ({
isSufficientlySecure,
hasPermanentEncryptionKey,
alertingFrameworkHeath,
alertingFrameworkHealth,
...res,
});
@ -41,11 +42,11 @@ export async function alertingFrameworkHealth({
const res = await http.get<AsApiContract<AlertingFrameworkHealth>>(
`${BASE_ALERTING_API_PATH}/_health`
);
const alertingFrameworkHeath = rewriteAlertingFrameworkHeath(
res.alerting_framework_heath as unknown as AsApiContract<AlertsHealth>
const alertingFrameworkHealthRewrited = rewriteAlertingFrameworkHealth(
res.alerting_framework_health as unknown as AsApiContract<AlertsHealth>
);
return {
...rewriteBodyRes(res),
alertingFrameworkHeath,
alertingFrameworkHealth: alertingFrameworkHealthRewrited,
};
}

View file

@ -89,6 +89,10 @@ export default function createFindTests({ getService }: FtrProviderContext) {
default:
expect(health.is_sufficiently_secure).to.eql(true);
expect(health.has_permanent_encryption_key).to.eql(true);
expect(health.alerting_framework_health.decryption_health.status).to.eql('ok');
expect(health.alerting_framework_health.execution_health.status).to.eql('ok');
expect(health.alerting_framework_health.read_health.status).to.eql('ok');
// Legacy: pre-v8.0 typo
expect(health.alerting_framework_heath.decryption_health.status).to.eql('ok');
expect(health.alerting_framework_heath.execution_health.status).to.eql('ok');
expect(health.alerting_framework_heath.read_health.status).to.eql('ok');
@ -138,6 +142,11 @@ export default function createFindTests({ getService }: FtrProviderContext) {
});
break;
default:
expect(health.alerting_framework_health.execution_health.status).to.eql('warn');
expect(health.alerting_framework_health.execution_health.timestamp).to.eql(
ruleInErrorStatus.execution_status.last_execution_date
);
// Legacy: pre-v8.0 typo
expect(health.alerting_framework_heath.execution_health.status).to.eql('warn');
expect(health.alerting_framework_heath.execution_health.timestamp).to.eql(
ruleInErrorStatus.execution_status.last_execution_date