-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ml] migrate file_data_visualizer/import route to file_upload plugin (#…
…89640) * 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>
- Loading branch information
1 parent
047dd29
commit d601090
Showing
42 changed files
with
330 additions
and
220 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
File renamed without changes.
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; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export * from './constants'; | ||
export * from './types'; |
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,54 @@ | ||
/* | ||
* 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 ImportResponse { | ||
success: boolean; | ||
id: string; | ||
index?: string; | ||
pipelineId?: string; | ||
docCount: number; | ||
failures: ImportFailure[]; | ||
error?: any; | ||
ingestError?: boolean; | ||
} | ||
|
||
export interface ImportFailure { | ||
item: number; | ||
reason: string; | ||
doc: ImportDoc; | ||
} | ||
|
||
export interface Doc { | ||
message: string; | ||
} | ||
|
||
export type ImportDoc = Doc | string; | ||
|
||
export interface Settings { | ||
pipeline?: string; | ||
index: string; | ||
body: any[]; | ||
[key: string]: any; | ||
} | ||
|
||
export interface Mappings { | ||
_meta?: { | ||
created_by: string; | ||
}; | ||
properties: { | ||
[key: string]: any; | ||
}; | ||
} | ||
|
||
export interface IngestPipelineWrapper { | ||
id: string; | ||
pipeline: IngestPipeline; | ||
} | ||
|
||
export interface IngestPipeline { | ||
description: string; | ||
processors: any[]; | ||
} |
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,11 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test', | ||
rootDir: '../../..', | ||
roots: ['<rootDir>/x-pack/plugins/file_upload'], | ||
}; |
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 @@ | ||
{ | ||
"id": "fileUpload", | ||
"version": "8.0.0", | ||
"kibanaVersion": "kibana", | ||
"server": true, | ||
"ui": false, | ||
"requiredPlugins": ["usageCollection"] | ||
} |
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,23 @@ | ||
/* | ||
* 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 { boomify, isBoom } from '@hapi/boom'; | ||
import { ResponseError, CustomHttpResponseOptions } from 'kibana/server'; | ||
|
||
export function wrapError(error: any): CustomHttpResponseOptions<ResponseError> { | ||
const boom = isBoom(error) | ||
? error | ||
: boomify(error, { statusCode: error.status ?? error.statusCode }); | ||
const statusCode = boom.output.statusCode; | ||
return { | ||
body: { | ||
message: boom, | ||
...(statusCode !== 500 && error.body ? { attributes: { body: error.body } } : {}), | ||
}, | ||
headers: boom.output.headers as { [key: string]: string }, | ||
statusCode, | ||
}; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* 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 { FileUploadPlugin } from './plugin'; | ||
|
||
export const plugin = () => new FileUploadPlugin(); |
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,24 @@ | ||
/* | ||
* 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 { CoreSetup, CoreStart, Plugin } from 'src/core/server'; | ||
import { fileUploadRoutes } from './routes'; | ||
import { initFileUploadTelemetry } from './telemetry'; | ||
import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/server'; | ||
|
||
interface SetupDeps { | ||
usageCollection: UsageCollectionSetup; | ||
} | ||
|
||
export class FileUploadPlugin implements Plugin { | ||
async setup(coreSetup: CoreSetup, plugins: SetupDeps) { | ||
fileUploadRoutes(coreSetup.http.createRouter()); | ||
|
||
initFileUploadTelemetry(coreSetup, plugins.usageCollection); | ||
} | ||
|
||
start(core: CoreStart) {} | ||
} |
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,85 @@ | ||
/* | ||
* 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 { IRouter, IScopedClusterClient } from 'kibana/server'; | ||
import { MAX_FILE_SIZE_BYTES, IngestPipelineWrapper, Mappings, Settings } from '../common'; | ||
import { wrapError } from './error_wrapper'; | ||
import { InputData, importDataProvider } from './import_data'; | ||
|
||
import { updateTelemetry } from './telemetry'; | ||
import { importFileBodySchema, importFileQuerySchema } from './schemas'; | ||
|
||
function importData( | ||
client: IScopedClusterClient, | ||
id: string | undefined, | ||
index: string, | ||
settings: Settings, | ||
mappings: Mappings, | ||
ingestPipeline: IngestPipelineWrapper, | ||
data: InputData | ||
) { | ||
const { importData: importDataFunc } = importDataProvider(client); | ||
return importDataFunc(id, index, settings, mappings, ingestPipeline, data); | ||
} | ||
|
||
/** | ||
* Routes for the file upload. | ||
*/ | ||
export function fileUploadRoutes(router: IRouter) { | ||
/** | ||
* @apiGroup FileDataVisualizer | ||
* | ||
* @api {post} /api/file_upload/import Import file data | ||
* @apiName ImportFile | ||
* @apiDescription Imports file data into elasticsearch index. | ||
* | ||
* @apiSchema (query) importFileQuerySchema | ||
* @apiSchema (body) importFileBodySchema | ||
*/ | ||
router.post( | ||
{ | ||
path: '/api/file_upload/import', | ||
validate: { | ||
query: importFileQuerySchema, | ||
body: importFileBodySchema, | ||
}, | ||
options: { | ||
body: { | ||
accepts: ['application/json'], | ||
maxBytes: MAX_FILE_SIZE_BYTES, | ||
}, | ||
tags: ['access:ml:canFindFileStructure'], | ||
}, | ||
}, | ||
async (context, request, response) => { | ||
try { | ||
const { id } = request.query; | ||
const { index, data, settings, mappings, ingestPipeline } = request.body; | ||
|
||
// `id` being `undefined` tells us that this is a new import due to create a new index. | ||
// follow-up import calls to just add additional data will include the `id` of the created | ||
// index, we'll ignore those and don't increment the counter. | ||
if (id === undefined) { | ||
await updateTelemetry(); | ||
} | ||
|
||
const result = await importData( | ||
context.core.elasticsearch.client, | ||
id, | ||
index, | ||
settings, | ||
mappings, | ||
// @ts-expect-error | ||
ingestPipeline, | ||
data | ||
); | ||
return response.ok({ body: result }); | ||
} catch (e) { | ||
return response.customError(wrapError(e)); | ||
} | ||
} | ||
); | ||
} |
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,24 @@ | ||
/* | ||
* 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 { schema } from '@kbn/config-schema'; | ||
|
||
export const importFileQuerySchema = schema.object({ | ||
id: schema.maybe(schema.string()), | ||
}); | ||
|
||
export const importFileBodySchema = schema.object({ | ||
index: schema.string(), | ||
data: schema.arrayOf(schema.any()), | ||
settings: schema.maybe(schema.any()), | ||
/** Mappings */ | ||
mappings: schema.any(), | ||
/** Ingest pipeline definition */ | ||
ingestPipeline: schema.object({ | ||
id: schema.maybe(schema.string()), | ||
pipeline: schema.maybe(schema.any()), | ||
}), | ||
}); |
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
File renamed without changes.
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
Oops, something went wrong.