Skip to content

Commit

Permalink
Merge branch 'main' into security-solution-remove-saved-object-deps
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko authored Apr 12, 2024
2 parents fa733f2 + 73d8533 commit d65bd15
Show file tree
Hide file tree
Showing 43 changed files with 487 additions and 98 deletions.
2 changes: 2 additions & 0 deletions config/serverless.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ xpack.ml.ad.enabled: false
xpack.ml.dfa.enabled: false
xpack.ml.nlp.enabled: true
xpack.ml.compatibleModuleType: 'search'

data_visualizer.resultLinks.fileBeat.enabled: false
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ class TutorialDirectoryUi extends React.Component {
}),
content: <SampleDataTab />,
},
...extraTabs.map(({ id, name, component: Component }) => ({
...extraTabs.map(({ id, name, getComponent }) => ({
id,
name,
content: <Component />,
content: getComponent(),
})),
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ describe('AddDataService', () => {
test('allows multiple register directory header link calls', () => {
const setup = new AddDataService().setup();
expect(() => {
setup.registerAddDataTab({ id: 'abc', name: 'a b c', component: () => <a>123</a> });
setup.registerAddDataTab({ id: 'def', name: 'a b c', component: () => <a>456</a> });
setup.registerAddDataTab({ id: 'abc', name: 'a b c', getComponent: () => <a>123</a> });
setup.registerAddDataTab({ id: 'def', name: 'a b c', getComponent: () => <a>456</a> });
}).not.toThrow();
});

test('throws when same directory header link is registered twice', () => {
const setup = new AddDataService().setup();
expect(() => {
setup.registerAddDataTab({ id: 'abc', name: 'a b c', component: () => <a>123</a> });
setup.registerAddDataTab({ id: 'abc', name: 'a b c', component: () => <a>456</a> });
setup.registerAddDataTab({ id: 'abc', name: 'a b c', getComponent: () => <a>123</a> });
setup.registerAddDataTab({ id: 'abc', name: 'a b c', getComponent: () => <a>456</a> });
}).toThrow();
});
});
Expand All @@ -38,8 +38,8 @@ describe('AddDataService', () => {
const service = new AddDataService();
const setup = service.setup();
const links = [
{ id: 'abc', name: 'a b c', component: () => <a>123</a> },
{ id: 'def', name: 'a b c', component: () => <a>456</a> },
{ id: 'abc', name: 'a b c', getComponent: () => <a>123</a> },
{ id: 'def', name: 'a b c', getComponent: () => <a>456</a> },
];
setup.registerAddDataTab(links[0]);
setup.registerAddDataTab(links[1]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
* Side Public License, v 1.
*/

import React from 'react';

/** @public */
export interface AddDataTab {
id: string;
name: string;
component: React.FC;
getComponent: () => JSX.Element;
}

export class AddDataService {
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/vis_types/timelion/server/lib/load_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

import _ from 'lodash';
import globby from 'globby';
import path from 'path';
import normalizePath from 'normalize-path';
import processFunctionDefinition from './process_function_definition';

export default function (directory) {
Expand All @@ -20,7 +18,7 @@ export default function (directory) {
// Get a list of all files and use the filename as the object key
const files = _.map(
globby
.sync(normalizePath(path.resolve(__dirname, '../' + directory + '/*.js')))
.sync('../' + directory + '/*.js', { cwd: __dirname })
.filter((filename) => !filename.includes('.test')),
function (file) {
const name = file.substring(file.lastIndexOf('/') + 1, file.lastIndexOf('.'));
Expand All @@ -30,7 +28,9 @@ export default function (directory) {

// Get a list of all directories with an index.js, use the directory name as the key in the object
const directories = _.chain(
globby.sync(normalizePath(path.resolve(__dirname, '../' + directory + '/*/index.js')))
globby.sync('../' + directory + '/*/index.js', {
cwd: __dirname,
})
)
.map(function (file) {
const parts = file.split('/');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
'data.search.sessions.maxUpdateRetries (number)',
'data.search.sessions.notTouchedTimeout (duration)',
'data_views.scriptedFieldsEnabled (any)', // It's a boolean (any because schema.conditional)
'data_visualizer.resultLinks.fileBeat.enabled (boolean)',
'dev_tools.deeplinks.navLinkStatus (string)',
'enterpriseSearch.canDeployEntSearch (boolean)',
'enterpriseSearch.host (string)',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export type SetupFormat = typeof AWS_SETUP_FORMAT.CLOUD_FORMATION | typeof AWS_S
export const AWS_SETUP_FORMAT = {
CLOUD_FORMATION: 'cloud_formation',
MANUAL: 'manual',
};
} as const;

export const AWS_CREDENTIALS_TYPE = {
ASSUME_ROLE: 'assume_role',
Expand All @@ -53,6 +53,7 @@ export const AWS_CREDENTIALS_TYPE = {
SHARED_CREDENTIALS: 'shared_credentials',
CLOUD_FORMATION: 'cloud_formation',
} as const;

export const AWSSetupInfoContent = ({ info }: AWSSetupInfoContentProps) => {
return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export type SetupFormat = typeof AZURE_SETUP_FORMAT.ARM_TEMPLATE | typeof AZURE_
export const AZURE_SETUP_FORMAT = {
ARM_TEMPLATE: 'arm_template',
MANUAL: 'manual',
};
} as const;

export const AZURE_CREDENTIALS_TYPE = {
ARM_TEMPLATE: 'arm_template',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@ import {
export const GCP_SETUP_ACCESS = {
CLOUD_SHELL: 'google_cloud_shell',
MANUAL: 'manual',
};
} as const;

export const GCP_CREDENTIALS_TYPE = {
CREDENTIALS_FILE: 'credentials-file',
CREDENTIALS_JSON: 'credentials-json',
CREDENTIALS_NONE: 'credentials-none',
};
} as const;

type SetupFormatGCP = typeof GCP_SETUP_ACCESS.CLOUD_SHELL | typeof GCP_SETUP_ACCESS.MANUAL;

export const GCPSetupInfoContent = () => (
<>
<EuiHorizontalRule margin="xl" />
Expand Down
17 changes: 17 additions & 0 deletions x-pack/plugins/data_visualizer/common/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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 interface ResultLinks {
fileBeat?: {
enabled: boolean;
};
}
export type ResultLink = keyof ResultLinks;

export interface ConfigSchema {
resultLinks?: ResultLinks;
}
35 changes: 25 additions & 10 deletions x-pack/plugins/data_visualizer/public/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,39 @@
* 2.0.
*/

import type { ResultLinks } from '../../common/app';
import { lazyLoadModules } from '../lazy_load_bundle';
import type {
DataDriftSpec,
FileDataVisualizerSpec,
IndexDataVisualizerSpec,
} from '../application';

export async function getFileDataVisualizerComponent(): Promise<() => FileDataVisualizerSpec> {
const modules = await lazyLoadModules();
return () => modules.FileDataVisualizer;
export interface SpecWithLinks<T> {
resultLinks: ResultLinks;
component: T;
}

export async function getIndexDataVisualizerComponent(): Promise<() => IndexDataVisualizerSpec> {
const modules = await lazyLoadModules();
return () => modules.IndexDataVisualizer;
}
export function getComponents(resultLinks: ResultLinks) {
async function getFileDataVisualizerComponent(): Promise<
() => SpecWithLinks<FileDataVisualizerSpec>
> {
const modules = await lazyLoadModules(resultLinks);
return () => ({ component: modules.FileDataVisualizer, resultLinks });
}

async function getIndexDataVisualizerComponent(): Promise<() => IndexDataVisualizerSpec> {
const modules = await lazyLoadModules(resultLinks);
return () => modules.IndexDataVisualizer;
}

export async function getDataDriftComponent(): Promise<() => DataDriftSpec> {
const modules = await lazyLoadModules();
return () => modules.DataDrift;
async function getDataDriftComponent(): Promise<() => DataDriftSpec> {
const modules = await lazyLoadModules(resultLinks);
return () => modules.DataDrift;
}
return {
getFileDataVisualizerComponent,
getIndexDataVisualizerComponent,
getDataDriftComponent,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type { FindFileStructureResponse } from '@kbn/file-upload-plugin/common';
import type { FileUploadPluginStart } from '@kbn/file-upload-plugin/public';
import { flatten } from 'lodash';
import { isDefined } from '@kbn/ml-is-defined';
import type { ResultLinks } from '../../../../../common/app';
import type { LinkCardProps } from '../link_card/link_card';
import { useDataVisualizerKibana } from '../../../kibana_context';

Expand Down Expand Up @@ -50,6 +51,7 @@ interface Props {
createDataView: boolean;
showFilebeatFlyout(): void;
getAdditionalLinks?: GetAdditionalLinks;
resultLinks?: ResultLinks;
}

interface GlobalState {
Expand All @@ -67,6 +69,7 @@ export const ResultsLinks: FC<Props> = ({
createDataView,
showFilebeatFlyout,
getAdditionalLinks,
resultLinks,
}) => {
const {
services: {
Expand Down Expand Up @@ -257,21 +260,25 @@ export const ResultsLinks: FC<Props> = ({
/>
</EuiFlexItem>
)}
<EuiFlexItem>
<EuiCard
hasBorder
icon={<EuiIcon size="xxl" type={`filebeatApp`} />}
data-test-subj="fileDataVisFilebeatConfigLink"
title={
<FormattedMessage
id="xpack.dataVisualizer.file.resultsLinks.fileBeatConfig"
defaultMessage="Create Filebeat configuration"
/>
}
description=""
onClick={showFilebeatFlyout}
/>
</EuiFlexItem>

{resultLinks?.fileBeat?.enabled === false ? null : (
<EuiFlexItem>
<EuiCard
hasBorder
icon={<EuiIcon size="xxl" type={`filebeatApp`} />}
data-test-subj="fileDataVisFilebeatConfigLink"
title={
<FormattedMessage
id="xpack.dataVisualizer.file.resultsLinks.fileBeatConfig"
defaultMessage="Create Filebeat configuration"
/>
}
description=""
onClick={showFilebeatFlyout}
/>
</EuiFlexItem>
)}

{Array.isArray(asyncHrefCards) &&
asyncHrefCards.map((link) => (
<EuiFlexItem key={link.title}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const WelcomeContent: FC<Props> = ({ hasPermissionToImport }) => {
<h1>
<FormattedMessage
id="xpack.dataVisualizer.file.welcomeContent.visualizeDataFromLogFileTitle"
defaultMessage="Visualize data from a log file"
defaultMessage="Upload data from a file"
/>
</h1>
</EuiTitle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ export const FileContents: FC<Props> = ({ data, format, numberOfLines, semiStruc
) : (
<>
{highlightedLines.map((line, i) => (
<>
<React.Fragment key={`line-${i}`}>
{line}
{i === highlightedLines.length - 1 ? null : <EuiHorizontalRule margin="s" />}
</>
</React.Fragment>
))}
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ export function useGrokHighlighter() {

return lines.map((line) => {
const formattedWords: JSX.Element[] = [];
for (const { word, field } of line) {
for (let j = 0; j < line.length; j++) {
const { word, field } = line[j];
const key = `word-${j}`;
if (field) {
formattedWords.push(<FieldBadge type={field.type} value={word} name={field.name} />);
formattedWords.push(
<FieldBadge type={field.type} value={word} name={field.name} key={key} />
);
} else {
formattedWords.push(<span>{word}</span>);
formattedWords.push(<span key={key}>{word}</span>);
}
}
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ export class FileDataVisualizerView extends Component {
dataStart={this.props.dataStart}
fileUpload={this.props.fileUpload}
getAdditionalLinks={this.props.getAdditionalLinks}
resultLinks={this.props.resultLinks}
capabilities={this.props.capabilities}
mode={mode}
onChangeMode={this.changeMode}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ export class ImportView extends Component {
createDataView={createDataView}
showFilebeatFlyout={this.showFilebeatFlyout}
getAdditionalLinks={this.props.getAdditionalLinks ?? []}
resultLinks={this.props.resultLinks}
/>

{isFilebeatFlyoutVisible && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ import '../_index.scss';
import type { FC } from 'react';
import React from 'react';
import { KibanaContextProvider, KibanaThemeProvider } from '@kbn/kibana-react-plugin/public';
import type { ResultLinks } from '../../../common/app';
import { getCoreStart, getPluginsStart } from '../../kibana_services';

// @ts-ignore
import { FileDataVisualizerView } from './components/file_data_visualizer_view';
import type { GetAdditionalLinks } from '../common/components/results_links';

interface Props {
export interface Props {
resultLinks?: ResultLinks;
getAdditionalLinks?: GetAdditionalLinks;
}

export type FileDataVisualizerSpec = typeof FileDataVisualizer;
export const FileDataVisualizer: FC<Props> = ({ getAdditionalLinks }) => {

export const FileDataVisualizer: FC<Props> = ({ getAdditionalLinks, resultLinks }) => {
const coreStart = getCoreStart();
const { data, maps, embeddable, discover, share, security, fileUpload, cloud, fieldFormats } =
getPluginsStart();
Expand Down Expand Up @@ -48,6 +51,7 @@ export const FileDataVisualizer: FC<Props> = ({ getAdditionalLinks }) => {
http={coreStart.http}
fileUpload={fileUpload}
getAdditionalLinks={getAdditionalLinks}
resultLinks={resultLinks}
capabilities={coreStart.application.capabilities}
/>
</CloudContext>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ const DataVisualizerStateContextProvider: FC<DataVisualizerStateContextProviderP
);
};

interface Props {
export interface Props {
getAdditionalLinks?: GetAdditionalLinks;
showFrozenDataTierChoice?: boolean;
esql?: boolean;
Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/data_visualizer/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
* 2.0.
*/

import type { PluginInitializerContext } from '@kbn/core/public';
import { DataVisualizerPlugin } from './plugin';

export function plugin() {
return new DataVisualizerPlugin();
export function plugin(initializerContext: PluginInitializerContext) {
return new DataVisualizerPlugin(initializerContext);
}

export type { DataVisualizerPluginStart } from './plugin';
Expand Down
Loading

0 comments on commit d65bd15

Please sign in to comment.