Skip to content
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
6 changes: 4 additions & 2 deletions x-pack/plugins/ml/common/constants/file_datavisualizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/

export const MAX_BYTES = 104857600; // 100MB
export const ABSOLUTE_MAX_BYTES = 1073741274; // 1GB
export const MAX_FILE_SIZE = '100MB';
export const MAX_FILE_SIZE_BYTES = 104857600; // 100MB

export const ABSOLUTE_MAX_FILE_SIZE_BYTES = 1073741274; // 1GB
export const FILE_SIZE_DISPLAY_FORMAT = '0,0.[0] b';

// Value to use in the Elasticsearch index mapping meta data to identify the
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/ml/common/types/ml_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*/

import { schema, TypeOf } from '@kbn/config-schema';
import { MAX_BYTES } from '../constants/file_datavisualizer';
import { MAX_FILE_SIZE } from '../constants/file_datavisualizer';

export const configSchema = schema.object({
file_data_visualizer: schema.object({
max_file_size_bytes: schema.number({ defaultValue: MAX_BYTES }),
max_file_size: schema.string({ defaultValue: MAX_FILE_SIZE }),
}),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import numeral from '@elastic/numeral';
import { ml } from '../../../../services/ml_api_service';
import { AnalysisResult, InputOverrides } from '../../../../../../common/types/file_datavisualizer';
import {
ABSOLUTE_MAX_BYTES,
MAX_FILE_SIZE_BYTES,
ABSOLUTE_MAX_FILE_SIZE_BYTES,
FILE_SIZE_DISPLAY_FORMAT,
} from '../../../../../../common/constants/file_datavisualizer';
import { getMlConfig } from '../../../../util/dependency_cache';
Expand Down Expand Up @@ -61,8 +62,13 @@ export function readFile(file: File) {
}

export function getMaxBytes() {
const maxBytes = getMlConfig().file_data_visualizer.max_file_size_bytes;
return maxBytes < ABSOLUTE_MAX_BYTES ? maxBytes : ABSOLUTE_MAX_BYTES;
const maxFileSize = getMlConfig().file_data_visualizer.max_file_size;
// @ts-ignore
const maxBytes = numeral(maxFileSize.toUpperCase()).value();
if (maxBytes < MAX_FILE_SIZE_BYTES) {
return MAX_FILE_SIZE_BYTES;
}
return maxBytes < ABSOLUTE_MAX_FILE_SIZE_BYTES ? maxBytes : ABSOLUTE_MAX_FILE_SIZE_BYTES;
}

export function getMaxBytesFormatted() {
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/ml/server/routes/file_data_visualizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { schema } from '@kbn/config-schema';
import { RequestHandlerContext } from 'kibana/server';
import { MAX_BYTES } from '../../common/constants/file_datavisualizer';
import { MAX_FILE_SIZE_BYTES } from '../../common/constants/file_datavisualizer';
import {
InputOverrides,
Settings,
Expand Down Expand Up @@ -79,7 +79,7 @@ export function fileDataVisualizerRoutes({ router, mlLicense }: RouteInitializat
options: {
body: {
accepts: ['text/*', 'application/json'],
maxBytes: MAX_BYTES,
maxBytes: MAX_FILE_SIZE_BYTES,
},
},
},
Expand Down Expand Up @@ -121,7 +121,7 @@ export function fileDataVisualizerRoutes({ router, mlLicense }: RouteInitializat
options: {
body: {
accepts: ['application/json'],
maxBytes: MAX_BYTES,
maxBytes: MAX_FILE_SIZE_BYTES,
},
},
},
Expand Down