Skip to content

Commit

Permalink
addressing pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Oct 5, 2020
1 parent b5720ec commit 5d0e902
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function registerApmAlerts(
- Service name: \\{\\{context.serviceName\\}\\}
- Environment: \\{\\{context.environment\\}\\}
- Threshold: \\{\\{context.threshold\\}\\} errors
- Triggered value: \\{\\{context.triggerValue\\}\\} errors over the last \\{\\{context.intervalSize\\}\\}\\{\\{context.intervalUnit\\}\\}`,
- Triggered value: \\{\\{context.triggerValue\\}\\} errors over the last \\{\\{context.interval\\}\\}`,
}
),
});
Expand All @@ -58,7 +58,7 @@ export function registerApmAlerts(
- Type: \\{\\{context.transactionType\\}\\}
- Environment: \\{\\{context.environment\\}\\}
- Threshold: \\{\\{context.threshold\\}\\}ms
- Triggered value: \\{\\{context.triggerValue\\}\\} over the last \\{\\{context.intervalSize\\}\\}\\{\\{context.intervalUnit\\}\\}`,
- Triggered value: \\{\\{context.triggerValue\\}\\} over the last \\{\\{context.interval\\}\\}`,
}
),
});
Expand All @@ -85,7 +85,7 @@ export function registerApmAlerts(
- Type: \\{\\{context.transactionType\\}\\}
- Environment: \\{\\{context.environment\\}\\}
- Threshold: \\{\\{context.threshold\\}\\}%
- Triggered value: \\{\\{context.triggerValue\\}\\}% of errors over the last \\{\\{context.intervalSize\\}\\}\\{\\{context.intervalUnit\\}\\}`,
- Triggered value: \\{\\{context.triggerValue\\}\\}% of errors over the last \\{\\{context.interval\\}\\}`,
}
),
});
Expand Down
16 changes: 3 additions & 13 deletions x-pack/plugins/apm/server/lib/alerts/action_variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,14 @@ export const apmActionVariables = {
),
name: 'triggerValue',
},
windowSize: {
interval: {
description: i18n.translate(
'xpack.apm.alerts.action_variables.intervalSize',
{
defaultMessage:
'The interval size the alert will use to check for any incident',
'The length and unit of the time period where the alert conditions were met',
}
),
name: 'intervalSize',
},
windowUnit: {
description: i18n.translate(
'xpack.apm.alerts.action_variables.intervalUnit',
{
defaultMessage:
'The interval unit the alert will use to check for any incident',
}
),
name: 'intervalUnit',
name: 'interval',
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -117,32 +117,28 @@ describe('Error count alert', () => {
environment: 'env-foo',
threshold: 1,
triggerValue: 2,
intervalSize: 5,
intervalUnit: 'm',
interval: '5m',
});
expect(scheduleActions).toHaveBeenCalledWith('threshold_met', {
serviceName: 'foo',
environment: 'env-foo-2',
threshold: 1,
triggerValue: 2,
intervalSize: 5,
intervalUnit: 'm',
interval: '5m',
});
expect(scheduleActions).toHaveBeenCalledWith('threshold_met', {
serviceName: 'bar',
environment: 'env-bar',
threshold: 1,
triggerValue: 2,
intervalSize: 5,
intervalUnit: 'm',
interval: '5m',
});
expect(scheduleActions).toHaveBeenCalledWith('threshold_met', {
serviceName: 'bar',
environment: 'env-bar-2',
threshold: 1,
triggerValue: 2,
intervalSize: 5,
intervalUnit: 'm',
interval: '5m',
});
});
it('sends alerts with service name', async () => {
Expand Down Expand Up @@ -194,16 +190,14 @@ describe('Error count alert', () => {
environment: undefined,
threshold: 1,
triggerValue: 2,
intervalSize: 5,
intervalUnit: 'm',
interval: '5m',
});
expect(scheduleActions).toHaveBeenCalledWith('threshold_met', {
serviceName: 'bar',
environment: undefined,
threshold: 1,
triggerValue: 2,
intervalSize: 5,
intervalUnit: 'm',
interval: '5m',
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ export function registerErrorCountAlertType({
apmActionVariables.environment,
apmActionVariables.threshold,
apmActionVariables.triggerValue,
apmActionVariables.windowSize,
apmActionVariables.windowUnit,
apmActionVariables.interval,
],
},
producer: 'apm',
Expand Down Expand Up @@ -140,8 +139,7 @@ export function registerErrorCountAlertType({
environment,
threshold: alertParams.threshold,
triggerValue: errorCount,
intervalSize: alertParams.windowSize,
intervalUnit: alertParams.windowUnit,
interval: `${alertParams.windowSize}${alertParams.windowUnit}`,
});
}
response.aggregations?.services.buckets.forEach((serviceBucket) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ export function registerTransactionDurationAlertType({
apmActionVariables.environment,
apmActionVariables.threshold,
apmActionVariables.triggerValue,
apmActionVariables.windowSize,
apmActionVariables.windowUnit,
apmActionVariables.interval,
],
},
producer: 'apm',
Expand Down Expand Up @@ -153,8 +152,7 @@ export function registerTransactionDurationAlertType({
environment,
threshold,
triggerValue: transactionDurationFormatted,
intervalSize: alertParams.windowSize,
intervalUnit: alertParams.windowUnit,
interval: `${alertParams.windowSize}${alertParams.windowUnit}`,
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,35 +133,31 @@ describe('Transaction error rate alert', () => {
environment: 'env-foo',
threshold: 10,
triggerValue: '50',
intervalSize: 5,
intervalUnit: 'm',
interval: '5m',
});
expect(scheduleActions).toHaveBeenCalledWith('threshold_met', {
serviceName: 'foo',
transactionType: 'type-foo',
environment: 'env-foo-2',
threshold: 10,
triggerValue: '50',
intervalSize: 5,
intervalUnit: 'm',
interval: '5m',
});
expect(scheduleActions).toHaveBeenCalledWith('threshold_met', {
serviceName: 'bar',
transactionType: 'type-bar',
environment: 'env-bar',
threshold: 10,
triggerValue: '50',
intervalSize: 5,
intervalUnit: 'm',
interval: '5m',
});
expect(scheduleActions).toHaveBeenCalledWith('threshold_met', {
serviceName: 'bar',
transactionType: 'type-bar',
environment: 'env-bar-2',
threshold: 10,
triggerValue: '50',
intervalSize: 5,
intervalUnit: 'm',
interval: '5m',
});
});
it('sends alerts with service name and transaction type', async () => {
Expand Down Expand Up @@ -226,17 +222,15 @@ describe('Transaction error rate alert', () => {
environment: undefined,
threshold: 10,
triggerValue: '50',
intervalSize: 5,
intervalUnit: 'm',
interval: '5m',
});
expect(scheduleActions).toHaveBeenCalledWith('threshold_met', {
serviceName: 'bar',
transactionType: 'type-bar',
environment: undefined,
threshold: 10,
triggerValue: '50',
intervalSize: 5,
intervalUnit: 'm',
interval: '5m',
});
});

Expand Down Expand Up @@ -289,17 +283,15 @@ describe('Transaction error rate alert', () => {
environment: undefined,
threshold: 10,
triggerValue: '50',
intervalSize: 5,
intervalUnit: 'm',
interval: '5m',
});
expect(scheduleActions).toHaveBeenCalledWith('threshold_met', {
serviceName: 'bar',
transactionType: undefined,
environment: undefined,
threshold: 10,
triggerValue: '50',
intervalSize: 5,
intervalUnit: 'm',
interval: '5m',
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ export function registerTransactionErrorRateAlertType({
apmActionVariables.environment,
apmActionVariables.threshold,
apmActionVariables.triggerValue,
apmActionVariables.windowSize,
apmActionVariables.windowUnit,
apmActionVariables.interval,
],
},
producer: 'apm',
Expand Down Expand Up @@ -175,8 +174,7 @@ export function registerTransactionErrorRateAlertType({
triggerValue: String(
parseFloat(transactionErrorRate.toPrecision(3))
),
intervalSize: alertParams.windowSize,
intervalUnit: alertParams.windowUnit,
interval: `${alertParams.windowSize}${alertParams.windowUnit}`,
});
}

Expand Down

0 comments on commit 5d0e902

Please sign in to comment.