Skip to content

Commit 008479f

Browse files
[ml] migrate file_data_visualizer/import route to file_upload plugin (#89640) (#90075)
* migrate file_upload plugin to maps_file_upload * update plugins list * migrate ml import endpoint * migrate ml telemetry to file_upload plugin * add fileUpload plugin to ml * add TS project * update ML to use file_upload endpoint * move types to file_upload plugin * ignore error * clean up * i18n clean-up * remove schemas from ml * remove usageCollection from ml * node scripts/build_plugin_list_docs * update telemety collector * revert changes to ingestPipeline schema * change name of TELEMETRY_DOC_ID to unique value * remove ImportFile from ml/server/routes/apidoc.json * fix typo in x=pack/tsconfig.json Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> # Conflicts: # src/plugins/telemetry/schema/oss_plugins.json # x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json
1 parent 5429a45 commit 008479f

File tree

41 files changed

+324
-214
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+324
-214
lines changed

docs/developer/plugin-list.asciidoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@ and actions.
366366
|The features plugin enhance Kibana with a per-feature privilege system.
367367
368368
369+
|{kib-repo}blob/{branch}/x-pack/plugins/file_upload[fileUpload]
370+
|WARNING: Missing README.
371+
372+
369373
|{kib-repo}blob/{branch}/x-pack/plugins/fleet/README.md[fleet]
370374
|Fleet needs to have Elasticsearch API keys enabled, and also to have TLS enabled on kibana, (if you want to run Kibana without TLS you can provide the following config flag --xpack.fleet.agents.tlsCheckDisabled=false)
371375
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
export * from './constants';
8+
export * from './types';
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
export interface ImportResponse {
8+
success: boolean;
9+
id: string;
10+
index?: string;
11+
pipelineId?: string;
12+
docCount: number;
13+
failures: ImportFailure[];
14+
error?: any;
15+
ingestError?: boolean;
16+
}
17+
18+
export interface ImportFailure {
19+
item: number;
20+
reason: string;
21+
doc: ImportDoc;
22+
}
23+
24+
export interface Doc {
25+
message: string;
26+
}
27+
28+
export type ImportDoc = Doc | string;
29+
30+
export interface Settings {
31+
pipeline?: string;
32+
index: string;
33+
body: any[];
34+
[key: string]: any;
35+
}
36+
37+
export interface Mappings {
38+
_meta?: {
39+
created_by: string;
40+
};
41+
properties: {
42+
[key: string]: any;
43+
};
44+
}
45+
46+
export interface IngestPipelineWrapper {
47+
id: string;
48+
pipeline: IngestPipeline;
49+
}
50+
51+
export interface IngestPipeline {
52+
description: string;
53+
processors: any[];
54+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
module.exports = {
8+
preset: '@kbn/test',
9+
rootDir: '../../..',
10+
roots: ['<rootDir>/x-pack/plugins/file_upload'],
11+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "fileUpload",
3+
"version": "8.0.0",
4+
"kibanaVersion": "kibana",
5+
"server": true,
6+
"ui": false,
7+
"requiredPlugins": ["usageCollection"]
8+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { boomify, isBoom } from '@hapi/boom';
8+
import { ResponseError, CustomHttpResponseOptions } from 'kibana/server';
9+
10+
export function wrapError(error: any): CustomHttpResponseOptions<ResponseError> {
11+
const boom = isBoom(error)
12+
? error
13+
: boomify(error, { statusCode: error.status ?? error.statusCode });
14+
const statusCode = boom.output.statusCode;
15+
return {
16+
body: {
17+
message: boom,
18+
...(statusCode !== 500 && error.body ? { attributes: { body: error.body } } : {}),
19+
},
20+
headers: boom.output.headers as { [key: string]: string },
21+
statusCode,
22+
};
23+
}

x-pack/plugins/ml/server/models/file_data_visualizer/import_data.ts renamed to x-pack/plugins/file_upload/server/import_data.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@
55
*/
66

77
import { IScopedClusterClient } from 'kibana/server';
8-
import { INDEX_META_DATA_CREATED_BY } from '../../../common/constants/file_datavisualizer';
8+
import { INDEX_META_DATA_CREATED_BY } from '../common/constants';
99
import {
1010
ImportResponse,
1111
ImportFailure,
1212
Settings,
1313
Mappings,
1414
IngestPipelineWrapper,
15-
} from '../../../common/types/file_datavisualizer';
16-
import { InputData } from './file_data_visualizer';
15+
} from '../common';
16+
17+
export type InputData = any[];
1718

1819
export function importDataProvider({ asCurrentUser }: IScopedClusterClient) {
1920
async function importData(
20-
id: string,
21+
id: string | undefined,
2122
index: string,
2223
settings: Settings,
2324
mappings: Mappings,
@@ -77,7 +78,7 @@ export function importDataProvider({ asCurrentUser }: IScopedClusterClient) {
7778
} catch (error) {
7879
return {
7980
success: false,
80-
id,
81+
id: id!,
8182
index: createdIndex,
8283
pipelineId: createdPipelineId,
8384
error: error.body !== undefined ? error.body : error,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { FileUploadPlugin } from './plugin';
8+
9+
export const plugin = () => new FileUploadPlugin();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { CoreSetup, CoreStart, Plugin } from 'src/core/server';
8+
import { fileUploadRoutes } from './routes';
9+
import { initFileUploadTelemetry } from './telemetry';
10+
import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/server';
11+
12+
interface SetupDeps {
13+
usageCollection: UsageCollectionSetup;
14+
}
15+
16+
export class FileUploadPlugin implements Plugin {
17+
async setup(coreSetup: CoreSetup, plugins: SetupDeps) {
18+
fileUploadRoutes(coreSetup.http.createRouter());
19+
20+
initFileUploadTelemetry(coreSetup, plugins.usageCollection);
21+
}
22+
23+
start(core: CoreStart) {}
24+
}

0 commit comments

Comments
 (0)