Skip to content

Commit

Permalink
[7.x] [Logs UI] Use fields API in logs ML category examples (#77188) (#…
Browse files Browse the repository at this point in the history
…78029)

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
Alejandro Fernández Gómez and elasticmachine committed Sep 22, 2020
1 parent bed8fcf commit 9c75cf7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,8 @@ export async function fetchLogEntryExamples(
return {
examples: hits.map((hit) => ({
id: hit._id,
dataset: hit._source.event?.dataset ?? '',
message: hit._source.message ?? '',
dataset: hit.fields['event.dataset']?.[0] ?? '',
message: hit.fields.message?.[0] ?? '',
timestamp: hit.sort[0],
tiebreaker: hit.sort[1],
})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from './queries/log_entry_categories';
import {
createLogEntryCategoryExamplesQuery,
LogEntryCategoryExampleHit,
logEntryCategoryExamplesResponseRT,
} from './queries/log_entry_category_examples';
import {
Expand Down Expand Up @@ -423,11 +424,11 @@ async function fetchLogEntryCategoryExamples(
return {
examples: hits.map((hit) => ({
id: hit._id,
dataset: hit._source.event?.dataset ?? '',
message: hit._source.message ?? '',
dataset: hit.fields['event.dataset']?.[0] ?? '',
message: hit.fields.message?.[0] ?? '',
timestamp: hit.sort[0],
tiebreaker: hit.sort[1],
context: getContextFromSource(hit._source),
context: getContextFromFields(hit.fields),
})),
timing: {
spans: [esSearchSpan],
Expand All @@ -437,10 +438,10 @@ async function fetchLogEntryCategoryExamples(

const parseCategoryId = (rawCategoryId: string) => parseInt(rawCategoryId, 10);

const getContextFromSource = (source: any): LogEntryContext => {
const containerId = source.container?.id;
const hostName = source.host?.name;
const logFilePath = source.log?.file?.path;
const getContextFromFields = (fields: LogEntryCategoryExampleHit['fields']): LogEntryContext => {
const containerId = fields['container.id']?.[0];
const hostName = fields['host.name']?.[0];
const logFilePath = fields['log.file.path']?.[0];

if (typeof containerId === 'string') {
return { 'container.id': containerId };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,21 @@ export const createLogEntryCategoryExamplesQuery = (
},
},
sort: [{ [timestampField]: 'asc' }, { [tiebreakerField]: 'asc' }],
_source: false,
fields: ['event.dataset', 'message', 'container.id', 'host.name', 'log.file.path'],
},
_source: ['event.dataset', 'message', 'container.id', 'host.name', 'log.file.path'],
index: indices,
size: exampleCount,
});

export const logEntryCategoryExampleHitRT = rt.type({
_id: rt.string,
_source: rt.partial({
event: rt.partial({
dataset: rt.string,
}),
message: rt.string,
container: rt.partial({
id: rt.string,
}),
host: rt.partial({
name: rt.string,
}),
log: rt.partial({
file: rt.partial({
path: rt.string,
}),
}),
fields: rt.partial({
'event.dataset': rt.array(rt.string),
message: rt.array(rt.string),
'container.id': rt.array(rt.string),
'host.name': rt.array(rt.string),
'log.file.path': rt.array(rt.string),
}),
sort: rt.tuple([rt.number, rt.number]),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,18 @@ export const createLogEntryExamplesQuery = (
},
},
sort: [{ [timestampField]: 'asc' }, { [tiebreakerField]: 'asc' }],
_source: false,
fields: ['event.dataset', 'message'],
},
_source: ['event.dataset', 'message'],
index: indices,
size: exampleCount,
});

export const logEntryExampleHitRT = rt.type({
_id: rt.string,
_source: rt.partial({
event: rt.partial({
dataset: rt.string,
}),
message: rt.string,
fields: rt.partial({
'event.dataset': rt.array(rt.string),
message: rt.array(rt.string),
}),
sort: rt.tuple([rt.number, rt.number]),
});
Expand Down

0 comments on commit 9c75cf7

Please sign in to comment.