Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions x-pack/plugins/alerting/common/alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export interface AlertAggregations {
alertExecutionStatus: { [status: string]: number };
ruleEnabledStatus: { enabled: number; disabled: number };
ruleMutedStatus: { muted: number; unmuted: number };
ruleSnoozedStatus: { snoozed: number };
}

export interface MappedParamsProperties {
Expand Down
9 changes: 9 additions & 0 deletions x-pack/plugins/alerting/server/routes/aggregate_rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ describe('aggregateRulesRoute', () => {
muted: 2,
unmuted: 39,
},
ruleSnoozedStatus: {
snoozed: 4,
},
};
rulesClient.aggregate.mockResolvedValueOnce(aggregateResult);

Expand Down Expand Up @@ -88,6 +91,9 @@ describe('aggregateRulesRoute', () => {
"muted": 2,
"unmuted": 39,
},
"rule_snoozed_status": Object {
"snoozed": 4,
},
},
}
`);
Expand Down Expand Up @@ -120,6 +126,9 @@ describe('aggregateRulesRoute', () => {
muted: 2,
unmuted: 39,
},
rule_snoozed_status: {
snoozed: 4,
},
},
});
});
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/alerting/server/routes/aggregate_rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ const rewriteBodyRes: RewriteResponseCase<AggregateResult> = ({
alertExecutionStatus,
ruleEnabledStatus,
ruleMutedStatus,
ruleSnoozedStatus,
...rest
}) => ({
...rest,
rule_execution_status: alertExecutionStatus,
rule_enabled_status: ruleEnabledStatus,
rule_muted_status: ruleMutedStatus,
rule_snoozed_status: ruleSnoozedStatus,
});

export const aggregateRulesRoute = (
Expand Down
22 changes: 22 additions & 0 deletions x-pack/plugins/alerting/server/rules_client/rules_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ export interface RuleAggregation {
doc_count: number;
}>;
};
snoozed: {
buckets: Array<{
key: number;
key_as_string: string;
doc_count: number;
}>;
};
}

export interface ConstructorOptions {
Expand Down Expand Up @@ -191,6 +198,7 @@ export interface AggregateResult {
alertExecutionStatus: { [status: string]: number };
ruleEnabledStatus?: { enabled: number; disabled: number };
ruleMutedStatus?: { muted: number; unmuted: number };
ruleSnoozedStatus?: { snoozed: number };
}

export interface FindResult<Params extends RuleTypeParams> {
Expand Down Expand Up @@ -858,6 +866,7 @@ export class RulesClient {
);
throw error;
}

const { filter: authorizationFilter } = authorizationTuple;
const resp = await this.unsecuredSavedObjectsClient.find<RawRule, RuleAggregation>({
...options,
Expand All @@ -878,6 +887,13 @@ export class RulesClient {
muted: {
terms: { field: 'alert.attributes.muteAll' },
},
snoozed: {
date_range: {
field: 'alert.attributes.snoozeEndTime',
format: 'strict_date_time',
Comment thread
chrisronline marked this conversation as resolved.
ranges: [{ from: 'now' }],
},
},
},
});

Expand All @@ -893,6 +909,7 @@ export class RulesClient {
muted: 0,
unmuted: 0,
},
ruleSnoozedStatus: { snoozed: 0 },
};

for (const key of RuleExecutionStatusValues) {
Expand Down Expand Up @@ -934,6 +951,11 @@ export class RulesClient {
unmuted: mutedBuckets.find((bucket) => bucket.key === 0)?.doc_count ?? 0,
};

const snoozedBuckets = resp.aggregations.snoozed.buckets;
ret.ruleSnoozedStatus = {
snoozed: snoozedBuckets.reduce((acc, bucket) => acc + bucket.doc_count, 0),
};

return ret;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ describe('aggregate()', () => {
{ key: 1, key_as_string: '1', doc_count: 3 },
],
},
snoozed: {
buckets: [
{
key: '2022-03-21T20:22:01.501Z-*',
format: 'strict_date_time',
from: 1.647894121501e12,
from_as_string: '2022-03-21T20:22:01.501Z',
doc_count: 2,
},
],
},
},
});

Expand Down Expand Up @@ -146,6 +157,9 @@ describe('aggregate()', () => {
"muted": 3,
"unmuted": 27,
},
"ruleSnoozedStatus": Object {
"snoozed": 2,
},
}
`);
expect(unsecuredSavedObjectsClient.find).toHaveBeenCalledTimes(1);
Expand All @@ -166,6 +180,13 @@ describe('aggregate()', () => {
muted: {
terms: { field: 'alert.attributes.muteAll' },
},
snoozed: {
date_range: {
field: 'alert.attributes.snoozeEndTime',
format: 'strict_date_time',
ranges: [{ from: 'now' }],
},
},
},
},
]);
Expand Down Expand Up @@ -193,6 +214,13 @@ describe('aggregate()', () => {
muted: {
terms: { field: 'alert.attributes.muteAll' },
},
snoozed: {
date_range: {
field: 'alert.attributes.snoozeEndTime',
format: 'strict_date_time',
ranges: [{ from: 'now' }],
},
},
},
},
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ interface RuleStatsState {
disabled: number;
muted: number;
error: number;
snoozed: number;
}

export interface TopAlert {
Expand Down Expand Up @@ -90,6 +91,7 @@ function AlertsPage() {
disabled: 0,
muted: 0,
error: 0,
snoozed: 0,
});

useEffect(() => {
Expand All @@ -111,18 +113,21 @@ function AlertsPage() {
const response = await loadRuleAggregations({
http,
});
const { ruleExecutionStatus, ruleMutedStatus, ruleEnabledStatus } = response;
if (ruleExecutionStatus && ruleMutedStatus && ruleEnabledStatus) {
const { ruleExecutionStatus, ruleMutedStatus, ruleEnabledStatus, ruleSnoozedStatus } =
response;
if (ruleExecutionStatus && ruleMutedStatus && ruleEnabledStatus && ruleSnoozedStatus) {
const total = Object.values(ruleExecutionStatus).reduce((acc, value) => acc + value, 0);
const { disabled } = ruleEnabledStatus;
const { muted } = ruleMutedStatus;
const { error } = ruleExecutionStatus;
const { snoozed } = ruleSnoozedStatus;
setRuleStats({
...ruleStats,
total,
disabled,
muted,
error,
snoozed,
});
}
setRuleStatsLoading(false);
Expand Down Expand Up @@ -263,9 +268,9 @@ function AlertsPage() {
data-test-subj="statDisabled"
/>,
<EuiStat
title={ruleStats.muted}
title={ruleStats.muted + ruleStats.snoozed}
Copy link
Copy Markdown
Contributor

@mgiota mgiota Mar 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@XavierM I would like to see this PR merged #128108 where we implemented the snoozed status (and update the muteAll field) and do a bit of manual testing to see if these numbers work well.

I am just writing the scenarios I would like to test once both PRs are merged:
Scenario 1

  • User in Stack Management selects snooze for a specified timerange for one rule. (The muteAll field I guess will be false in this case, right?)
  • In o11y rules page status for this rule will appear as enabled and not snoozed permanently
  • In Alerts page there will be 1 Snoozed alert

Scenario 2

  • User in Stack Management selects snooze for a specified timerange for one rule.
  • In o11y rules page status for this rule will appear as enabled
  • In o11y rules page user selects Snoozed permanently for another rule
  • In Alerts page there will be 2 Snoozed alerts (the one from stack Management ruleStats.snoozed and the other from o11y rules page ruleStats.muted)

description={i18n.translate('xpack.observability.alerts.ruleStats.muted', {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@XavierM Shall we make it explicit in the name that it contains muted and snoozed xpack.observability.alerts.ruleStats.mutedAndSnoozed?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind keeping it as it is either.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's keep it like that for now because this is going to change again in the next release meaning muted will become deprecated sooner than later.

defaultMessage: 'Muted',
defaultMessage: 'Snoozed',
})}
color="primary"
titleSize="xs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export default function createAggregateTests({ getService }: FtrProviderContext)
const response = await supertest.get(
`${getUrlPrefix(Spaces.space1.id)}/internal/alerting/rules/_aggregate`
);

expect(response.status).to.eql(200);
expect(response.body).to.eql({
rule_enabled_status: {
Expand All @@ -42,6 +41,9 @@ export default function createAggregateTests({ getService }: FtrProviderContext)
muted: 0,
unmuted: 0,
},
rule_snoozed_status: {
snoozed: 0,
},
});
});

Expand Down Expand Up @@ -96,12 +98,11 @@ export default function createAggregateTests({ getService }: FtrProviderContext)
// calls are successful, the call to aggregate may return stale totals if called
// too early.
await delay(1000);
const reponse = await supertest.get(
const response = await supertest.get(
Comment thread
chrisronline marked this conversation as resolved.
`${getUrlPrefix(Spaces.space1.id)}/internal/alerting/rules/_aggregate`
);

expect(reponse.status).to.eql(200);
expect(reponse.body).to.eql({
expect(response.status).to.eql(200);
expect(response.body).to.eql({
rule_enabled_status: {
disabled: 0,
enabled: 7,
Expand All @@ -118,6 +119,9 @@ export default function createAggregateTests({ getService }: FtrProviderContext)
muted: 0,
unmuted: 7,
},
rule_snoozed_status: {
snoozed: 0,
},
});
});

Expand Down Expand Up @@ -195,6 +199,9 @@ export default function createAggregateTests({ getService }: FtrProviderContext)
muted: 0,
unmuted: 7,
},
ruleSnoozedStatus: {
snoozed: 0,
},
});
});
});
Expand Down