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

[7.12] [Logs UI] Fixes missing fields in the log entries search strategy (#94443) #94522

Merged
merged 1 commit into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -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