diff --git a/examples/alerts_demo/common/constants.ts b/examples/alerts_demo/common/constants.ts index 3c6b12e463b03..99edb2218e07c 100644 --- a/examples/alerts_demo/common/constants.ts +++ b/examples/alerts_demo/common/constants.ts @@ -8,7 +8,7 @@ import { AlertTypeParams } from '../../../x-pack/plugins/alerting/common'; -export const ALERTS_DEMO_APP_ID = 'AlertsDemo'; +export const ALERTS_DEMO_APP_ID = 'alerts_demo'; // always firing export const DEFAULT_INSTANCES_TO_GENERATE = 5; diff --git a/examples/alerts_demo/public/plugin.ts b/examples/alerts_demo/public/plugin.ts index 511c98b2dc68c..96e94fdd5303b 100755 --- a/examples/alerts_demo/public/plugin.ts +++ b/examples/alerts_demo/public/plugin.ts @@ -17,6 +17,7 @@ import { AlertsDemoClientSetupDeps, AlertsDemoClientStartDeps, } from './types'; +import { ALERTS_DEMO_APP_ID } from '../common/constants'; import { PLUGIN_NAME } from '../common'; import { DEFAULT_APP_CATEGORIES } from '../../../src/core/public'; // import { getAlertType as getAlwaysFiringAlertType } from './alert_types/always_firing'; @@ -47,9 +48,11 @@ export class AlertsDemoPlugin implements AlertsDemoPluginClass { pluginsSetup.observability.observabilityRuleTypeRegistry.register( createAlwaysFiringAlertType() ); + + // console.log(pluginsSetup.observability.observabilityRuleTypeRegistry.list(), '!!list'); // pluginsSetup.triggersActionsUi.ruleTypeRegistry.register(getAlwaysFiringAlertType()); pluginsSetup.developerExamples.register({ - appId: 'alertsDemo', + appId: ALERTS_DEMO_APP_ID, title: 'Alerts Demo example', description: 'This alerting example walks you through how to set up a new rule.', links: [ @@ -64,7 +67,7 @@ export class AlertsDemoPlugin implements AlertsDemoPluginClass { }); // Register an application into the side navigation menu core.application.register({ - id: 'alertsDemo', + id: ALERTS_DEMO_APP_ID, title: PLUGIN_NAME, category: DEFAULT_APP_CATEGORIES.observability, async mount(params: AppMountParameters) { diff --git a/examples/alerts_demo/server/alert_types/always_firing.ts b/examples/alerts_demo/server/alert_types/always_firing.ts index f6a5c345c9f0e..b7f6ff7e6eb2a 100644 --- a/examples/alerts_demo/server/alert_types/always_firing.ts +++ b/examples/alerts_demo/server/alert_types/always_firing.ts @@ -71,6 +71,7 @@ export const createAlertsDemoExecutor = (libs: BackendLibs) => >(async function ({ services, params: { instances = DEFAULT_INSTANCES_TO_GENERATE, thresholds }, + state, }) { const { alertWithLifecycle } = services; const alertInstanceFactory: AlertInstanceFactory = (id, reason) => @@ -80,12 +81,15 @@ export const createAlertsDemoExecutor = (libs: BackendLibs) => [ALERT_REASON]: reason, }, }); + + const count = (state.count ?? 0) + 1; range(instances) .map(() => uuid.v4()) .forEach((id: string) => { const tShirtSize = getTShirtSizeByIdAndThreshold(id, thresholds); - const alertInstance = alertInstanceFactory(id, tShirtSize); - alertInstance.scheduleActions(tShirtSize); + alertInstanceFactory(id, tShirtSize) + .replaceState({ triggerdOnCycle: count }) + .scheduleActions(tShirtSize); }); }); diff --git a/examples/alerts_demo/server/plugin.ts b/examples/alerts_demo/server/plugin.ts index 49d3c79c660ba..3f46a5e491bc3 100755 --- a/examples/alerts_demo/server/plugin.ts +++ b/examples/alerts_demo/server/plugin.ts @@ -31,7 +31,7 @@ export class AlertsDemoPlugin implements Plugin = []; - + const registeredRuleTypes: string[] = []; return { + list: () => { + return registeredRuleTypes; + }, register: (type: ObservabilityRuleTypeModel) => { const { format, ...rest } = type; + registeredRuleTypes.push(type.id); formatters.push({ typeId: type.id, fn: format }); ruleTypeRegistry.register(rest); }, diff --git a/x-pack/plugins/observability/public/services/get_observability_alerts.ts b/x-pack/plugins/observability/public/services/get_observability_alerts.ts index 2cb30ca004c86..7e152975a026b 100644 --- a/x-pack/plugins/observability/public/services/get_observability_alerts.ts +++ b/x-pack/plugins/observability/public/services/get_observability_alerts.ts @@ -8,7 +8,7 @@ import { CoreStart } from 'kibana/public'; import { Alert } from '../../../alerting/common'; -const allowedConsumers = ['apm', 'uptime', 'logs', 'infrastructure', 'alerts']; +const allowedConsumers = ['apm', 'uptime', 'logs', 'infrastructure', 'alerts', 'alerts_demo']; export async function getObservabilityAlerts({ core }: { core: CoreStart }) { try {