Skip to content

Commit

Permalink
Use fields API in /item API
Browse files Browse the repository at this point in the history
  • Loading branch information
afgomez authored and Alejandro Fernández Gómez committed Sep 8, 2020
1 parent 1c57b84 commit 528c82a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { pipe } from 'fp-ts/lib/pipeable';
import { map, fold } from 'fp-ts/lib/Either';
import { identity, constant } from 'fp-ts/lib/function';
import { RequestHandlerContext } from 'src/core/server';
import { JsonObject, JsonValue } from '../../../../common/typed_json';
import { JsonValue } from '../../../../common/typed_json';
import {
LogEntriesAdapter,
LogEntriesParams,
Expand All @@ -31,7 +31,7 @@ const TIMESTAMP_FORMAT = 'epoch_millis';
interface LogItemHit {
_index: string;
_id: string;
_source: JsonObject;
fields: { [key: string]: [value: unknown] };
sort: [number, number];
}

Expand Down Expand Up @@ -215,6 +215,8 @@ export class InfraKibanaLogEntriesAdapter implements LogEntriesAdapter {
values: [id],
},
},
fields: ['*'],
_source: false,
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ const serializeValue = (value: any): string => {
}
return `${value}`;
};
export const convertESFieldsToLogItemFields = (fields: {
[field: string]: [value: unknown];
}): LogEntriesItemField[] => {
return Object.keys(fields).map((field) => ({ field, value: serializeValue(fields[field][0]) }));
};

export const convertDocumentSourceToLogItemFields = (
source: JsonObject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
SavedSourceConfigurationFieldColumnRuntimeType,
} from '../../sources';
import { getBuiltinRules } from './builtin_rules';
import { convertDocumentSourceToLogItemFields } from './convert_document_source_to_log_item_fields';
import { convertESFieldsToLogItemFields } from './convert_document_source_to_log_item_fields';
import {
CompiledLogMessageFormattingRule,
Fields,
Expand Down Expand Up @@ -264,7 +264,7 @@ export class InfraLogEntriesDomain {
tiebreaker: document.sort[1],
},
fields: sortBy(
[...defaultFields, ...convertDocumentSourceToLogItemFields(document._source)],
[...defaultFields, ...convertESFieldsToLogItemFields(document.fields)],
'field'
),
};
Expand Down Expand Up @@ -313,7 +313,7 @@ export class InfraLogEntriesDomain {
interface LogItemHit {
_index: string;
_id: string;
_source: JsonObject;
fields: { [field: string]: [value: unknown] };
sort: [number, number];
}

Expand Down

0 comments on commit 528c82a

Please sign in to comment.