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

[ObsUX] Fix timestamp for anomaly alert test #169255

Merged
Merged
Changes from 1 commit
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 @@ -23,23 +23,24 @@ 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 = Date.now() - 1000 * 60 * 60 * 24 * 2; // day ago
const end = Date.now();
Copy link
Member

@sorenlouv sorenlouv Oct 18, 2023

Choose a reason for hiding this comment

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

nit: moment with subtract() and add() is easier to read.

start: moment(end).subtract(7, 'minutes').toISOString(),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed here bf3d743


const spikeStart = new Date('2021-01-07T23:15:00.000Z').getTime();
const spikeEnd = new Date('2021-01-08T00:15:00.000Z').getTime();
const spikeStart = new Date(Date.now() - 1000 * 60 * 15).getTime(); // 15 minutes ago
const spikeEnd = new Date(Date.now()).getTime();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const spikeEnd = new Date(Date.now()).getTime();
const spikeEnd = Date.now();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated here bf3d743


const NORMAL_DURATION = 100;
const NORMAL_RATE = 1;

let ruleId: string;

before(async () => {
await cleanup();
Copy link
Contributor

@kpatticha kpatticha Oct 19, 2023

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We want to clean before and after the test

Copy link
Member

Choose a reason for hiding this comment

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

During development it's much easier if cleanup happens before running the test. On CI it is better to have cleanup after to avoid contamination between tests. I don't have strong opinions whether we need to cleanup both before and after though. Perhaps you can comment out the cleanup in the before step. It's still easy to enable for debug purposes.


const serviceA = apm
.service({ name: 'a', environment: 'production', agentName: 'java' })
.instance('a');
Expand All @@ -65,26 +66,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,
Expand All @@ -97,7 +97,6 @@ export default function ApiTest({ getService }: FtrProviderContext) {
},
ruleTypeId: ApmRuleType.Anomaly,
});

ruleId = createdRule.id;
if (!ruleId) {
expect(ruleId).to.not.eql(undefined);
Expand Down