From 15df226e0f811665e9b27e90776677d46beb7a33 Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Tue, 30 Oct 2018 12:37:46 +0000 Subject: [PATCH] [ML] Reducing risk of upload timeouts (#24677) (#24821) * [ML] Reducing risk of upload timeouts * function rename * removing hardcoded number * fixing typo * updating comment --- .../file_datavisualizer_view.js | 14 ++++++++++++-- .../components/file_datavisualizer_view/utils.js | 8 ++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/ml/public/file_datavisualizer/components/file_datavisualizer_view/file_datavisualizer_view.js b/x-pack/plugins/ml/public/file_datavisualizer/components/file_datavisualizer_view/file_datavisualizer_view.js index 81247c3fe8150..e3c7708cc1d0a 100644 --- a/x-pack/plugins/ml/public/file_datavisualizer/components/file_datavisualizer_view/file_datavisualizer_view.js +++ b/x-pack/plugins/ml/public/file_datavisualizer/components/file_datavisualizer_view/file_datavisualizer_view.js @@ -23,13 +23,20 @@ import { FileCouldNotBeRead, FileTooLarge } from './file_error_callouts'; import { EditFlyout } from '../edit_flyout'; import { ImportView } from '../import_view'; import { MAX_BYTES } from '../../../../common/constants/file_datavisualizer'; -import { readFile, createUrlOverrides, processResults } from './utils'; +import { + readFile, + createUrlOverrides, + processResults, + reduceData, +} from './utils'; export const MODE = { READ: 0, IMPORT: 1, }; +const UPLOAD_SIZE_MB = 5; + export class FileDataVisualizerView extends Component { constructor(props) { super(props); @@ -108,9 +115,12 @@ export class FileDataVisualizerView extends Component { async loadSettings(data, overrides, isRetry = false) { try { + // reduce the amount of data being sent to the endpoint + // 5MB should be enough to contain 1000 lines + const lessData = reduceData(data, UPLOAD_SIZE_MB); console.log('overrides', overrides); const { analyzeFile } = ml.fileDatavisualizer; - const resp = await analyzeFile(data, overrides); + const resp = await analyzeFile(lessData, overrides); const serverSettings = processResults(resp.results); const serverOverrides = resp.overrides; diff --git a/x-pack/plugins/ml/public/file_datavisualizer/components/file_datavisualizer_view/utils.js b/x-pack/plugins/ml/public/file_datavisualizer/components/file_datavisualizer_view/utils.js index e97c16b629b8f..a3fa19fb7ee0f 100644 --- a/x-pack/plugins/ml/public/file_datavisualizer/components/file_datavisualizer_view/utils.js +++ b/x-pack/plugins/ml/public/file_datavisualizer/components/file_datavisualizer_view/utils.js @@ -30,6 +30,14 @@ export function readFile(file) { }); } +export function reduceData(data, mb) { + // assuming ascii characters in the file where 1 char is 1 byte + // TODO - change this when other non UTF-8 formats are + // supported for the read data + const size = mb * Math.pow(2, 20); + return (data.length >= size) ? data.slice(0, size) : data; +} + export function createUrlOverrides(overrides, originalSettings) { const formattedOverrides = {}; for (const o in overrideDefaults) {