Skip to content

Commit

Permalink
Merge branch 'master' into remove-matrix-support
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Jan 23, 2020
2 parents 8488b4b + cda6b13 commit aa547ee
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 64 deletions.
6 changes: 2 additions & 4 deletions x-pack/legacy/plugins/lens/server/routes/existing_fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,15 @@ async function fetchIndexPatternStats({
match_all: {},
};
}
const viableFields = fields.filter(
f => !f.isScript && !f.isAlias && !metaFields.includes(f.name)
);
const scriptedFields = fields.filter(f => f.isScript);

const result = await client.callAsCurrentUser('search', {
index,
body: {
size: SAMPLE_SIZE,
_source: viableFields.map(f => f.name),
query,
// _source is required because we are also providing script fields.
_source: '*',
script_fields: scriptedFields.reduce((acc, field) => {
acc[field.name] = {
script: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface Props {
browserFields: BrowserFields;
columnHeaders: ColumnHeader[];
columnRenderers: ColumnRenderer[];
containerElementRef: HTMLDivElement;
data: TimelineItem[];
eventIdToNoteIds: Readonly<Record<string, string[]>>;
getNotesByIds: (noteIds: string[]) => Note[];
Expand All @@ -53,61 +54,62 @@ interface Props {
// Passing the styles directly to the component because the width is
// being calculated and is recommended by Styled Components for performance
// https://github.com/styled-components/styled-components/issues/134#issuecomment-312415291
export const Events = React.memo<Props>(
({
actionsColumnWidth,
addNoteToEvent,
browserFields,
columnHeaders,
columnRenderers,
data,
eventIdToNoteIds,
getNotesByIds,
id,
isEventViewer = false,
loadingEventIds,
onColumnResized,
onPinEvent,
onRowSelected,
onUpdateColumns,
onUnPinEvent,
pinnedEventIds,
rowRenderers,
selectedEventIds,
showCheckboxes,
toggleColumn,
updateNote,
}) => (
<EventsTbody data-test-subj="events">
{data.map((event, i) => (
<StatefulEvent
actionsColumnWidth={actionsColumnWidth}
addNoteToEvent={addNoteToEvent}
browserFields={browserFields}
columnHeaders={columnHeaders}
columnRenderers={columnRenderers}
event={event}
eventIdToNoteIds={eventIdToNoteIds}
getNotesByIds={getNotesByIds}
isEventPinned={eventIsPinned({ eventId: event._id, pinnedEventIds })}
isEventViewer={isEventViewer}
key={event._id}
loadingEventIds={loadingEventIds}
maxDelay={maxDelay(i)}
onColumnResized={onColumnResized}
onPinEvent={onPinEvent}
onRowSelected={onRowSelected}
onUnPinEvent={onUnPinEvent}
onUpdateColumns={onUpdateColumns}
rowRenderers={rowRenderers}
selectedEventIds={selectedEventIds}
showCheckboxes={showCheckboxes}
timelineId={id}
toggleColumn={toggleColumn}
updateNote={updateNote}
/>
))}
</EventsTbody>
)
const EventsComponent: React.FC<Props> = ({
actionsColumnWidth,
addNoteToEvent,
browserFields,
columnHeaders,
columnRenderers,
containerElementRef,
data,
eventIdToNoteIds,
getNotesByIds,
id,
isEventViewer = false,
loadingEventIds,
onColumnResized,
onPinEvent,
onRowSelected,
onUpdateColumns,
onUnPinEvent,
pinnedEventIds,
rowRenderers,
selectedEventIds,
showCheckboxes,
toggleColumn,
updateNote,
}) => (
<EventsTbody data-test-subj="events">
{data.map((event, i) => (
<StatefulEvent
containerElementRef={containerElementRef}
actionsColumnWidth={actionsColumnWidth}
addNoteToEvent={addNoteToEvent}
browserFields={browserFields}
columnHeaders={columnHeaders}
columnRenderers={columnRenderers}
event={event}
eventIdToNoteIds={eventIdToNoteIds}
getNotesByIds={getNotesByIds}
isEventPinned={eventIsPinned({ eventId: event._id, pinnedEventIds })}
isEventViewer={isEventViewer}
key={event._id}
loadingEventIds={loadingEventIds}
maxDelay={maxDelay(i)}
onColumnResized={onColumnResized}
onPinEvent={onPinEvent}
onRowSelected={onRowSelected}
onUnPinEvent={onUnPinEvent}
onUpdateColumns={onUpdateColumns}
rowRenderers={rowRenderers}
selectedEventIds={selectedEventIds}
showCheckboxes={showCheckboxes}
timelineId={id}
toggleColumn={toggleColumn}
updateNote={updateNote}
/>
))}
</EventsTbody>
);
Events.displayName = 'Events';

export const Events = React.memo(EventsComponent);
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { StatefulEventChild } from './stateful_event_child';

interface Props {
actionsColumnWidth: number;
containerElementRef: HTMLDivElement;
addNoteToEvent: AddNoteToEvent;
browserFields: BrowserFields;
columnHeaders: ColumnHeader[];
Expand Down Expand Up @@ -115,6 +116,7 @@ const StatefulEventComponent: React.FC<Props> = ({
actionsColumnWidth,
addNoteToEvent,
browserFields,
containerElementRef,
columnHeaders,
columnRenderers,
event,
Expand Down Expand Up @@ -201,6 +203,7 @@ const StatefulEventComponent: React.FC<Props> = ({
<VisibilitySensor
partialVisibility={true}
scrollCheck={true}
containment={containerElementRef}
offset={{ top: TOP_OFFSET, bottom: BOTTOM_OFFSET }}
>
{({ isVisible }) => {
Expand Down Expand Up @@ -279,7 +282,7 @@ const StatefulEventComponent: React.FC<Props> = ({
} else {
// Height place holder for visibility detection as well as re-rendering sections.
const height =
divElement.current != null
divElement.current != null && divElement.current.clientHeight
? `${divElement.current.clientHeight}px`
: DEFAULT_ROW_HEIGHT;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { useMemo } from 'react';
import React, { useMemo, useRef } from 'react';

import { BrowserFields } from '../../../containers/source';
import { TimelineItem, TimelineNonEcsData } from '../../../graphql/types';
Expand Down Expand Up @@ -95,6 +95,7 @@ export const Body = React.memo<BodyProps>(
toggleColumn,
updateNote,
}) => {
const containerElementRef = useRef<HTMLDivElement>(null);
const timelineTypeContext = useTimelineTypeContext();
const additionalActionWidth =
timelineTypeContext.timelineActions?.reduce((acc, v) => acc + v.width, 0) ?? 0;
Expand All @@ -112,7 +113,7 @@ export const Body = React.memo<BodyProps>(

return (
<>
<TimelineBody data-test-subj="timeline-body" bodyHeight={height}>
<TimelineBody data-test-subj="timeline-body" bodyHeight={height} ref={containerElementRef}>
<EventsTable
data-test-subj="events-table"
// Passing the styles directly to the component because the width is being calculated and is recommended by Styled Components for performance: https://github.com/styled-components/styled-components/issues/134#issuecomment-312415291
Expand All @@ -138,6 +139,7 @@ export const Body = React.memo<BodyProps>(
/>

<Events
containerElementRef={containerElementRef.current!}
actionsColumnWidth={actionsColumnWidth}
addNoteToEvent={addNoteToEvent}
browserFields={browserFields}
Expand Down
49 changes: 49 additions & 0 deletions x-pack/test/api_integration/apis/lens/existing_fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,41 @@ const fieldsWithData = [
'relatedContent.url.raw',
];

const metricBeatData = [
'@timestamp',
'agent.ephemeral_id',
'agent.hostname',
'agent.id',
'agent.type',
'agent.version',
'ecs.version',
'event.dataset',
'event.duration',
'event.module',
'host.architecture',
'host.hostname',
'host.id',
'host.name',
'host.os.build',
'host.os.family',
'host.os.kernel',
'host.os.name',
'host.os.platform',
'host.os.version',
'metricset.name',
'service.type',
'system.cpu.cores',
'system.cpu.idle.pct',
'system.cpu.iowait.pct',
'system.cpu.irq.pct',
'system.cpu.nice.pct',
'system.cpu.softirq.pct',
'system.cpu.steal.pct',
'system.cpu.system.pct',
'system.cpu.total.pct',
'system.cpu.user.pct',
];

// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext) => {
const esArchiver = getService('esArchiver');
Expand Down Expand Up @@ -124,6 +159,20 @@ export default ({ getService }: FtrProviderContext) => {
expect(body.existingFieldNames.sort()).to.eql(fieldsWithData.sort());
});

it('should succeed for thousands of fields', async () => {
const { body } = await supertest
.get(
`/api/lens/existing_fields/${encodeURIComponent(
'metricbeat-*'
)}?fromDate=${TEST_START_TIME}&toDate=${TEST_END_TIME}`
)
.set(COMMON_HEADERS)
.expect(200);

expect(body.indexPatternTitle).to.eql('metricbeat-*');
expect(body.existingFieldNames.sort()).to.eql(metricBeatData.sort());
});

it('should throw a 404 for a non-existent index', async () => {
await supertest
.get(
Expand Down
123 changes: 123 additions & 0 deletions x-pack/test/functional/es_archives/visualize/default/data.json

Large diffs are not rendered by default.

0 comments on commit aa547ee

Please sign in to comment.