diff --git a/x-pack/legacy/plugins/infra/common/http_api/log_entries/entries.ts b/x-pack/legacy/plugins/infra/common/http_api/log_entries/entries.ts index 3d9b32f47f5e..bc9db5722aa9 100644 --- a/x-pack/legacy/plugins/infra/common/http_api/log_entries/entries.ts +++ b/x-pack/legacy/plugins/infra/common/http_api/log_entries/entries.ts @@ -45,12 +45,41 @@ export const logEntriesRequestRT = rt.union([ export type LogEntriesRequest = rt.TypeOf; +// JSON value +const valueRT = rt.union([rt.string, rt.number, rt.boolean, rt.object, rt.null, rt.undefined]); + +export const logMessagePartRT = rt.union([ + rt.type({ + constant: rt.string, + }), + rt.type({ + field: rt.string, + value: valueRT, + highlights: rt.array(rt.string), + }), +]); + +export const logColumnRT = rt.union([ + rt.type({ columnId: rt.string, timestamp: rt.number }), + rt.type({ + columnId: rt.string, + field: rt.string, + value: valueRT, + }), + rt.type({ + columnId: rt.string, + message: rt.array(logMessagePartRT), + }), +]); + export const logEntryRT = rt.type({ id: rt.string, cursor: logEntriesCursorRT, - columns: rt.array(rt.any), + columns: rt.array(logColumnRT), }); +export type LogMessagepart = rt.TypeOf; +export type LogColumn = rt.TypeOf; export type LogEntry = rt.TypeOf; export const logEntriesResponseRT = rt.type({ diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/log_entries_domain.ts b/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/log_entries_domain.ts index 78317fdaa823..2d5aacb1e484 100644 --- a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/log_entries_domain.ts +++ b/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/log_entries_domain.ts @@ -16,6 +16,7 @@ import { LogEntry, LogEntriesItem, LogEntriesCursor, + LogColumn, } from '../../../../common/http_api'; import { InfraLogEntry, InfraLogMessageSegment } from '../../../graphql/types'; import { @@ -203,27 +204,27 @@ export class InfraLogEntriesDomain { return { id: doc.gid, cursor: doc.key, - columns: configuration.logColumns.map(column => { - if ('timestampColumn' in column) { - return { - columnId: column.timestampColumn.id, - timestamp: doc.key.time, - }; - } - if ('messageColumn' in column) { - return { - columnId: column.messageColumn.id, - message: messageFormattingRules.format(doc.fields, doc.highlights), - }; - } - if ('fieldColumn' in column) { - return { - columnId: column.fieldColumn.id, - field: column.fieldColumn.field, - value: doc.fields[column.fieldColumn.field], - }; + columns: configuration.logColumns.map( + (column): LogColumn => { + if ('timestampColumn' in column) { + return { + columnId: column.timestampColumn.id, + timestamp: doc.key.time, + }; + } else if ('messageColumn' in column) { + return { + columnId: column.messageColumn.id, + message: messageFormattingRules.format(doc.fields, doc.highlights), + }; + } else { + return { + columnId: column.fieldColumn.id, + field: column.fieldColumn.field, + value: doc.fields[column.fieldColumn.field], + }; + } } - }), + ), }; });