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] Reducing risk of upload timeouts #24677

Merged
merged 5 commits into from
Oct 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need revisiting when we offer people the chance to change the number of lines that get sampled.

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