-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[ML] New Platform server shim: update file data visualizer routes to use new platform router #56972
Merged
darnautov
merged 11 commits into
elastic:master
from
darnautov:ML-49743-fileDataVisualizerRoutes
Feb 7, 2020
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a4fe581
[ML] change import endpoint call to fileupload plugin, update file an…
darnautov 8f78c7f
[ML] add apiDoc annotation
darnautov 5630793
[ML] AnalysisResult interface, remove url from apidoc.json
darnautov 8c77b27
[ML] delete import_data.js
darnautov e5e6098
[ML] remove caching code, address PR comments
darnautov 5570202
[ML] file import
darnautov 0bfcb34
[ML] apidoc
darnautov 6444aff
Merge branch 'master' into ML-49743-fileDataVisualizerRoutes
darnautov ce85c3a
[ML] schema validation
darnautov c0eb6ff
Merge remote-tracking branch 'origin/ML-49743-fileDataVisualizerRoute…
darnautov 61d55af
Merge branch 'master' into ML-49743-fileDataVisualizerRoutes
elasticmachine 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
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
100 changes: 0 additions & 100 deletions
100
x-pack/legacy/plugins/ml/server/models/file_data_visualizer/file_data_visualizer.js
This file was deleted.
Oops, something went wrong.
105 changes: 105 additions & 0 deletions
105
x-pack/legacy/plugins/ml/server/models/file_data_visualizer/file_data_visualizer.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,105 @@ | ||
/* | ||
* 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 Boom from 'boom'; | ||
import { RequestHandlerContext } from 'kibana/server'; | ||
|
||
export interface InputData { | ||
[key: string]: any; | ||
} | ||
|
||
export interface InputOverrides { | ||
[key: string]: string; | ||
} | ||
|
||
export type FormattedOverrides = InputOverrides & { | ||
column_names: string[]; | ||
has_header_row: boolean; | ||
should_trim_fields: boolean; | ||
}; | ||
|
||
export interface AnalysisResult { | ||
results: { | ||
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[]; | ||
}; | ||
overrides?: FormattedOverrides; | ||
} | ||
|
||
export function fileDataVisualizerProvider(context: RequestHandlerContext) { | ||
async function analyzeFile(data: any, overrides: any): Promise<AnalysisResult> { | ||
let results = []; | ||
|
||
try { | ||
results = await context.ml!.mlClient.callAsCurrentUser('ml.fileStructure', { | ||
body: data, | ||
...overrides, | ||
}); | ||
} catch (error) { | ||
const err = error.message !== undefined ? error.message : error; | ||
throw Boom.badRequest(err); | ||
} | ||
|
||
const { hasOverrides, reducedOverrides } = formatOverrides(overrides); | ||
|
||
return { | ||
...(hasOverrides && { overrides: reducedOverrides }), | ||
results, | ||
}; | ||
} | ||
|
||
return { | ||
analyzeFile, | ||
}; | ||
} | ||
|
||
function formatOverrides(overrides: InputOverrides) { | ||
let hasOverrides = false; | ||
|
||
const reducedOverrides: FormattedOverrides = Object.keys(overrides).reduce((acc, overrideKey) => { | ||
const overrideValue: string = overrides[overrideKey]; | ||
if (overrideValue !== '') { | ||
if (overrideKey === 'column_names') { | ||
acc.column_names = overrideValue.split(','); | ||
} else if (overrideKey === 'has_header_row') { | ||
acc.has_header_row = overrideValue === 'true'; | ||
} else if (overrideKey === 'should_trim_fields') { | ||
acc.should_trim_fields = overrideValue === 'true'; | ||
} else { | ||
acc[overrideKey] = overrideValue; | ||
} | ||
|
||
hasOverrides = true; | ||
} | ||
return acc; | ||
}, {} as FormattedOverrides); | ||
|
||
return { | ||
reducedOverrides, | ||
hasOverrides, | ||
}; | ||
} |
165 changes: 0 additions & 165 deletions
165
x-pack/legacy/plugins/ml/server/models/file_data_visualizer/import_data.js
This file was deleted.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switching to the
fileupload
route for the import means we are losing the telemetry on the count of indexes created by the ML file data visualizer, which was done by a call toincrementFileDataVisualizerIndexCreationCount
in/ml/server/lib/ml_telemetry/ml_telemetry.ts
. We need to keep the telemetry part of the import, but get the file upload plugin to do the actual file import.