mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[ObsUX] Fix timestamp for anomaly alert test (#169255)
Closes https://github.com/elastic/kibana/issues/160769 ### What was done The anomaly alert test was failing with timeout because was not generating alerts, the data and spikes were added to far away in time, so when the job is created doesn't take into account data that far in the past We fixed the timerange of the data generated and the spikes. BEFORE: <img width="1196" alt="image" src="d14665f3
-28be-437b-b9ca-f5f7d449e5f1"> AFTER: <img width="1196" alt="image" src="683cb592
-173b-4952-b7db-697e3dfb8ebd">
This commit is contained in:
parent
0fd5ff51e5
commit
17c78db794
2 changed files with 19 additions and 23 deletions
|
@ -174,7 +174,6 @@ export function registerAnomalyRuleType({
|
|||
range: {
|
||||
timestamp: {
|
||||
gte: dateStart,
|
||||
format: 'epoch_millis',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import moment from 'moment';
|
||||
import { ApmRuleType } from '@kbn/apm-plugin/common/rules/apm_rule_types';
|
||||
import { apm, timerange } from '@kbn/apm-synthtrace-client';
|
||||
import expect from '@kbn/expect';
|
||||
|
@ -23,34 +24,32 @@ export default function ApiTest({ getService }: FtrProviderContext) {
|
|||
const logger = getService('log');
|
||||
|
||||
const synthtraceEsClient = getService('synthtraceEsClient');
|
||||
// FLAKY https://github.com/elastic/kibana/issues/160298
|
||||
registry.when.skip(
|
||||
registry.when(
|
||||
'fetching service anomalies with a trial license',
|
||||
{ config: 'trial', archives: [] },
|
||||
() => {
|
||||
const start = '2021-01-01T00:00:00.000Z';
|
||||
const end = '2021-01-08T00:15:00.000Z';
|
||||
const start = moment().subtract(1, 'days').valueOf();
|
||||
const end = moment().valueOf();
|
||||
|
||||
const spikeStart = new Date('2021-01-07T23:15:00.000Z').getTime();
|
||||
const spikeEnd = new Date('2021-01-08T00:15:00.000Z').getTime();
|
||||
|
||||
const NORMAL_DURATION = 100;
|
||||
const NORMAL_RATE = 1;
|
||||
const spikeStart = moment().subtract(15, 'minutes').valueOf();
|
||||
const spikeEnd = moment().valueOf();
|
||||
|
||||
let ruleId: string;
|
||||
|
||||
before(async () => {
|
||||
await cleanup();
|
||||
|
||||
const serviceA = apm
|
||||
.service({ name: 'a', environment: 'production', agentName: 'java' })
|
||||
.instance('a');
|
||||
|
||||
const events = timerange(new Date(start).getTime(), new Date(end).getTime())
|
||||
const events = timerange(start, end)
|
||||
.interval('1m')
|
||||
.rate(1)
|
||||
.generator((timestamp) => {
|
||||
const isInSpike = timestamp >= spikeStart && timestamp < spikeEnd;
|
||||
const count = isInSpike ? 4 : NORMAL_RATE;
|
||||
const duration = isInSpike ? 1000 : NORMAL_DURATION;
|
||||
const count = isInSpike ? 4 : 1;
|
||||
const duration = isInSpike ? 1000 : 100;
|
||||
const outcome = isInSpike ? 'failure' : 'success';
|
||||
|
||||
return [
|
||||
|
@ -65,26 +64,25 @@ export default function ApiTest({ getService }: FtrProviderContext) {
|
|||
});
|
||||
|
||||
await synthtraceEsClient.index(events);
|
||||
|
||||
await createAndRunApmMlJobs({ es, ml, environments: ['production'] });
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await cleanup();
|
||||
});
|
||||
|
||||
async function cleanup() {
|
||||
try {
|
||||
await synthtraceEsClient.clean();
|
||||
await deleteRuleById({ supertest, ruleId });
|
||||
await ml.cleanMlIndices();
|
||||
} catch (e) {
|
||||
logger.info('Could not delete rule by id', e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
describe('with ml jobs', () => {
|
||||
before(async () => {
|
||||
await createAndRunApmMlJobs({ es, ml, environments: ['production'] });
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await ml.cleanMlIndices();
|
||||
});
|
||||
|
||||
it('checks if alert is active', async () => {
|
||||
const createdRule = await createApmRule({
|
||||
supertest,
|
||||
|
@ -97,7 +95,6 @@ export default function ApiTest({ getService }: FtrProviderContext) {
|
|||
},
|
||||
ruleTypeId: ApmRuleType.Anomaly,
|
||||
});
|
||||
|
||||
ruleId = createdRule.id;
|
||||
if (!ruleId) {
|
||||
expect(ruleId).to.not.eql(undefined);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue