Skip to content

Commit c3a5536

Browse files
[Security_Solution] Split up indices (#69589) (#69718)
* Fixing resolver alert generation * Splitting indices up * Removing tests that could randomly fail because of the generation code * Adding support for multiple indices * Updating archives with the new index names * Removing alerts data stream * Switching to process instead of fake Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 5c0fb09 commit c3a5536

File tree

24 files changed

+130
-74
lines changed

24 files changed

+130
-74
lines changed

x-pack/plugins/security_solution/common/endpoint/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
export const eventsIndexPattern = 'events-endpoint-*';
7+
export const eventsIndexPattern = 'logs-endpoint.events.*';
8+
export const alertsIndexPattern = 'logs-endpoint.alerts-*';
89
export const metadataIndexPattern = 'metrics-endpoint.metadata-*';
910
export const policyIndexPattern = 'metrics-endpoint.policy-*';
1011
export const telemetryIndexPattern = 'metrics-endpoint.telemetry-*';

x-pack/plugins/security_solution/common/endpoint/index_data.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ export async function indexHostsAndAlerts(
1616
metadataIndex: string,
1717
policyIndex: string,
1818
eventIndex: string,
19+
alertIndex: string,
1920
alertsPerHost: number,
2021
options: TreeOptions = {}
2122
) {
2223
const random = seedrandom(seed);
2324
for (let i = 0; i < numHosts; i++) {
2425
const generator = new EndpointDocGenerator(random);
2526
await indexHostDocs(numDocs, client, metadataIndex, policyIndex, generator);
26-
await indexAlerts(client, eventIndex, generator, alertsPerHost, options);
27+
await indexAlerts(client, eventIndex, alertIndex, generator, alertsPerHost, options);
2728
}
2829
await client.indices.refresh({
2930
index: eventIndex,
@@ -65,7 +66,8 @@ async function indexHostDocs(
6566

6667
async function indexAlerts(
6768
client: Client,
68-
index: string,
69+
eventIndex: string,
70+
alertIndex: string,
6971
generator: EndpointDocGenerator,
7072
numAlerts: number,
7173
options: TreeOptions = {}
@@ -82,9 +84,14 @@ async function indexAlerts(
8284
}
8385
const body = resolverDocs.reduce(
8486
// eslint-disable-next-line @typescript-eslint/no-explicit-any
85-
(array: Array<Record<string, any>>, doc) => (
86-
array.push({ create: { _index: index } }, doc), array
87-
),
87+
(array: Array<Record<string, any>>, doc) => {
88+
let index = eventIndex;
89+
if (doc.event.kind === 'alert') {
90+
index = alertIndex;
91+
}
92+
array.push({ create: { _index: index } }, doc);
93+
return array;
94+
},
8895
[]
8996
);
9097
await client.bulk({ body, refresh: 'true' });

x-pack/plugins/security_solution/public/endpoint_alerts/store/middleware.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { eventsIndexPattern } from '../../../common/endpoint/constants';
7+
import { alertsIndexPattern } from '../../../common/endpoint/constants';
88
import { IIndexPattern } from '../../../../../../src/plugins/data/public';
99
import {
1010
AlertResultList,
@@ -49,10 +49,10 @@ export const alertMiddlewareFactory: ImmutableMiddlewareFactory<AlertListState>
4949
async function fetchIndexPatterns(): Promise<IIndexPattern[]> {
5050
const { indexPatterns } = depsStart.data;
5151
const fields = await indexPatterns.getFieldsForWildcard({
52-
pattern: eventsIndexPattern,
52+
pattern: alertsIndexPattern,
5353
});
5454
const indexPattern: IIndexPattern = {
55-
title: eventsIndexPattern,
55+
title: alertsIndexPattern,
5656
fields,
5757
};
5858

x-pack/plugins/security_solution/scripts/endpoint/resolver_generator.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,25 @@ async function main() {
9595
eventIndex: {
9696
alias: 'ei',
9797
describe: 'index to store events in',
98-
default: 'events-endpoint-1',
98+
default: 'logs-endpoint.events.process-default',
99+
type: 'string',
100+
},
101+
alertIndex: {
102+
alias: 'ai',
103+
describe: 'index to store alerts in',
104+
default: 'logs-endpoint.alerts-default',
99105
type: 'string',
100106
},
101107
metadataIndex: {
102108
alias: 'mi',
103109
describe: 'index to store host metadata in',
104-
default: 'metrics-endpoint.metadata-default-1',
110+
default: 'metrics-endpoint.metadata-default',
105111
type: 'string',
106112
},
107113
policyIndex: {
108114
alias: 'pi',
109115
describe: 'index to store host policy in',
110-
default: 'metrics-endpoint.policy-default-1',
116+
default: 'metrics-endpoint.policy-default',
111117
type: 'string',
112118
},
113119
ancestors: {
@@ -192,7 +198,10 @@ async function main() {
192198

193199
const client = new Client(clientOptions);
194200
if (argv.delete) {
195-
await deleteIndices([argv.eventIndex, argv.metadataIndex, argv.policyIndex], client);
201+
await deleteIndices(
202+
[argv.eventIndex, argv.metadataIndex, argv.policyIndex, argv.alertIndex],
203+
client
204+
);
196205
}
197206

198207
let seed = argv.seed;
@@ -209,6 +218,7 @@ async function main() {
209218
argv.metadataIndex,
210219
argv.policyIndex,
211220
argv.eventIndex,
221+
argv.alertIndex,
212222
argv.alertsPerHost,
213223
{
214224
ancestors: argv.ancestors,

x-pack/plugins/security_solution/server/endpoint/alerts/handlers/details/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
import { GetResponse } from 'elasticsearch';
77
import { KibanaRequest, RequestHandler } from 'kibana/server';
8-
import { eventsIndexPattern } from '../../../../../common/endpoint/constants';
8+
import { alertsIndexPattern } from '../../../../../common/endpoint/constants';
99
import { AlertEvent } from '../../../../../common/endpoint/types';
1010
import { EndpointAppContext } from '../../../types';
1111
import { AlertDetailsRequestParams } from '../../../../../common/endpoint_alerts/types';
@@ -34,7 +34,7 @@ export const alertDetailsHandlerWrapper = function (
3434
ctx,
3535
req.params,
3636
response,
37-
eventsIndexPattern
37+
alertsIndexPattern
3838
);
3939

4040
const currentHostInfo = await getHostData(

x-pack/plugins/security_solution/server/endpoint/alerts/handlers/list/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66
import { RequestHandler } from 'kibana/server';
7-
import { eventsIndexPattern } from '../../../../../common/endpoint/constants';
7+
import { alertsIndexPattern } from '../../../../../common/endpoint/constants';
88
import { EndpointAppContext } from '../../../types';
99
import { searchESForAlerts } from '../lib';
1010
import { getRequestData, mapToAlertResultList } from './lib';
@@ -23,7 +23,7 @@ export const alertListHandlerWrapper = function (
2323
const response = await searchESForAlerts(
2424
ctx.core.elasticsearch.legacy.client,
2525
reqData,
26-
eventsIndexPattern
26+
alertsIndexPattern
2727
);
2828
const mappedBody = await mapToAlertResultList(ctx, endpointAppContext, reqData, response);
2929
return res.ok({ body: mappedBody });

x-pack/plugins/security_solution/server/endpoint/routes/resolver/alerts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { TypeOf } from '@kbn/config-schema';
88
import { RequestHandler, Logger } from 'kibana/server';
99
import { validateAlerts } from '../../../../common/endpoint/schema/resolver';
10-
import { eventsIndexPattern } from '../../../../common/endpoint/constants';
10+
import { alertsIndexPattern, eventsIndexPattern } from '../../../../common/endpoint/constants';
1111
import { Fetcher } from './utils/fetch';
1212
import { EndpointAppContext } from '../../types';
1313

@@ -23,7 +23,7 @@ export function handleAlerts(
2323
try {
2424
const client = context.core.elasticsearch.legacy.client;
2525

26-
const fetcher = new Fetcher(client, id, eventsIndexPattern, endpointID);
26+
const fetcher = new Fetcher(client, id, eventsIndexPattern, alertsIndexPattern, endpointID);
2727

2828
return res.ok({
2929
body: await fetcher.alerts(alerts, afterAlert),

x-pack/plugins/security_solution/server/endpoint/routes/resolver/ancestry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import { RequestHandler, Logger } from 'kibana/server';
88
import { TypeOf } from '@kbn/config-schema';
9-
import { eventsIndexPattern } from '../../../../common/endpoint/constants';
9+
import { eventsIndexPattern, alertsIndexPattern } from '../../../../common/endpoint/constants';
1010
import { validateAncestry } from '../../../../common/endpoint/schema/resolver';
1111
import { Fetcher } from './utils/fetch';
1212
import { EndpointAppContext } from '../../types';
@@ -23,7 +23,7 @@ export function handleAncestry(
2323
try {
2424
const client = context.core.elasticsearch.legacy.client;
2525

26-
const fetcher = new Fetcher(client, id, eventsIndexPattern, endpointID);
26+
const fetcher = new Fetcher(client, id, eventsIndexPattern, alertsIndexPattern, endpointID);
2727
const ancestorInfo = await fetcher.ancestors(ancestors);
2828

2929
return res.ok({

x-pack/plugins/security_solution/server/endpoint/routes/resolver/children.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import { RequestHandler, Logger } from 'kibana/server';
88
import { TypeOf } from '@kbn/config-schema';
9-
import { eventsIndexPattern } from '../../../../common/endpoint/constants';
9+
import { eventsIndexPattern, alertsIndexPattern } from '../../../../common/endpoint/constants';
1010
import { validateChildren } from '../../../../common/endpoint/schema/resolver';
1111
import { Fetcher } from './utils/fetch';
1212
import { EndpointAppContext } from '../../types';
@@ -22,7 +22,7 @@ export function handleChildren(
2222
} = req;
2323
try {
2424
const client = context.core.elasticsearch.legacy.client;
25-
const fetcher = new Fetcher(client, id, eventsIndexPattern, endpointID);
25+
const fetcher = new Fetcher(client, id, eventsIndexPattern, alertsIndexPattern, endpointID);
2626

2727
return res.ok({
2828
body: await fetcher.children(children, generations, afterChild),

x-pack/plugins/security_solution/server/endpoint/routes/resolver/events.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import { TypeOf } from '@kbn/config-schema';
88
import { RequestHandler, Logger } from 'kibana/server';
9-
import { eventsIndexPattern } from '../../../../common/endpoint/constants';
9+
import { eventsIndexPattern, alertsIndexPattern } from '../../../../common/endpoint/constants';
1010
import { validateEvents } from '../../../../common/endpoint/schema/resolver';
1111
import { Fetcher } from './utils/fetch';
1212
import { EndpointAppContext } from '../../types';
@@ -23,7 +23,7 @@ export function handleEvents(
2323
try {
2424
const client = context.core.elasticsearch.legacy.client;
2525

26-
const fetcher = new Fetcher(client, id, eventsIndexPattern, endpointID);
26+
const fetcher = new Fetcher(client, id, eventsIndexPattern, alertsIndexPattern, endpointID);
2727

2828
return res.ok({
2929
body: await fetcher.events(events, afterEvent),

0 commit comments

Comments
 (0)