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

[Event Log] Ensure sorting tests are less flaky #64781

Merged
merged 6 commits into from
May 4, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
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 @@ -42,6 +42,9 @@ export const logEventRoute = (router: IRouter, eventLogger: IEventLogger, logger
await context.core.savedObjects.client.create('event_log_test', {}, { id });
logger.info(`created saved object ${id}`);
}
// mark now as start and end
Copy link
Member

Choose a reason for hiding this comment

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

The only slightly odd thing here is that for the test where we search by end date, all of these events will have an end date - however, IRL, not all events have end dates. We may need to do something in the future - like when searching via end date, add an additional filter to only return events with an end date - but let's wait to see how people use this, to see if something needs to be done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, agreed, though this is sort by end rather than search by end.. semantics but it means that the behaviour is inline with how ES queries generally behave.

eventLogger.startTiming(event);
eventLogger.stopTiming(event);
eventLogger.logEvent(event);
logger.info(`logged`);
return res.ok({});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ export default function({ getService }: FtrProviderContext) {
const log = getService('log');
const retry = getService('retry');

// FLAKY: https://github.com/elastic/kibana/issues/64723
// FLAKY: https://github.com/elastic/kibana/issues/64812
describe.skip('Event Log public API', () => {
describe('Event Log public API', () => {
it('should allow querying for events by Saved Object', async () => {
const id = uuid.v4();

Expand Down Expand Up @@ -82,21 +80,15 @@ export default function({ getService }: FtrProviderContext) {
it('should support sorting by event end', async () => {
const id = uuid.v4();

const [firstExpectedEvent, ...expectedEvents] = times(6, () => fakeEvent(id));
// run one first to create the SO and avoid clashes
await logTestEvent(id, firstExpectedEvent);
await Promise.all(expectedEvents.map(event => logTestEvent(id, event)));
const expectedEvents = await logFakeEvents(id, 6);

await retry.try(async () => {
const {
body: { data: foundEvents },
} = await findEvents(id, { sort_field: 'event.end', sort_order: 'desc' });

expect(foundEvents.length).to.be(6);
assertEventsFromApiMatchCreatedEvents(
foundEvents,
[firstExpectedEvent, ...expectedEvents].reverse()
);
expect(foundEvents.length).to.be(expectedEvents.length);
assertEventsFromApiMatchCreatedEvents(foundEvents, expectedEvents.reverse());
});
});

Expand All @@ -112,8 +104,7 @@ export default function({ getService }: FtrProviderContext) {
const start = new Date().toISOString();

// write the documents that we should be found in the date range searches
const expectedEvents = times(6, () => fakeEvent(id));
await Promise.all(expectedEvents.map(event => logTestEvent(id, event)));
const expectedEvents = await logFakeEvents(id, 6);

// get the end time for the date range search
const end = new Date().toISOString();
Expand Down Expand Up @@ -176,7 +167,9 @@ export default function({ getService }: FtrProviderContext) {
) {
try {
foundEvents.forEach((foundEvent: IValidatedEvent, index: number) => {
expect(foundEvent!.event).to.eql(expectedEvents[index]!.event);
expect(omit(foundEvent!.event ?? {}, 'start', 'end', 'duration')).to.eql(
expectedEvents[index]!.event
);
expect(omit(foundEvent!.kibana ?? {}, 'server_uuid')).to.eql(expectedEvents[index]!.kibana);
expect(foundEvent!.message).to.eql(expectedEvents[index]!.message);
});
Expand Down Expand Up @@ -217,4 +210,14 @@ export default function({ getService }: FtrProviderContext) {
overrides
);
}

async function logFakeEvents(savedObjectId: string, eventsToLog: number): Promise<IEvent[]> {
const expectedEvents: IEvent[] = [];
for (let index = 0; index < eventsToLog; index++) {
const event = fakeEvent(savedObjectId);
await logTestEvent(savedObjectId, event);
expectedEvents.push(event);
}
return expectedEvents;
}
}