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

EMT-661: use new metadata current #74394

Merged
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
c7c37ff
EMT-661: use new metadata current
nnamdifrankie Aug 5, 2020
b222ae8
EMT-661: fix build
nnamdifrankie Aug 5, 2020
a518df4
EMT-661: fix build for now
nnamdifrankie Aug 5, 2020
c0a4d84
Merge branch 'master' into EMT-661-use-metadata-current-index
nnamdifrankie Aug 6, 2020
3603f5e
EMT-661: update schema and fix build
nnamdifrankie Aug 6, 2020
a356c92
EMT-661: fix test
nnamdifrankie Aug 6, 2020
70c5311
EMT-661: fix build
nnamdifrankie Aug 7, 2020
482c054
EMT-661: increase time for transform
nnamdifrankie Aug 7, 2020
614cfd8
EMT-661: disable frontend test
nnamdifrankie Aug 9, 2020
106628d
EMT-661: update build
nnamdifrankie Aug 10, 2020
30b7e7a
Merge branch 'master' into EMT-661-use-metadata-current-index
nnamdifrankie Aug 10, 2020
d5578b6
EMT-661: fix tests
nnamdifrankie Aug 10, 2020
74c4988
EMT-661: fix test and type check
nnamdifrankie Aug 10, 2020
0ad91e9
EMT-661: add missing file
nnamdifrankie Aug 10, 2020
b56369a
EMT-661: clean up and refactor
nnamdifrankie Aug 10, 2020
eca0a8d
Merge branch 'master' into EMT-661-use-metadata-current-index
nnamdifrankie Aug 13, 2020
edb1d30
more clean up
nnamdifrankie Aug 13, 2020
e09e512
Merge branch 'master' into EMT-661-use-metadata-current-index
elasticmachine Aug 18, 2020
13442a8
Merge branch 'master' into EMT-661-use-metadata-current-index
nnamdifrankie Aug 20, 2020
77e4395
Merge branch 'master' into EMT-661-use-metadata-current-index
nnamdifrankie Aug 29, 2020
d450f9d
EMT-661: add epm first steps.
nnamdifrankie Aug 31, 2020
b0a51a2
EMT-661: remove transform helper
nnamdifrankie Aug 31, 2020
cbf7d2d
EMT-661: fix tests
nnamdifrankie Sep 1, 2020
c21b7c8
EMT-661: fix test
nnamdifrankie Sep 1, 2020
349fcd1
EMT-661: add test for installing transform
nnamdifrankie Sep 2, 2020
4f8a9e6
EMT-661: fix build
nnamdifrankie Sep 3, 2020
d592bcb
EMT-661: fix build
nnamdifrankie Sep 3, 2020
07bc7ba
EMT-661: clean up
nnamdifrankie Sep 3, 2020
b00c65c
EMT-661: clean up
nnamdifrankie Sep 3, 2020
da3ad7c
EMT-661: fix build temp
nnamdifrankie Sep 3, 2020
eb0c4df
EMT-661: fix build
nnamdifrankie Sep 3, 2020
5e84d99
EMT-661: add more test, and remove 400 guard
nnamdifrankie Sep 3, 2020
2786976
Merge branch 'master' into EMT-661-use-metadata-current-index
elasticmachine Sep 3, 2020
a6225eb
EMT-661: fix build for now
nnamdifrankie Sep 3, 2020
7f26338
Merge branch 'master' into EMT-661-use-metadata-current-index
elasticmachine Sep 3, 2020
5e8ad6e
EMT-661: enable no data tests./
nnamdifrankie Sep 3, 2020
c2fae69
EMT-661: move things
nnamdifrankie Sep 3, 2020
cc1d123
EMT-661: clean up code, add more test, review comments.
nnamdifrankie Sep 4, 2020
5dafd4d
EMT-661: add integration test
nnamdifrankie Sep 4, 2020
4affdb1
EMT-661: change index pattern
nnamdifrankie Sep 4, 2020
301a299
EMT-661: more clean up
nnamdifrankie Sep 4, 2020
0d8ccee
EMT-661: fix build
nnamdifrankie Sep 4, 2020
bdf394c
EMT-661: fix transform name.
nnamdifrankie Sep 4, 2020
0bf0fa3
EMT-661: handle when current version is same as previous version
nnamdifrankie Sep 4, 2020
809a3d7
EMT-661: remove delete before put.
nnamdifrankie Sep 5, 2020
f22d28f
Merge branch 'master' into EMT-661-use-metadata-current-index
elasticmachine Sep 5, 2020
1bb921b
EMT-661: trigger build
nnamdifrankie Sep 6, 2020
952824e
EMT-661: skip polling test, should be moved.
nnamdifrankie Sep 6, 2020
1b769c3
Merge branch 'master' into EMT-661-use-metadata-current-index
elasticmachine Sep 7, 2020
51302c7
EMT-661: move position of transform reference in test
nnamdifrankie Sep 8, 2020
2bc5d3a
Merge branch 'master' into EMT-661-use-metadata-current-index
nnamdifrankie Sep 8, 2020
db0b200
EMT-661: Only delete when there are previous installation has a trans…
nnamdifrankie Sep 8, 2020
6e1532d
Merge branch 'master' into EMT-661-use-metadata-current-index
nnamdifrankie Sep 8, 2020
192a1c4
EMT-661: lint
nnamdifrankie Sep 8, 2020
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 @@ -7,6 +7,7 @@
export const eventsIndexPattern = 'logs-endpoint.events.*';
export const alertsIndexPattern = 'logs-endpoint.alerts-*';
export const metadataIndexPattern = 'metrics-endpoint.metadata-*';
export const metadataCurrentIndexPattern = 'metrics-endpoint.metadata_current-*';
export const policyIndexPattern = 'metrics-endpoint.policy-*';
export const telemetryIndexPattern = 'metrics-endpoint.telemetry-*';
export const LIMITED_CONCURRENCY_ENDPOINT_ROUTE_TAG = 'endpoint:limited-concurrency';
Expand Down
7 changes: 7 additions & 0 deletions x-pack/plugins/security_solution/common/endpoint/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,13 @@ export type HostInfo = Immutable<{
host_status: HostStatus;
}>;

export type HostMetadataDetails = Immutable<{
agent: {
id: string;
};
HostDetails: HostMetadata;
}>;

export type HostMetadata = Immutable<{
'@timestamp': number;
event: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import { SearchResponse } from 'elasticsearch';
import { schema } from '@kbn/config-schema';
import Boom from 'boom';

import { metadataIndexPattern } from '../../../../common/endpoint/constants';
import { metadataCurrentIndexPattern } from '../../../../common/endpoint/constants';
import { getESQueryHostMetadataByID, kibanaRequestToMetadataListESQuery } from './query_builders';
import {
HostInfo,
HostMetadata,
HostMetadataDetails,
HostResultList,
HostStatus,
} from '../../../../common/endpoint/types';
Expand All @@ -23,10 +24,6 @@ import { Agent, AgentStatus } from '../../../../../ingest_manager/common/types/m
import { findAllUnenrolledAgentIds } from './support/unenroll';
import { findAgentIDsByStatus } from './support/agent_status';

interface HitSource {
_source: HostMetadata;
}

interface MetadataRequestContext {
agentService: AgentService;
logger: Logger;
Expand Down Expand Up @@ -127,7 +124,7 @@ export function registerEndpointRoutes(router: IRouter, endpointAppContext: Endp
const queryParams = await kibanaRequestToMetadataListESQuery(
req,
endpointAppContext,
metadataIndexPattern,
metadataCurrentIndexPattern,
{
unenrolledAgentIds: unenrolledAgentIds.concat(IGNORED_ELASTIC_AGENT_IDS),
statusAgentIDs: statusIDs,
Expand All @@ -137,7 +134,7 @@ export function registerEndpointRoutes(router: IRouter, endpointAppContext: Endp
const response = (await context.core.elasticsearch.legacy.client.callAsCurrentUser(
'search',
queryParams
)) as SearchResponse<HostMetadata>;
)) as SearchResponse<HostMetadataDetails>;

return res.ok({
body: await mapToHostResultList(queryParams, response, metadataRequestContext),
Expand Down Expand Up @@ -193,17 +190,17 @@ export async function getHostData(
metadataRequestContext: MetadataRequestContext,
id: string
): Promise<HostInfo | undefined> {
const query = getESQueryHostMetadataByID(id, metadataIndexPattern);
const query = getESQueryHostMetadataByID(id, metadataCurrentIndexPattern);
const response = (await metadataRequestContext.requestHandlerContext.core.elasticsearch.legacy.client.callAsCurrentUser(
'search',
query
)) as SearchResponse<HostMetadata>;
)) as SearchResponse<HostMetadataDetails>;

if (response.hits.hits.length === 0) {
return undefined;
}

const hostMetadata: HostMetadata = response.hits.hits[0]._source;
const hostMetadata: HostMetadata = response.hits.hits[0]._source.HostDetails;
const agent = await findAgent(metadataRequestContext, hostMetadata);

if (agent && !agent.active) {
Expand Down Expand Up @@ -241,19 +238,19 @@ async function findAgent(
async function mapToHostResultList(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
queryParams: Record<string, any>,
searchResponse: SearchResponse<HostMetadata>,
searchResponse: SearchResponse<HostMetadataDetails>,
metadataRequestContext: MetadataRequestContext
): Promise<HostResultList> {
const totalNumberOfHosts = searchResponse?.aggregations?.total?.value || 0;
const totalNumberOfHosts =
((searchResponse.hits?.total as unknown) as { value: number; relation: string }).value || 0;
if (searchResponse.hits.hits.length > 0) {
return {
request_page_size: queryParams.size,
request_page_index: queryParams.from,
hosts: await Promise.all(
searchResponse.hits.hits
.map((response) => response.inner_hits.most_recent.hits.hits)
.flatMap((data) => data as HitSource)
.map(async (entry) => enrichHostMetadata(entry._source, metadataRequestContext))
searchResponse.hits.hits.map(async (entry) =>
enrichHostMetadata(entry._source.HostDetails, metadataRequestContext)
)
),
total: totalNumberOfHosts,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
import {
HostInfo,
HostMetadata,
HostMetadataDetails,
HostResultList,
HostStatus,
} from '../../../../common/endpoint/types';
Expand Down Expand Up @@ -141,7 +142,7 @@ describe('test endpoint route', () => {
bool: {
must_not: {
terms: {
'elastic.agent.id': [
'HostDetails.elastic.agent.id': [
'00000000-0000-0000-0000-000000000000',
'11111111-1111-1111-1111-111111111111',
],
Expand Down Expand Up @@ -197,7 +198,7 @@ describe('test endpoint route', () => {
bool: {
must_not: {
terms: {
'elastic.agent.id': [
'HostDetails.elastic.agent.id': [
'00000000-0000-0000-0000-000000000000',
'11111111-1111-1111-1111-111111111111',
],
Expand Down Expand Up @@ -442,7 +443,7 @@ describe('Filters Schema Test', () => {
});
});

function createSearchResponse(hostMetadata?: HostMetadata): SearchResponse<HostMetadata> {
function createSearchResponse(hostMetadata?: HostMetadata): SearchResponse<HostMetadataDetails> {
return ({
took: 15,
timed_out: false,
Expand All @@ -454,7 +455,7 @@ function createSearchResponse(hostMetadata?: HostMetadata): SearchResponse<HostM
},
hits: {
total: {
value: 5,
value: 1,
relation: 'eq',
},
max_score: null,
Expand All @@ -464,36 +465,18 @@ function createSearchResponse(hostMetadata?: HostMetadata): SearchResponse<HostM
_index: 'metrics-endpoint.metadata-default',
_id: '8FhM0HEBYyRTvb6lOQnw',
_score: null,
_source: hostMetadata,
sort: [1588337587997],
inner_hits: {
most_recent: {
hits: {
total: {
value: 2,
relation: 'eq',
},
max_score: null,
hits: [
{
_index: 'metrics-endpoint.metadata-default',
_id: 'W6Vo1G8BYQH1gtPUgYkC',
_score: null,
_source: hostMetadata,
sort: [1579816615336],
},
],
},
_source: {
agent: {
id: '1e3472bb-5c20-4946-b469-b5af1a809e4f',
},
HostDetails: {
...hostMetadata,
},
},
sort: [1588337587997],
},
]
: [],
},
aggregations: {
total: {
value: 1,
},
},
} as unknown) as SearchResponse<HostMetadata>;
} as unknown) as SearchResponse<HostMetadataDetails>;
}
Loading