Skip to content

Commit

Permalink
[ML] Reducing risk of upload timeouts (elastic#24677) (elastic#24821)
Browse files Browse the repository at this point in the history
* [ML] Reducing risk of upload timeouts

* function rename

* removing hardcoded number

* fixing typo

* updating comment
  • Loading branch information
jgowdyelastic authored Oct 30, 2018
1 parent a4c33d1 commit 15df226
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 15df226

Please sign in to comment.