[Metrics UI] Make alert instance IDs more useful (#70100)

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Zacqary Adam Xeper 2020-06-30 12:59:19 -05:00 committed by GitHub
parent bb7bc782b2
commit 0f78bc9ba5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 15 deletions

View file

@ -39,7 +39,7 @@ export const createInventoryMetricThresholdExecutor = (
const inventoryItems = Object.keys(first(results)); const inventoryItems = Object.keys(first(results));
for (const item of inventoryItems) { for (const item of inventoryItems) {
const alertInstance = services.alertInstanceFactory(`${alertId}-${item}`); const alertInstance = services.alertInstanceFactory(`${item}::${alertId}`);
// AND logic; all criteria must be across the threshold // AND logic; all criteria must be across the threshold
const shouldAlertFire = results.every((result) => result[item].shouldFire); const shouldAlertFire = results.every((result) => result[item].shouldFire);

View file

@ -24,7 +24,7 @@ let persistAlertInstances = false; // eslint-disable-line
describe('The metric threshold alert type', () => { describe('The metric threshold alert type', () => {
describe('querying the entire infrastructure', () => { describe('querying the entire infrastructure', () => {
const instanceID = 'test-*'; const instanceID = '*::test';
const execute = (comparator: Comparator, threshold: number[], sourceId: string = 'default') => const execute = (comparator: Comparator, threshold: number[], sourceId: string = 'default') =>
executor({ executor({
services, services,
@ -118,8 +118,8 @@ describe('The metric threshold alert type', () => {
], ],
}, },
}); });
const instanceIdA = 'test-a'; const instanceIdA = 'a::test';
const instanceIdB = 'test-b'; const instanceIdB = 'b::test';
test('sends an alert when all groups pass the threshold', async () => { test('sends an alert when all groups pass the threshold', async () => {
await execute(Comparator.GT, [0.75]); await execute(Comparator.GT, [0.75]);
expect(mostRecentAction(instanceIdA).id).toBe(FIRED_ACTIONS.id); expect(mostRecentAction(instanceIdA).id).toBe(FIRED_ACTIONS.id);
@ -175,20 +175,20 @@ describe('The metric threshold alert type', () => {
}, },
}); });
test('sends an alert when all criteria cross the threshold', async () => { test('sends an alert when all criteria cross the threshold', async () => {
const instanceID = 'test-*'; const instanceID = '*::test';
await execute(Comparator.GT_OR_EQ, [1.0], [3.0]); await execute(Comparator.GT_OR_EQ, [1.0], [3.0]);
expect(mostRecentAction(instanceID).id).toBe(FIRED_ACTIONS.id); expect(mostRecentAction(instanceID).id).toBe(FIRED_ACTIONS.id);
expect(getState(instanceID).alertState).toBe(AlertStates.ALERT); expect(getState(instanceID).alertState).toBe(AlertStates.ALERT);
}); });
test('sends no alert when some, but not all, criteria cross the threshold', async () => { test('sends no alert when some, but not all, criteria cross the threshold', async () => {
const instanceID = 'test-*'; const instanceID = '*::test';
await execute(Comparator.LT_OR_EQ, [1.0], [3.0]); await execute(Comparator.LT_OR_EQ, [1.0], [3.0]);
expect(mostRecentAction(instanceID)).toBe(undefined); expect(mostRecentAction(instanceID)).toBe(undefined);
expect(getState(instanceID).alertState).toBe(AlertStates.OK); expect(getState(instanceID).alertState).toBe(AlertStates.OK);
}); });
test('alerts only on groups that meet all criteria when querying with a groupBy parameter', async () => { test('alerts only on groups that meet all criteria when querying with a groupBy parameter', async () => {
const instanceIdA = 'test-a'; const instanceIdA = 'a::test';
const instanceIdB = 'test-b'; const instanceIdB = 'b::test';
await execute(Comparator.GT_OR_EQ, [1.0], [3.0], 'something'); await execute(Comparator.GT_OR_EQ, [1.0], [3.0], 'something');
expect(mostRecentAction(instanceIdA).id).toBe(FIRED_ACTIONS.id); expect(mostRecentAction(instanceIdA).id).toBe(FIRED_ACTIONS.id);
expect(getState(instanceIdA).alertState).toBe(AlertStates.ALERT); expect(getState(instanceIdA).alertState).toBe(AlertStates.ALERT);
@ -196,7 +196,7 @@ describe('The metric threshold alert type', () => {
expect(getState(instanceIdB).alertState).toBe(AlertStates.OK); expect(getState(instanceIdB).alertState).toBe(AlertStates.OK);
}); });
test('sends all criteria to the action context', async () => { test('sends all criteria to the action context', async () => {
const instanceID = 'test-*'; const instanceID = '*::test';
await execute(Comparator.GT_OR_EQ, [1.0], [3.0]); await execute(Comparator.GT_OR_EQ, [1.0], [3.0]);
const { action } = mostRecentAction(instanceID); const { action } = mostRecentAction(instanceID);
const reasons = action.reason.split('\n'); const reasons = action.reason.split('\n');
@ -210,7 +210,7 @@ describe('The metric threshold alert type', () => {
}); });
}); });
describe('querying with the count aggregator', () => { describe('querying with the count aggregator', () => {
const instanceID = 'test-*'; const instanceID = '*::test';
const execute = (comparator: Comparator, threshold: number[]) => const execute = (comparator: Comparator, threshold: number[]) =>
executor({ executor({
services, services,
@ -236,7 +236,7 @@ describe('The metric threshold alert type', () => {
}); });
}); });
describe('querying with the p99 aggregator', () => { describe('querying with the p99 aggregator', () => {
const instanceID = 'test-*'; const instanceID = '*::test';
const execute = (comparator: Comparator, threshold: number[]) => const execute = (comparator: Comparator, threshold: number[]) =>
executor({ executor({
services, services,
@ -262,7 +262,7 @@ describe('The metric threshold alert type', () => {
}); });
}); });
describe('querying with the p95 aggregator', () => { describe('querying with the p95 aggregator', () => {
const instanceID = 'test-*'; const instanceID = '*::test';
const execute = (comparator: Comparator, threshold: number[]) => const execute = (comparator: Comparator, threshold: number[]) =>
executor({ executor({
services, services,
@ -288,7 +288,7 @@ describe('The metric threshold alert type', () => {
}); });
}); });
describe("querying a metric that hasn't reported data", () => { describe("querying a metric that hasn't reported data", () => {
const instanceID = 'test-*'; const instanceID = '*::test';
const execute = (alertOnNoData: boolean) => const execute = (alertOnNoData: boolean) =>
executor({ executor({
services, services,
@ -317,7 +317,7 @@ describe('The metric threshold alert type', () => {
}); });
// describe('querying a metric that later recovers', () => { // describe('querying a metric that later recovers', () => {
// const instanceID = 'test-*'; // const instanceID = '*::test';
// const execute = (threshold: number[]) => // const execute = (threshold: number[]) =>
// executor({ // executor({
// services, // services,

View file

@ -36,7 +36,7 @@ export const createMetricThresholdExecutor = (libs: InfraBackendLibs, alertId: s
// Because each alert result has the same group definitions, just grab the groups from the first one. // Because each alert result has the same group definitions, just grab the groups from the first one.
const groups = Object.keys(first(alertResults)); const groups = Object.keys(first(alertResults));
for (const group of groups) { for (const group of groups) {
const alertInstance = services.alertInstanceFactory(`${alertId}-${group}`); const alertInstance = services.alertInstanceFactory(`${group}::${alertId}`);
// AND logic; all criteria must be across the threshold // AND logic; all criteria must be across the threshold
const shouldAlertFire = alertResults.every((result) => const shouldAlertFire = alertResults.every((result) =>