[APM] Latency threshold incorrect value (#107963)
* fixing threshold * removing console * adding unit test Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
77d7d1730b
commit
96ddfe6f7e
2 changed files with 72 additions and 4 deletions
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { registerTransactionDurationAlertType } from './register_transaction_duration_alert_type';
|
||||
import { createRuleTypeMocks } from './test_utils';
|
||||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
|
||||
import { elasticsearchClientMock } from 'src/core/server/elasticsearch/client/mocks';
|
||||
|
||||
describe('registerTransactionDurationAlertType', () => {
|
||||
it('sends alert when value is greater than threashold', async () => {
|
||||
const {
|
||||
services,
|
||||
dependencies,
|
||||
executor,
|
||||
scheduleActions,
|
||||
} = createRuleTypeMocks();
|
||||
|
||||
registerTransactionDurationAlertType(dependencies);
|
||||
|
||||
services.scopedClusterClient.asCurrentUser.search.mockReturnValue(
|
||||
elasticsearchClientMock.createSuccessTransportRequestPromise({
|
||||
hits: {
|
||||
hits: [],
|
||||
total: {
|
||||
relation: 'eq',
|
||||
value: 2,
|
||||
},
|
||||
},
|
||||
aggregations: {
|
||||
latency: {
|
||||
value: 5500000,
|
||||
},
|
||||
},
|
||||
took: 0,
|
||||
timed_out: false,
|
||||
_shards: {
|
||||
failed: 0,
|
||||
skipped: 0,
|
||||
successful: 1,
|
||||
total: 1,
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
const params = {
|
||||
threshold: 3000,
|
||||
windowSize: 5,
|
||||
windowUnit: 'm',
|
||||
transactionType: 'request',
|
||||
serviceName: 'opbeans-java',
|
||||
};
|
||||
await executor({ params });
|
||||
expect(scheduleActions).toHaveBeenCalledTimes(1);
|
||||
expect(scheduleActions).toHaveBeenCalledWith('threshold_met', {
|
||||
transactionType: 'request',
|
||||
serviceName: 'opbeans-java',
|
||||
environment: 'Not defined',
|
||||
threshold: 3000,
|
||||
triggerValue: '5,500 ms',
|
||||
interval: `5m`,
|
||||
});
|
||||
});
|
||||
});
|
|
@ -149,9 +149,10 @@ export function registerTransactionDurationAlertType({
|
|||
const transactionDuration =
|
||||
'values' in latency ? Object.values(latency.values)[0] : latency?.value;
|
||||
|
||||
const threshold = alertParams.threshold * 1000;
|
||||
// Converts threshold to microseconds because this is the unit used on transactionDuration
|
||||
const thresholdMicroseconds = alertParams.threshold * 1000;
|
||||
|
||||
if (transactionDuration && transactionDuration > threshold) {
|
||||
if (transactionDuration && transactionDuration > thresholdMicroseconds) {
|
||||
const durationFormatter = getDurationFormatter(transactionDuration);
|
||||
const transactionDurationFormatted = durationFormatter(
|
||||
transactionDuration
|
||||
|
@ -168,14 +169,14 @@ export function registerTransactionDurationAlertType({
|
|||
[TRANSACTION_TYPE]: alertParams.transactionType,
|
||||
[PROCESSOR_EVENT]: ProcessorEvent.transaction,
|
||||
[ALERT_EVALUATION_VALUE]: transactionDuration,
|
||||
[ALERT_EVALUATION_THRESHOLD]: alertParams.threshold * 1000,
|
||||
[ALERT_EVALUATION_THRESHOLD]: alertParams.threshold,
|
||||
},
|
||||
})
|
||||
.scheduleActions(alertTypeConfig.defaultActionGroupId, {
|
||||
transactionType: alertParams.transactionType,
|
||||
serviceName: alertParams.serviceName,
|
||||
environment: getEnvironmentLabel(alertParams.environment),
|
||||
threshold,
|
||||
threshold: alertParams.threshold,
|
||||
triggerValue: transactionDurationFormatted,
|
||||
interval: `${alertParams.windowSize}${alertParams.windowUnit}`,
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue