Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Onboard Latency Threshold rule type with FAAD #179080

Merged
merged 4 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export enum AggregationType {

export const THRESHOLD_MET_GROUP_ID = 'threshold_met';
export type ThresholdMetActionGroupId = typeof THRESHOLD_MET_GROUP_ID;
const THRESHOLD_MET_GROUP: ActionGroup<ThresholdMetActionGroupId> = {
export const THRESHOLD_MET_GROUP: ActionGroup<ThresholdMetActionGroupId> = {
id: THRESHOLD_MET_GROUP_ID,
name: i18n.translate('xpack.apm.a.thresholdMet', {
defaultMessage: 'Threshold met',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const ApmRuleTypeAlertDefinition: IRuleTypeAlerts = {
context: APM_RULE_TYPE_ALERT_CONTEXT,
mappings: { fieldMap: apmRuleTypeAlertFieldMap },
useLegacyAlerts: true,
shouldWrite: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

What does shouldWrite mean?

Copy link
Contributor Author

@doakalexi doakalexi Mar 22, 2024

Choose a reason for hiding this comment

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

We added this flag to prevent rules that were registered with both the rule registry and the alerting framework from having both write alerting docs. It will be removed once we move all rules away from the rule registry

Copy link
Contributor

Choose a reason for hiding this comment

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

We should set this to true here and remove the override in x-pack/plugins/observability_solution/apm/server/routes/alerts/rule_types/transaction_duration/register_transaction_duration_rule_type.ts

Copy link
Contributor Author

@doakalexi doakalexi Mar 22, 2024

Choose a reason for hiding this comment

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

I think we need this until all the APM rules have been onboarded. On the last rule I will make sure to do this. Thanks!

};

export interface RegisterRuleDependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import { createRuleTypeMocks } from '../../test_utils';

describe('registerTransactionDurationRuleType', () => {
it('sends alert when value is greater than threshold', async () => {
const { services, dependencies, executor, scheduleActions } =
createRuleTypeMocks();
const { services, dependencies, executor } = createRuleTypeMocks();

registerTransactionDurationRuleType(dependencies);

Expand Down Expand Up @@ -44,6 +43,7 @@ describe('registerTransactionDurationRuleType', () => {
total: 1,
},
});
services.alertsClient.report.mockReturnValue({ uuid: 'test-uuid' });

const params = {
threshold: 3000,
Expand All @@ -55,28 +55,41 @@ describe('registerTransactionDurationRuleType', () => {
transactionName: 'GET /orders',
};
await executor({ params });
expect(scheduleActions).toHaveBeenCalledTimes(1);
expect(scheduleActions).toHaveBeenCalledWith('threshold_met', {
alertDetailsUrl: expect.stringContaining(
'http://localhost:5601/eyr/app/observability/alerts/'
),
transactionName: 'GET /orders',
environment: 'development',
interval: `5 mins`,
reason:
'Avg. latency is 5.5 s in the last 5 mins for service: opbeans-java, env: development, type: request. Alert when > 3.0 s.',
transactionType: 'request',
serviceName: 'opbeans-java',
threshold: 3000,
triggerValue: '5,500 ms',
viewInAppUrl:
'http://localhost:5601/eyr/app/apm/services/opbeans-java?transactionType=request&environment=development',
expect(services.alertsClient.setAlertData).toHaveBeenCalledTimes(1);
expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({
context: {
alertDetailsUrl: expect.stringContaining(
'http://localhost:5601/eyr/app/observability/alerts/'
),
environment: 'development',
interval: '5 mins',
reason:
'Avg. latency is 5.5 s in the last 5 mins for service: opbeans-java, env: development, type: request. Alert when > 3.0 s.',
serviceName: 'opbeans-java',
threshold: 3000,
transactionName: 'GET /orders',
transactionType: 'request',
triggerValue: '5,500 ms',
viewInAppUrl:
'http://localhost:5601/eyr/app/apm/services/opbeans-java?transactionType=request&environment=development',
},
id: 'opbeans-java_development_request',
payload: {
'kibana.alert.evaluation.threshold': 3000000,
'kibana.alert.evaluation.value': 5500000,
'kibana.alert.reason':
'Avg. latency is 5.5 s in the last 5 mins for service: opbeans-java, env: development, type: request. Alert when > 3.0 s.',
'processor.event': 'transaction',
'service.environment': 'development',
'service.name': 'opbeans-java',
'transaction.name': 'GET /orders',
'transaction.type': 'request',
},
});
});

it('sends alert when rule is configured with group by on transaction.name', async () => {
const { services, dependencies, executor, scheduleActions } =
createRuleTypeMocks();
const { services, dependencies, executor } = createRuleTypeMocks();

registerTransactionDurationRuleType(dependencies);

Expand Down Expand Up @@ -109,6 +122,7 @@ describe('registerTransactionDurationRuleType', () => {
total: 1,
},
});
services.alertsClient.report.mockReturnValue({ uuid: 'test-uuid' });

const params = {
threshold: 3000,
Expand All @@ -125,28 +139,41 @@ describe('registerTransactionDurationRuleType', () => {
],
};
await executor({ params });
expect(scheduleActions).toHaveBeenCalledTimes(1);
expect(scheduleActions).toHaveBeenCalledWith('threshold_met', {
alertDetailsUrl: expect.stringContaining(
'http://localhost:5601/eyr/app/observability/alerts/'
),
environment: 'development',
interval: `5 mins`,
reason:
'Avg. latency is 5.5 s in the last 5 mins for service: opbeans-java, env: development, type: request, name: GET /products. Alert when > 3.0 s.',
transactionType: 'request',
serviceName: 'opbeans-java',
threshold: 3000,
triggerValue: '5,500 ms',
viewInAppUrl:
'http://localhost:5601/eyr/app/apm/services/opbeans-java?transactionType=request&environment=development',
transactionName: 'GET /products',
expect(services.alertsClient.setAlertData).toHaveBeenCalledTimes(1);
expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({
context: {
alertDetailsUrl: expect.stringContaining(
'http://localhost:5601/eyr/app/observability/alerts/'
),
environment: 'development',
interval: '5 mins',
reason:
'Avg. latency is 5.5 s in the last 5 mins for service: opbeans-java, env: development, type: request, name: GET /products. Alert when > 3.0 s.',
serviceName: 'opbeans-java',
threshold: 3000,
transactionName: 'GET /products',
transactionType: 'request',
triggerValue: '5,500 ms',
viewInAppUrl:
'http://localhost:5601/eyr/app/apm/services/opbeans-java?transactionType=request&environment=development',
},
id: 'opbeans-java_development_request_GET /products',
payload: {
'kibana.alert.evaluation.threshold': 3000000,
'kibana.alert.evaluation.value': 5500000,
'kibana.alert.reason':
'Avg. latency is 5.5 s in the last 5 mins for service: opbeans-java, env: development, type: request, name: GET /products. Alert when > 3.0 s.',
'processor.event': 'transaction',
'service.environment': 'development',
'service.name': 'opbeans-java',
'transaction.name': 'GET /products',
'transaction.type': 'request',
},
});
});

it('sends alert when rule is configured with preselected group by', async () => {
const { services, dependencies, executor, scheduleActions } =
createRuleTypeMocks();
const { services, dependencies, executor } = createRuleTypeMocks();

registerTransactionDurationRuleType(dependencies);

Expand Down Expand Up @@ -179,6 +206,7 @@ describe('registerTransactionDurationRuleType', () => {
total: 1,
},
});
services.alertsClient.report.mockReturnValue({ uuid: 'test-uuid' });

const params = {
threshold: 3000,
Expand All @@ -191,27 +219,41 @@ describe('registerTransactionDurationRuleType', () => {
};

await executor({ params });
expect(scheduleActions).toHaveBeenCalledTimes(1);
expect(scheduleActions).toHaveBeenCalledWith('threshold_met', {
alertDetailsUrl: expect.stringContaining(
'http://localhost:5601/eyr/app/observability/alerts/'
),
environment: 'development',
interval: `5 mins`,
reason:
'Avg. latency is 5.5 s in the last 5 mins for service: opbeans-java, env: development, type: request. Alert when > 3.0 s.',
transactionType: 'request',
serviceName: 'opbeans-java',
threshold: 3000,
triggerValue: '5,500 ms',
viewInAppUrl:
'http://localhost:5601/eyr/app/apm/services/opbeans-java?transactionType=request&environment=development',
expect(services.alertsClient.setAlertData).toHaveBeenCalledTimes(1);
expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({
context: {
alertDetailsUrl: expect.stringContaining(
'http://localhost:5601/eyr/app/observability/alerts/'
),
environment: 'development',
interval: '5 mins',
reason:
'Avg. latency is 5.5 s in the last 5 mins for service: opbeans-java, env: development, type: request. Alert when > 3.0 s.',
serviceName: 'opbeans-java',
threshold: 3000,
transactionName: undefined,
transactionType: 'request',
triggerValue: '5,500 ms',
viewInAppUrl:
'http://localhost:5601/eyr/app/apm/services/opbeans-java?transactionType=request&environment=development',
},
id: 'opbeans-java_development_request',
payload: {
'kibana.alert.evaluation.threshold': 3000000,
'kibana.alert.evaluation.value': 5500000,
'kibana.alert.reason':
'Avg. latency is 5.5 s in the last 5 mins for service: opbeans-java, env: development, type: request. Alert when > 3.0 s.',
'processor.event': 'transaction',
'service.environment': 'development',
'service.name': 'opbeans-java',
'transaction.name': undefined,
'transaction.type': 'request',
},
});
});

it('sends alert when service.environment field does not exist in the source', async () => {
const { services, dependencies, executor, scheduleActions } =
createRuleTypeMocks();
const { services, dependencies, executor } = createRuleTypeMocks();

registerTransactionDurationRuleType(dependencies);

Expand Down Expand Up @@ -249,6 +291,7 @@ describe('registerTransactionDurationRuleType', () => {
total: 1,
},
});
services.alertsClient.report.mockReturnValue({ uuid: 'test-uuid' });

const params = {
threshold: 3000,
Expand All @@ -265,28 +308,41 @@ describe('registerTransactionDurationRuleType', () => {
],
};
await executor({ params });
expect(scheduleActions).toHaveBeenCalledTimes(1);
expect(scheduleActions).toHaveBeenCalledWith('threshold_met', {
alertDetailsUrl: expect.stringContaining(
'http://localhost:5601/eyr/app/observability/alerts/'
),
environment: 'Not defined',
interval: `5 mins`,
reason:
'Avg. latency is 5.5 s in the last 5 mins for service: opbeans-java, env: Not defined, type: request, name: tx-java. Alert when > 3.0 s.',
transactionType: 'request',
serviceName: 'opbeans-java',
threshold: 3000,
triggerValue: '5,500 ms',
viewInAppUrl:
'http://localhost:5601/eyr/app/apm/services/opbeans-java?transactionType=request&environment=ENVIRONMENT_ALL',
transactionName: 'tx-java',
expect(services.alertsClient.setAlertData).toHaveBeenCalledTimes(1);
expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({
context: {
alertDetailsUrl: expect.stringContaining(
'http://localhost:5601/eyr/app/observability/alerts/'
),
environment: 'Not defined',
interval: '5 mins',
reason:
'Avg. latency is 5.5 s in the last 5 mins for service: opbeans-java, env: Not defined, type: request, name: tx-java. Alert when > 3.0 s.',
serviceName: 'opbeans-java',
threshold: 3000,
transactionName: 'tx-java',
transactionType: 'request',
triggerValue: '5,500 ms',
viewInAppUrl:
'http://localhost:5601/eyr/app/apm/services/opbeans-java?transactionType=request&environment=ENVIRONMENT_ALL',
},
id: 'opbeans-java_ENVIRONMENT_NOT_DEFINED_request_tx-java',
payload: {
'kibana.alert.evaluation.threshold': 3000000,
'kibana.alert.evaluation.value': 5500000,
'kibana.alert.reason':
'Avg. latency is 5.5 s in the last 5 mins for service: opbeans-java, env: Not defined, type: request, name: tx-java. Alert when > 3.0 s.',
'processor.event': 'transaction',
'service.environment': 'ENVIRONMENT_NOT_DEFINED',
'service.name': 'opbeans-java',
'transaction.name': 'tx-java',
'transaction.type': 'request',
},
});
});

it('sends alert when rule is configured with a filter query', async () => {
const { services, dependencies, executor, scheduleActions } =
createRuleTypeMocks();
const { services, dependencies, executor } = createRuleTypeMocks();

registerTransactionDurationRuleType(dependencies);

Expand Down Expand Up @@ -319,6 +375,7 @@ describe('registerTransactionDurationRuleType', () => {
total: 1,
},
});
services.alertsClient.report.mockReturnValue({ uuid: 'test-uuid' });

const params = {
threshold: 3000,
Expand All @@ -337,21 +394,36 @@ describe('registerTransactionDurationRuleType', () => {
};

await executor({ params });
expect(scheduleActions).toHaveBeenCalledTimes(1);
expect(scheduleActions).toHaveBeenCalledWith('threshold_met', {
alertDetailsUrl: expect.stringContaining(
'http://localhost:5601/eyr/app/observability/alerts/'
),
environment: 'development',
interval: `5 mins`,
reason:
'Avg. latency is 5.5 s in the last 5 mins for service: opbeans-java, env: development, type: request. Alert when > 3.0 s.',
transactionType: 'request',
serviceName: 'opbeans-java',
threshold: 3000,
triggerValue: '5,500 ms',
viewInAppUrl:
'http://localhost:5601/eyr/app/apm/services/opbeans-java?transactionType=request&environment=development',
expect(services.alertsClient.setAlertData).toHaveBeenCalledTimes(1);
expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({
context: {
alertDetailsUrl: expect.stringContaining(
'http://localhost:5601/eyr/app/observability/alerts/'
),
environment: 'development',
interval: '5 mins',
reason:
'Avg. latency is 5.5 s in the last 5 mins for service: opbeans-java, env: development, type: request. Alert when > 3.0 s.',
serviceName: 'opbeans-java',
threshold: 3000,
transactionName: undefined,
transactionType: 'request',
triggerValue: '5,500 ms',
viewInAppUrl:
'http://localhost:5601/eyr/app/apm/services/opbeans-java?transactionType=request&environment=development',
},
id: 'opbeans-java_development_request',
payload: {
'kibana.alert.evaluation.threshold': 3000000,
'kibana.alert.evaluation.value': 5500000,
'kibana.alert.reason':
'Avg. latency is 5.5 s in the last 5 mins for service: opbeans-java, env: development, type: request. Alert when > 3.0 s.',
'processor.event': 'transaction',
'service.environment': 'development',
'service.name': 'opbeans-java',
'transaction.name': undefined,
'transaction.type': 'request',
},
});
});
});
Loading