forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[APM] Latency threshold incorrect value (elastic#107963) (elastic#108195
) * fixing threshold * removing console * adding unit test Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Cauê Marcondes <55978943+cauemarcondes@users.noreply.github.com>
- Loading branch information
1 parent
9d82f5b
commit f1f884e
Showing
2 changed files
with
72 additions
and
4 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
x-pack/plugins/apm/server/lib/alerts/register_transaction_duration_alert_type.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters