-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Adds a list of Alert Instances to the Alert Details page based off of the current state of the Alert. Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
7339d02
commit 9017c99
Showing
27 changed files
with
1,398 additions
and
180 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import * as t from 'io-ts'; | ||
import { DateFromString } from './date_from_string'; | ||
|
||
const metaSchema = t.partial({ | ||
lastScheduledActions: t.type({ | ||
group: t.string, | ||
date: DateFromString, | ||
}), | ||
}); | ||
export type AlertInstanceMeta = t.TypeOf<typeof metaSchema>; | ||
|
||
const stateSchema = t.record(t.string, t.unknown); | ||
export type AlertInstanceState = t.TypeOf<typeof stateSchema>; | ||
|
||
export const rawAlertInstance = t.partial({ | ||
state: stateSchema, | ||
meta: metaSchema, | ||
}); | ||
export type RawAlertInstance = t.TypeOf<typeof rawAlertInstance>; |
26 changes: 26 additions & 0 deletions
26
x-pack/legacy/plugins/alerting/common/alert_task_instance.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,26 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import * as t from 'io-ts'; | ||
import { rawAlertInstance } from './alert_instance'; | ||
import { DateFromString } from './date_from_string'; | ||
|
||
export const alertStateSchema = t.partial({ | ||
alertTypeState: t.record(t.string, t.unknown), | ||
alertInstances: t.record(t.string, rawAlertInstance), | ||
previousStartedAt: t.union([t.null, DateFromString]), | ||
}); | ||
|
||
export type AlertTaskState = t.TypeOf<typeof alertStateSchema>; | ||
|
||
export const alertParamsSchema = t.intersection([ | ||
t.type({ | ||
alertId: t.string, | ||
}), | ||
t.partial({ | ||
spaceId: t.string, | ||
}), | ||
]); | ||
export type AlertTaskParams = t.TypeOf<typeof alertParamsSchema>; |
28 changes: 28 additions & 0 deletions
28
x-pack/legacy/plugins/alerting/common/date_from_string.test.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,28 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { DateFromString } from './date_from_string'; | ||
import { right, isLeft } from 'fp-ts/lib/Either'; | ||
|
||
describe('DateFromString', () => { | ||
test('validated and parses a string into a Date', () => { | ||
const date = new Date(1973, 10, 30); | ||
expect(DateFromString.decode(date.toISOString())).toEqual(right(date)); | ||
}); | ||
|
||
test('validated and returns a failure for an actual Date', () => { | ||
const date = new Date(1973, 10, 30); | ||
expect(isLeft(DateFromString.decode(date))).toEqual(true); | ||
}); | ||
|
||
test('validated and returns a failure for an invalid Date string', () => { | ||
expect(isLeft(DateFromString.decode('1234-23-45'))).toEqual(true); | ||
}); | ||
|
||
test('validated and returns a failure for a null value', () => { | ||
expect(isLeft(DateFromString.decode(null))).toEqual(true); | ||
}); | ||
}); |
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,26 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import * as t from 'io-ts'; | ||
import { either } from 'fp-ts/lib/Either'; | ||
|
||
// represents a Date from an ISO string | ||
export const DateFromString = new t.Type<Date, string, unknown>( | ||
'DateFromString', | ||
// detect the type | ||
(value): value is Date => value instanceof Date, | ||
(valueToDecode, context) => | ||
either.chain( | ||
// validate this is a string | ||
t.string.validate(valueToDecode, context), | ||
// decode | ||
value => { | ||
const decoded = new Date(value); | ||
return isNaN(decoded.getTime()) ? t.failure(valueToDecode, context) : t.success(decoded); | ||
} | ||
), | ||
valueToEncode => valueToEncode.toISOString() | ||
); |
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
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
Oops, something went wrong.