-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enterprise Search] Create reusable EntSearchLogStream component (#10…
…5804) * Set up Kibana dependencies required by LogStream component - notably, `infra` and `data` - @see https://github.com/elastic/kibana/blob/master/x-pack/plugins/infra/public/components/log_stream/log_stream.stories.mdx#prerequisites - tsconfig.json note - I believe I missed kibana_react from when we previously started requiring it for KibanaPageTemplate. Because LogStream requires it for KibanaContextProvider anyway I decided to add as a reference just in case * Set up log source configuration for ent search logs @see https://github.com/elastic/kibana/blob/master/x-pack/plugins/infra/public/components/log_stream/log_stream.stories.mdx#with-a-source-configuration or, monitoring plugin also has example usage * Set up providers required by the LogStream component @see https://github.com/elastic/kibana/blob/master/x-pack/plugins/infra/public/components/log_stream/log_stream.stories.mdx#prerequisites Note: there's some overlap in KibanaContextProvider with KibanaLogic that may be worth investigating/DRYing out in the future * Create reusable EntSearchLogStream component - light wrapper over LogStream with certain prepopulated defaults + Update LogStreamProps from infra team to be exported publicly for reuse (eslint will error otherwise) * Fix bad type export - thanks @afgomez!! * Fix failing security_only nav_links test - which was caused by `spaces` being required by infra but optional for our plugin. I moved `spaces` to required by `enterprise_search for clarity. - I'm still not sure I actually fixed the nav_links test correctly. I have almost no memory of adding those lines 12 months ago 🙈 * Fix spaces typing - remove `?` notation now that it's a required and non-optional plugin + reorder required plugins slightly Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
a1f097e
commit bc4928f
Showing
12 changed files
with
170 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/enterprise_search/public/applications/shared/log_stream/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export { EntSearchLogStream } from './log_stream'; |
75 changes: 75 additions & 0 deletions
75
x-pack/plugins/enterprise_search/public/applications/shared/log_stream/log_stream.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { shallow } from 'enzyme'; | ||
|
||
import { LogStream } from '../../../../../infra/public'; | ||
|
||
import { EntSearchLogStream } from './'; | ||
|
||
describe('EntSearchLogStream', () => { | ||
const mockDateNow = jest.spyOn(global.Date, 'now').mockReturnValue(160000000); | ||
|
||
describe('renders with default props', () => { | ||
const wrapper = shallow(<EntSearchLogStream />); | ||
|
||
it('renders a LogStream component', () => { | ||
expect(wrapper.type()).toEqual(LogStream); | ||
}); | ||
|
||
it('renders with the enterprise search log source ID', () => { | ||
expect(wrapper.prop('sourceId')).toEqual('ent-search-logs'); | ||
}); | ||
|
||
it('renders with a default last-24-hours timestamp if no timestamp is passed', () => { | ||
expect(wrapper.prop('startTimestamp')).toEqual(73600000); | ||
expect(wrapper.prop('endTimestamp')).toEqual(160000000); | ||
}); | ||
}); | ||
|
||
describe('renders custom props', () => { | ||
it('overrides the default props', () => { | ||
const wrapper = shallow( | ||
<EntSearchLogStream sourceId="test" startTimestamp={1} endTimestamp={2} /> | ||
); | ||
|
||
expect(wrapper.prop('sourceId')).toEqual('test'); | ||
expect(wrapper.prop('startTimestamp')).toEqual(1); | ||
expect(wrapper.prop('endTimestamp')).toEqual(2); | ||
}); | ||
|
||
it('allows passing a custom hoursAgo that modifies the default start timestamp', () => { | ||
const wrapper = shallow(<EntSearchLogStream hoursAgo={1} />); | ||
|
||
expect(wrapper.prop('startTimestamp')).toEqual(156400000); | ||
expect(wrapper.prop('endTimestamp')).toEqual(160000000); | ||
}); | ||
|
||
it('allows passing any prop that the LogStream component takes', () => { | ||
const wrapper = shallow( | ||
<EntSearchLogStream | ||
height={500} | ||
highlight="some-log-id" | ||
columns={[ | ||
{ type: 'timestamp', header: 'Timestamp' }, | ||
{ type: 'field', field: 'log.level', header: 'Log level', width: 300 }, | ||
]} | ||
filters={[]} | ||
/> | ||
); | ||
|
||
expect(wrapper.prop('height')).toEqual(500); | ||
expect(wrapper.prop('highlight')).toEqual('some-log-id'); | ||
expect(wrapper.prop('columns')).toBeTruthy(); | ||
expect(wrapper.prop('filters')).toEqual([]); | ||
}); | ||
}); | ||
|
||
afterAll(() => mockDateNow.mockRestore()); | ||
}); |
47 changes: 47 additions & 0 deletions
47
x-pack/plugins/enterprise_search/public/applications/shared/log_stream/log_stream.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { LogStream, LogStreamProps } from '../../../../../infra/public'; | ||
|
||
import { LOGS_SOURCE_ID } from '../../../../common/constants'; | ||
|
||
/* | ||
* EnterpriseSearchLogStream is a light wrapper on top of infra's embeddable LogStream component. | ||
* It prepopulates our log source ID (set in server/plugin.ts) and sets a basic 24-hours-ago | ||
* default for timestamps. All other props get passed as-is to the underlying LogStream. | ||
* | ||
* Documentation links for reference: | ||
* - https://github.com/elastic/kibana/blob/master/x-pack/plugins/infra/public/components/log_stream/log_stream.stories.mdx | ||
* - Run `yarn storybook infra` for live docs | ||
*/ | ||
|
||
interface Props extends Omit<LogStreamProps, 'startTimestamp' | 'endTimestamp'> { | ||
startTimestamp?: LogStreamProps['startTimestamp']; | ||
endTimestamp?: LogStreamProps['endTimestamp']; | ||
hoursAgo?: number; | ||
} | ||
|
||
export const EntSearchLogStream: React.FC<Props> = ({ | ||
startTimestamp, | ||
endTimestamp, | ||
hoursAgo = 24, | ||
...props | ||
}) => { | ||
if (!endTimestamp) endTimestamp = Date.now(); | ||
if (!startTimestamp) startTimestamp = endTimestamp - hoursAgo * 60 * 60 * 1000; | ||
|
||
return ( | ||
<LogStream | ||
sourceId={LOGS_SOURCE_ID} | ||
startTimestamp={startTimestamp} | ||
endTimestamp={endTimestamp} | ||
{...props} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters