Skip to content

Commit

Permalink
[Logs UI] Fixes missing fields in the log entries search strategy (#9…
Browse files Browse the repository at this point in the history
…4443) (#94522)

Co-authored-by: Kerry Gallagher <[email protected]>
  • Loading branch information
kibanamachine and Kerry350 authored Mar 12, 2021
1 parent 5d1707a commit fcab4fd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const logSourceMessageColumnConfigurationRT = rt.strict({
messageColumn: logSourceCommonColumnConfigurationRT,
});

const logSourceFieldColumnConfigurationRT = rt.strict({
export const logSourceFieldColumnConfigurationRT = rt.strict({
fieldColumn: rt.intersection([
logSourceCommonColumnConfigurationRT,
rt.strict({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import type {
ISearchStrategy,
PluginStart as DataPluginStart,
} from '../../../../../../src/plugins/data/server';
import { LogSourceColumnConfiguration } from '../../../common/http_api/log_sources';
import {
LogSourceColumnConfiguration,
LogSourceConfigurationProperties,
logSourceFieldColumnConfigurationRT,
} from '../../../common/http_api/log_sources';
import {
getLogEntryCursorFromHit,
LogColumn,
Expand Down Expand Up @@ -103,7 +107,7 @@ export const logEntriesSearchStrategyProvider = ({
params.size + 1,
configuration.fields.timestamp,
configuration.fields.tiebreaker,
messageFormattingRules.requiredFields,
getRequiredFields(configuration, messageFormattingRules, params.columns),
params.query,
params.highlightPhrase
),
Expand All @@ -125,7 +129,12 @@ export const logEntriesSearchStrategyProvider = ({

const entries = rawResponse.hits.hits
.slice(0, request.params.size)
.map(getLogEntryFromHit(configuration.logColumns, messageFormattingRules));
.map(
getLogEntryFromHit(
request.params.columns ? request.params.columns : configuration.logColumns,
messageFormattingRules
)
);

const sortDirection = getSortDirection(pickRequestCursor(request.params));

Expand Down Expand Up @@ -244,3 +253,26 @@ function getResponseCursors(entries: LogEntry[]) {

return { topCursor, bottomCursor };
}

const VIEW_IN_CONTEXT_FIELDS = ['log.file.path', 'host.name', 'container.id'];

const getRequiredFields = (
configuration: LogSourceConfigurationProperties,
messageFormattingRules: CompiledLogMessageFormattingRule,
columnOverrides?: LogSourceColumnConfiguration[]
): string[] => {
const columns = columnOverrides ? columnOverrides : configuration.logColumns;

const fieldsFromColumns = columns.reduce<string[]>((accumulatedFields, logColumn) => {
if (logSourceFieldColumnConfigurationRT.is(logColumn)) {
return [...accumulatedFields, logColumn.fieldColumn.field];
}
return accumulatedFields;
}, []);

const fieldsFromFormattingRules = messageFormattingRules.requiredFields;

return Array.from(
new Set([...fieldsFromColumns, ...fieldsFromFormattingRules, ...VIEW_IN_CONTEXT_FIELDS])
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import {
} from '../../../utils/elasticsearch_runtime_types';
import { createSortClause, createTimeRangeFilterClauses } from './common';

const CONTEXT_FIELDS = ['log.file.path', 'host.name', 'container.id'];

export const createGetLogEntriesQuery = (
logEntriesIndex: string,
startTimestamp: number,
Expand All @@ -36,7 +34,6 @@ export const createGetLogEntriesQuery = (
): RequestParams.AsyncSearchSubmit<Record<string, any>> => {
const sortDirection = getSortDirection(cursor);
const highlightQuery = createHighlightQuery(highlightTerm, fields);
const fieldsWithContext = createFieldsWithContext(fields);

return {
index: logEntriesIndex,
Expand All @@ -54,7 +51,7 @@ export const createGetLogEntriesQuery = (
],
},
},
fields: fieldsWithContext,
fields,
_source: false,
...createSortClause(sortDirection, timestampField, tiebreakerField),
...createSearchAfterClause(cursor),
Expand Down Expand Up @@ -120,9 +117,6 @@ const createHighlightQuery = (
}
};

const createFieldsWithContext = (fields: string[]): string[] =>
Array.from(new Set([...fields, ...CONTEXT_FIELDS]));

export const logEntryHitRT = rt.intersection([
commonHitFieldsRT,
rt.type({
Expand Down

0 comments on commit fcab4fd

Please sign in to comment.