Skip to content
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
merged 11 commits into from
Feb 7, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import chrome from 'ui/chrome';

import { http } from '../http_service';

const basePath = chrome.addBasePath('/api/ml');
const basePath = chrome.addBasePath('/api');

export const fileDatavisualizer = {
analyzeFile(obj, params = {}) {
Expand All @@ -22,7 +22,7 @@ export const fileDatavisualizer = {
}
}
return http({
url: `${basePath}/file_data_visualizer/analyze_file${paramString}`,
url: `${basePath}/ml/file_data_visualizer/analyze_file${paramString}`,
method: 'POST',
data: obj,
});
Expand All @@ -33,7 +33,7 @@ export const fileDatavisualizer = {
const { index, data, settings, mappings, ingestPipeline } = obj;

return http({
url: `${basePath}/file_data_visualizer/import${paramString}`,
url: `${basePath}/fileupload/import${paramString}`,
Copy link
Contributor

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 to incrementFileDataVisualizerIndexCreationCount 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.

method: 'POST',
data: {
index,
Expand Down

This file was deleted.

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,
};
}

This file was deleted.

Loading