Skip to content

Commit

Permalink
[Metrics UI] Make alert instance IDs more useful (#70100)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
Zacqary and elasticmachine authored Jun 30, 2020
1 parent bb7bc78 commit 0f78bc9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const createInventoryMetricThresholdExecutor = (

const inventoryItems = Object.keys(first(results));
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
const shouldAlertFire = results.every((result) => result[item].shouldFire);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let persistAlertInstances = false; // eslint-disable-line

describe('The metric threshold alert type', () => {
describe('querying the entire infrastructure', () => {
const instanceID = 'test-*';
const instanceID = '*::test';
const execute = (comparator: Comparator, threshold: number[], sourceId: string = 'default') =>
executor({
services,
Expand Down Expand Up @@ -118,8 +118,8 @@ describe('The metric threshold alert type', () => {
],
},
});
const instanceIdA = 'test-a';
const instanceIdB = 'test-b';
const instanceIdA = 'a::test';
const instanceIdB = 'b::test';
test('sends an alert when all groups pass the threshold', async () => {
await execute(Comparator.GT, [0.75]);
expect(mostRecentAction(instanceIdA).id).toBe(FIRED_ACTIONS.id);
Expand Down Expand Up @@ -175,28 +175,28 @@ describe('The metric threshold alert type', () => {
},
});
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]);
expect(mostRecentAction(instanceID).id).toBe(FIRED_ACTIONS.id);
expect(getState(instanceID).alertState).toBe(AlertStates.ALERT);
});
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]);
expect(mostRecentAction(instanceID)).toBe(undefined);
expect(getState(instanceID).alertState).toBe(AlertStates.OK);
});
test('alerts only on groups that meet all criteria when querying with a groupBy parameter', async () => {
const instanceIdA = 'test-a';
const instanceIdB = 'test-b';
const instanceIdA = 'a::test';
const instanceIdB = 'b::test';
await execute(Comparator.GT_OR_EQ, [1.0], [3.0], 'something');
expect(mostRecentAction(instanceIdA).id).toBe(FIRED_ACTIONS.id);
expect(getState(instanceIdA).alertState).toBe(AlertStates.ALERT);
expect(mostRecentAction(instanceIdB)).toBe(undefined);
expect(getState(instanceIdB).alertState).toBe(AlertStates.OK);
});
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]);
const { action } = mostRecentAction(instanceID);
const reasons = action.reason.split('\n');
Expand All @@ -210,7 +210,7 @@ describe('The metric threshold alert type', () => {
});
});
describe('querying with the count aggregator', () => {
const instanceID = 'test-*';
const instanceID = '*::test';
const execute = (comparator: Comparator, threshold: number[]) =>
executor({
services,
Expand All @@ -236,7 +236,7 @@ describe('The metric threshold alert type', () => {
});
});
describe('querying with the p99 aggregator', () => {
const instanceID = 'test-*';
const instanceID = '*::test';
const execute = (comparator: Comparator, threshold: number[]) =>
executor({
services,
Expand All @@ -262,7 +262,7 @@ describe('The metric threshold alert type', () => {
});
});
describe('querying with the p95 aggregator', () => {
const instanceID = 'test-*';
const instanceID = '*::test';
const execute = (comparator: Comparator, threshold: number[]) =>
executor({
services,
Expand All @@ -288,7 +288,7 @@ describe('The metric threshold alert type', () => {
});
});
describe("querying a metric that hasn't reported data", () => {
const instanceID = 'test-*';
const instanceID = '*::test';
const execute = (alertOnNoData: boolean) =>
executor({
services,
Expand Down Expand Up @@ -317,7 +317,7 @@ describe('The metric threshold alert type', () => {
});

// describe('querying a metric that later recovers', () => {
// const instanceID = 'test-*';
// const instanceID = '*::test';
// const execute = (threshold: number[]) =>
// executor({
// services,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
const groups = Object.keys(first(alertResults));
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
const shouldAlertFire = alertResults.every((result) =>
Expand Down

0 comments on commit 0f78bc9

Please sign in to comment.