Skip to content

Commit 68522ee

Browse files
committed
[ML] Changing file data visualizer max upload setting to string (#63502)
1 parent 1cd4895 commit 68522ee

4 files changed

Lines changed: 18 additions & 10 deletions

File tree

x-pack/plugins/ml/common/constants/file_datavisualizer.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
export const MAX_BYTES = 104857600; // 100MB
8-
export const ABSOLUTE_MAX_BYTES = 1073741274; // 1GB
7+
export const MAX_FILE_SIZE = '100MB';
8+
export const MAX_FILE_SIZE_BYTES = 104857600; // 100MB
9+
10+
export const ABSOLUTE_MAX_FILE_SIZE_BYTES = 1073741274; // 1GB
911
export const FILE_SIZE_DISPLAY_FORMAT = '0,0.[0] b';
1012

1113
// Value to use in the Elasticsearch index mapping meta data to identify the

x-pack/plugins/ml/common/types/ml_config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
*/
66

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

1010
export const configSchema = schema.object({
1111
file_data_visualizer: schema.object({
12-
max_file_size_bytes: schema.number({ defaultValue: MAX_BYTES }),
12+
max_file_size: schema.string({ defaultValue: MAX_FILE_SIZE }),
1313
}),
1414
});
1515

x-pack/plugins/ml/public/application/datavisualizer/file_based/components/utils/utils.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import numeral from '@elastic/numeral';
99
import { ml } from '../../../../services/ml_api_service';
1010
import { AnalysisResult, InputOverrides } from '../../../../../../common/types/file_datavisualizer';
1111
import {
12-
ABSOLUTE_MAX_BYTES,
12+
MAX_FILE_SIZE_BYTES,
13+
ABSOLUTE_MAX_FILE_SIZE_BYTES,
1314
FILE_SIZE_DISPLAY_FORMAT,
1415
} from '../../../../../../common/constants/file_datavisualizer';
1516
import { getMlConfig } from '../../../../util/dependency_cache';
@@ -61,8 +62,13 @@ export function readFile(file: File) {
6162
}
6263

6364
export function getMaxBytes() {
64-
const maxBytes = getMlConfig().file_data_visualizer.max_file_size_bytes;
65-
return maxBytes < ABSOLUTE_MAX_BYTES ? maxBytes : ABSOLUTE_MAX_BYTES;
65+
const maxFileSize = getMlConfig().file_data_visualizer.max_file_size;
66+
// @ts-ignore
67+
const maxBytes = numeral(maxFileSize.toUpperCase()).value();
68+
if (maxBytes < MAX_FILE_SIZE_BYTES) {
69+
return MAX_FILE_SIZE_BYTES;
70+
}
71+
return maxBytes < ABSOLUTE_MAX_FILE_SIZE_BYTES ? maxBytes : ABSOLUTE_MAX_FILE_SIZE_BYTES;
6672
}
6773

6874
export function getMaxBytesFormatted() {

x-pack/plugins/ml/server/routes/file_data_visualizer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import { schema } from '@kbn/config-schema';
88
import { RequestHandlerContext } from 'kibana/server';
9-
import { MAX_BYTES } from '../../common/constants/file_datavisualizer';
9+
import { MAX_FILE_SIZE_BYTES } from '../../common/constants/file_datavisualizer';
1010
import {
1111
InputOverrides,
1212
Settings,
@@ -79,7 +79,7 @@ export function fileDataVisualizerRoutes({ router, mlLicense }: RouteInitializat
7979
options: {
8080
body: {
8181
accepts: ['text/*', 'application/json'],
82-
maxBytes: MAX_BYTES,
82+
maxBytes: MAX_FILE_SIZE_BYTES,
8383
},
8484
},
8585
},
@@ -121,7 +121,7 @@ export function fileDataVisualizerRoutes({ router, mlLicense }: RouteInitializat
121121
options: {
122122
body: {
123123
accepts: ['application/json'],
124-
maxBytes: MAX_BYTES,
124+
maxBytes: MAX_FILE_SIZE_BYTES,
125125
},
126126
},
127127
},

0 commit comments

Comments
 (0)