-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[ML] Adding filebeat config to file dataviz #58152
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
Merged
jgowdyelastic
merged 10 commits into
elastic:master
from
jgowdyelastic:adding-filebeat-config-to-file-dataviz
Feb 25, 2020
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d61564d
[ML] Adding filebeat config to file dataviz
jgowdyelastic 7c2d51a
adding extra help text
jgowdyelastic 8ba2cb6
removing commented out code
jgowdyelastic a14d95d
adding extra blank line to processors section
jgowdyelastic f4d37ff
cleaning up types
jgowdyelastic a58c891
moving hosts line out of function
jgowdyelastic 8ab3b4d
typo in config text
jgowdyelastic 96de6a2
updating config based on review
jgowdyelastic aa37f4e
tiny refactor
jgowdyelastic 91ad89d
translating paths text
jgowdyelastic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
x-pack/legacy/plugins/ml/common/types/file_datavisualizer.ts
This file contains hidden or 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,31 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| export interface FindFileStructureResponse { | ||
| charset: string; | ||
| has_header_row: boolean; | ||
| has_byte_order_marker: boolean; | ||
| format: string; | ||
| field_stats: { | ||
| [fieldName: string]: { | ||
| count: number; | ||
| cardinality: number; | ||
| top_hits: Array<{ count: number; value: any }>; | ||
| }; | ||
| }; | ||
| sample_start: string; | ||
| num_messages_analyzed: number; | ||
| mappings: { | ||
| [fieldName: string]: { | ||
| type: string; | ||
| }; | ||
| }; | ||
| quote: string; | ||
| delimiter: string; | ||
| need_client_timezone: boolean; | ||
| num_lines_analyzed: number; | ||
| column_names: string[]; | ||
| } |
This file contains hidden or 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 hidden or 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
71 changes: 71 additions & 0 deletions
71
...pplication/datavisualizer/file_based/components/filebeat_config_flyout/filebeat_config.ts
This file contains hidden or 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,71 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import { i18n } from '@kbn/i18n'; | ||
| import { FindFileStructureResponse } from '../../../../../../common/types/file_datavisualizer'; | ||
|
|
||
| export function createFilebeatConfig( | ||
| index: string, | ||
| results: FindFileStructureResponse, | ||
| ingestPipelineId: string, | ||
| username: string | null | ||
| ) { | ||
| return [ | ||
| 'filebeat.inputs:', | ||
| '- type: log', | ||
| ...getPaths(), | ||
| ...getEncoding(results), | ||
| ...getExcludeLines(results), | ||
| ...getMultiline(results), | ||
| '', | ||
| ...getProcessors(results), | ||
| 'output.elasticsearch:', | ||
| ' hosts: ["<es_url>"]', | ||
| ...getUserDetails(username), | ||
| ` index: "${index}"`, | ||
| ` pipeline: "${ingestPipelineId}"`, | ||
| '', | ||
| 'setup:', | ||
| ' template.enabled: false', | ||
| ' ilm.enabled: false', | ||
| ].join('\n'); | ||
| } | ||
|
|
||
| function getPaths() { | ||
| const txt = i18n.translate('xpack.ml.fileDatavisualizer.fileBeatConfig.paths', { | ||
| defaultMessage: 'add path to your files here', | ||
| }); | ||
| return [' paths:', ` - '<${txt}>'`]; | ||
| } | ||
|
|
||
| function getEncoding(results: any) { | ||
| return results.charset !== 'UTF-8' ? [` encoding: ${results.charset}`] : []; | ||
| } | ||
|
|
||
| function getExcludeLines(results: any) { | ||
| return results.exclude_lines_pattern !== undefined | ||
| ? [` exclude_lines: ['${results.exclude_lines_pattern.replace(/'/g, "''")}']`] | ||
| : []; | ||
| } | ||
|
|
||
| function getMultiline(results: any) { | ||
| return results.multiline_start_pattern !== undefined | ||
| ? [ | ||
| ' multiline:', | ||
| ` pattern: '${results.multiline_start_pattern.replace(/'/g, "''")}'`, | ||
| ' match: after', | ||
| ' negate: true', | ||
| ] | ||
| : []; | ||
| } | ||
|
|
||
| function getProcessors(results: any) { | ||
| return results.need_client_timezone === true ? ['processors:', '- add_locale: ~', ''] : []; | ||
| } | ||
|
|
||
| function getUserDetails(username: string | null) { | ||
| return username !== null ? [` username: "${username}"`, ' password: "<password>"'] : []; | ||
| } | ||
162 changes: 162 additions & 0 deletions
162
...on/datavisualizer/file_based/components/filebeat_config_flyout/filebeat_config_flyout.tsx
This file contains hidden or 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,162 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import React, { FC, useState, useEffect } from 'react'; | ||
| import { FormattedMessage } from '@kbn/i18n/react'; | ||
| import { | ||
| EuiFlyout, | ||
| EuiFlyoutFooter, | ||
| EuiFlexGroup, | ||
| EuiFlexItem, | ||
| EuiButton, | ||
| EuiButtonEmpty, | ||
| EuiTitle, | ||
| EuiFlyoutBody, | ||
| EuiSpacer, | ||
| EuiCodeBlock, | ||
| EuiCode, | ||
| EuiCopy, | ||
| } from '@elastic/eui'; | ||
| import { createFilebeatConfig } from './filebeat_config'; | ||
| import { useMlKibana } from '../../../../contexts/kibana'; | ||
| import { FindFileStructureResponse } from '../../../../../../common/types/file_datavisualizer'; | ||
|
|
||
| export enum EDITOR_MODE { | ||
| HIDDEN, | ||
| READONLY, | ||
| EDITABLE, | ||
| } | ||
| interface Props { | ||
| index: string; | ||
| results: FindFileStructureResponse; | ||
| indexPatternId: string; | ||
| ingestPipelineId: string; | ||
| closeFlyout(): void; | ||
| } | ||
| export const FilebeatConfigFlyout: FC<Props> = ({ | ||
| index, | ||
| results, | ||
| indexPatternId, | ||
| ingestPipelineId, | ||
| closeFlyout, | ||
| }) => { | ||
| const [fileBeatConfig, setFileBeatConfig] = useState(''); | ||
| const [username, setUsername] = useState<string | null>(null); | ||
| const { | ||
| services: { security }, | ||
| } = useMlKibana(); | ||
|
|
||
| useEffect(() => { | ||
| security.authc.getCurrentUser().then(user => { | ||
| setUsername(user.username === undefined ? null : user.username); | ||
| }); | ||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| const config = createFilebeatConfig(index, results, ingestPipelineId, username); | ||
| setFileBeatConfig(config); | ||
| }, [username]); | ||
|
|
||
| return ( | ||
| <EuiFlyout onClose={closeFlyout} hideCloseButton size={'m'}> | ||
| <EuiFlyoutBody> | ||
| <EuiFlexGroup> | ||
| <Contents value={fileBeatConfig} username={username} index={index} /> | ||
| </EuiFlexGroup> | ||
| </EuiFlyoutBody> | ||
| <EuiFlyoutFooter> | ||
| <EuiFlexGroup justifyContent="spaceBetween"> | ||
| <EuiFlexItem grow={false}> | ||
| <EuiButtonEmpty iconType="cross" onClick={closeFlyout} flush="left"> | ||
| <FormattedMessage | ||
| id="xpack.ml.fileDatavisualizer.fileBeatConfigFlyout.closeButton" | ||
| defaultMessage="Close" | ||
| /> | ||
| </EuiButtonEmpty> | ||
| </EuiFlexItem> | ||
| <EuiFlexItem grow={false}> | ||
| <EuiCopy textToCopy={fileBeatConfig}> | ||
| {copy => ( | ||
| <EuiButton onClick={copy}> | ||
| <FormattedMessage | ||
| id="xpack.ml.fileDatavisualizer.fileBeatConfigFlyout.copyButton" | ||
| defaultMessage="Copy to clipboard" | ||
| /> | ||
| </EuiButton> | ||
| )} | ||
| </EuiCopy> | ||
| </EuiFlexItem> | ||
| </EuiFlexGroup> | ||
| </EuiFlyoutFooter> | ||
| </EuiFlyout> | ||
| ); | ||
| }; | ||
|
|
||
| const Contents: FC<{ | ||
| value: string; | ||
| index: string; | ||
| username: string | null; | ||
| }> = ({ value, index, username }) => { | ||
| return ( | ||
| <EuiFlexItem> | ||
| <EuiTitle size="s"> | ||
| <h5> | ||
| <FormattedMessage | ||
| id="xpack.ml.fileDatavisualizer.resultsLinks.fileBeatConfigTitle" | ||
| defaultMessage="Filebeat configuration" | ||
| /> | ||
| </h5> | ||
| </EuiTitle> | ||
| <EuiSpacer size="s" /> | ||
| <p> | ||
| <FormattedMessage | ||
| id="xpack.ml.fileDatavisualizer.resultsLinks.fileBeatConfigTopText1" | ||
| defaultMessage="Additional data can be uploaded to the {index} index using Filebeat." | ||
| values={{ index: <EuiCode>{index}</EuiCode> }} | ||
| /> | ||
| </p> | ||
| <p> | ||
| <FormattedMessage | ||
| id="xpack.ml.fileDatavisualizer.resultsLinks.fileBeatConfigTopText2" | ||
| defaultMessage="Modify {filebeatYml} to set the connection information:" | ||
| values={{ filebeatYml: <EuiCode>filebeat.yml</EuiCode> }} | ||
| /> | ||
| </p> | ||
|
|
||
| <EuiSpacer size="s" /> | ||
|
|
||
| <EuiCodeBlock language="bash">{value}</EuiCodeBlock> | ||
|
|
||
| <EuiSpacer size="s" /> | ||
| <p> | ||
| {username === null ? ( | ||
| <FormattedMessage | ||
| id="xpack.ml.fileDatavisualizer.resultsLinks.fileBeatConfigBottomTextNoUsername" | ||
| defaultMessage="Where {esUrl} is the URL of Elasticsearch." | ||
| values={{ | ||
| esUrl: <EuiCode>{'<es_url>'}</EuiCode>, | ||
| }} | ||
| /> | ||
| ) : ( | ||
| <FormattedMessage | ||
| id="xpack.ml.fileDatavisualizer.resultsLinks.fileBeatConfigBottomText" | ||
| defaultMessage="Where {password} is the password of the {user} user, {esUrl} is the URL of Elasticsearch." | ||
| values={{ | ||
| user: <EuiCode>{username}</EuiCode>, | ||
| password: <EuiCode>{'<password>'}</EuiCode>, | ||
| esUrl: <EuiCode>{'<es_url>'}</EuiCode>, | ||
| }} | ||
| /> | ||
| )} | ||
| </p> | ||
| </EuiFlexItem> | ||
| ); | ||
| }; |
7 changes: 7 additions & 0 deletions
7
...l/public/application/datavisualizer/file_based/components/filebeat_config_flyout/index.ts
This file contains hidden or 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,7 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| export { FilebeatConfigFlyout } from './filebeat_config_flyout'; |
This file contains hidden or 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 hidden or 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
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.