Skip to content

Commit

Permalink
Onboard APM Anomaly rule type with FAAD (#179196)
Browse files Browse the repository at this point in the history
towards: #169867

This PR onboards APM Anomaly rule type with FAAD.

I am having trouble getting this rule to create an alert. If there is
any easy way to verify pls let me know!
  • Loading branch information
doakalexi authored Apr 2, 2024
1 parent 507f09d commit 961df45
Show file tree
Hide file tree
Showing 2 changed files with 335 additions and 293 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Transaction duration anomaly alert', () => {
services.scopedClusterClient.asCurrentUser.search
).not.toHaveBeenCalled();

expect(services.alertFactory.create).not.toHaveBeenCalled();
expect(services.alertsClient.report).not.toHaveBeenCalled();
});

it('ml jobs are not available', async () => {
Expand Down Expand Up @@ -69,7 +69,7 @@ describe('Transaction duration anomaly alert', () => {
services.scopedClusterClient.asCurrentUser.search
).not.toHaveBeenCalled();

expect(services.alertFactory.create).not.toHaveBeenCalled();
expect(services.alertsClient.report).not.toHaveBeenCalled();
});

it('anomaly is less than threshold', async () => {
Expand Down Expand Up @@ -135,7 +135,7 @@ describe('Transaction duration anomaly alert', () => {
expect(
services.scopedClusterClient.asCurrentUser.search
).not.toHaveBeenCalled();
expect(services.alertFactory.create).not.toHaveBeenCalled();
expect(services.alertsClient.report).not.toHaveBeenCalled();
});
});

Expand All @@ -154,8 +154,9 @@ describe('Transaction duration anomaly alert', () => {
] as unknown as ApmMlJob[])
);

const { services, dependencies, executor, scheduleActions } =
createRuleTypeMocks();
const { services, dependencies, executor } = createRuleTypeMocks();

services.alertsClient.report.mockReturnValue({ uuid: 'test-uuid' });

const ml = {
mlSystemProvider: () => ({
Expand Down Expand Up @@ -221,23 +222,38 @@ describe('Transaction duration anomaly alert', () => {

await executor({ params });

expect(services.alertFactory.create).toHaveBeenCalledTimes(1);
expect(services.alertsClient.report).toHaveBeenCalledTimes(1);

expect(services.alertFactory.create).toHaveBeenCalledWith(
'apm.anomaly_foo_development_type-foo'
);
expect(services.alertsClient.report).toHaveBeenCalledWith({
actionGroup: 'threshold_met',
id: 'apm.anomaly_foo_development_type-foo',
});

expect(scheduleActions).toHaveBeenCalledWith('threshold_met', {
serviceName: 'foo',
transactionType: 'type-foo',
environment: 'development',
threshold: 'minor',
triggerValue: 'critical',
reason:
'critical latency anomaly with a score of 80, was detected in the last 5 mins for foo.',
viewInAppUrl:
'http://localhost:5601/eyr/app/apm/services/foo?transactionType=type-foo&environment=development',
alertDetailsUrl: 'mockedAlertsLocator > getLocation',
expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({
context: {
alertDetailsUrl: 'mockedAlertsLocator > getLocation',
environment: 'development',
reason:
'critical latency anomaly with a score of 80, was detected in the last 5 mins for foo.',
serviceName: 'foo',
threshold: 'minor',
transactionType: 'type-foo',
triggerValue: 'critical',
viewInAppUrl:
'http://localhost:5601/eyr/app/apm/services/foo?transactionType=type-foo&environment=development',
},
id: 'apm.anomaly_foo_development_type-foo',
payload: {
'kibana.alert.evaluation.threshold': 25,
'kibana.alert.evaluation.value': 80,
'kibana.alert.reason':
'critical latency anomaly with a score of 80, was detected in the last 5 mins for foo.',
'kibana.alert.severity': 'critical',
'processor.event': 'transaction',
'service.environment': 'development',
'service.name': 'foo',
'transaction.type': 'type-foo',
},
});
});
});
Expand Down
Loading

0 comments on commit 961df45

Please sign in to comment.