-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Endpoint] Fix endpoint tests with data streams #68794
Changes from 2 commits
afd44ea
6a58ee9
57aa58a
740563f
494a8e9
738d995
dbbe256
290c3c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import expect from '@kbn/expect/expect.js'; | |
import { FtrProviderContext } from '../../../ftr_provider_context'; | ||
import { AlertData } from '../../../../../plugins/security_solution/common/endpoint_alerts/types'; | ||
import { AlertId } from '../../../../../plugins/security_solution/server/endpoint/alerts/handlers/lib/index'; | ||
import { deleteEventsStream, deleteMetadataStream } from '../data_stream_helper'; | ||
|
||
/** | ||
* The number of alert documents in the es archive. | ||
|
@@ -66,26 +67,27 @@ export default function ({ getService }: FtrProviderContext) { | |
const nextPrevPrefixOrder = 'order=desc'; | ||
const nextPrevPrefixPageSize = 'page_size=10'; | ||
const nextPrevPrefix = `${nextPrevPrefixQuery}&${nextPrevPrefixDateRange}&${nextPrevPrefixSort}&${nextPrevPrefixOrder}&${nextPrevPrefixPageSize}`; | ||
const alertIndex = 'events-endpoint-1'; | ||
const alertIndex = '.ds-events-endpoint-1-000001'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The alert tests need the exact backing index for a couple of the tests. I don't love this, another option would be to just remove those tests I suppose. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed the event is quite different from the other indices, I am guessing this is the best right now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah it's going to change soon. It depends on the conclusion of this discussion: https://github.com/elastic/endpoint-app-team/issues/102 |
||
|
||
let nullableEventId = ''; | ||
|
||
// SKIPPED as it is failing ES PROMOTION: https://github.com/elastic/kibana/issues/68613 | ||
describe.skip('Endpoint alert API', () => { | ||
describe('Endpoint alert API', () => { | ||
describe('when data is in elasticsearch', () => { | ||
before(async () => { | ||
await esArchiver.load('endpoint/alerts/api_feature'); | ||
await esArchiver.load('endpoint/alerts/host_api_feature'); | ||
const res = await es.search({ | ||
index: alertIndex, | ||
index: 'events-endpoint-*', | ||
body: ES_QUERY_MISSING, | ||
}); | ||
nullableEventId = res.hits.hits[0]._source.event.id; | ||
}); | ||
|
||
after(async () => { | ||
await esArchiver.unload('endpoint/alerts/api_feature'); | ||
await esArchiver.unload('endpoint/alerts/host_api_feature'); | ||
// the endpoint uses data streams and es archiver does not support deleting them at the moment so we need | ||
// to do it manually | ||
await deleteEventsStream(getService); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To help it run a bit faster, you can wrap these two calls in a |
||
await deleteMetadataStream(getService); | ||
}); | ||
|
||
it('should not support POST requests', async () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { Client } from '@elastic/elasticsearch'; | ||
|
||
export async function deleteDataStream(getService: (serviceName: 'es') => Client, index: string) { | ||
const client = getService('es'); | ||
await client.transport.request( | ||
{ | ||
method: 'DELETE', | ||
path: `_data_stream/${index}`, | ||
}, | ||
{ | ||
ignore: [404], | ||
} | ||
); | ||
} | ||
|
||
export async function deleteMetadataStream(getService: (serviceName: 'es') => Client) { | ||
await deleteDataStream(getService, 'metrics-endpoint.metadata-*'); | ||
} | ||
|
||
export async function deleteEventsStream(getService: (serviceName: 'es') => Client) { | ||
await deleteDataStream(getService, 'events-endpoint-*'); | ||
} | ||
|
||
export async function deletePolicyStream(getService: (serviceName: 'es') => Client) { | ||
await deleteDataStream(getService, 'metrics-endpoint.policy-*'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Data streams will fail if using
index