Skip to content

Commit

Permalink
Make CSV upload limit configurable
Browse files Browse the repository at this point in the history
Kibana's Upload CSV feature isn't intended for gigantic import jobs, so
I originally set a sane default of 1GB. Some users exprssed a desire to
import slightly larger files, they should be able to import something
that's 1.1GB without being blocked by an arbitrary limit. So I've made
the limit configurable via kibana.yml.

This change includes a few pieces:
* Added optional `kibana.addDataMaxBytes` key to kibana.yml with 1GB
  default
* Set upload data route payload limit based on new config value
* Updated help text in UI to use the dynamic config value on the parse
  csv page
* Updated parse csv page to check file size and fail early if the
  selected file is too big

Resolves: elastic#7671
  • Loading branch information
Bargs committed Sep 12, 2016
1 parent 4f940ee commit 0503aa8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/kibana-yml.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ to this Kibana instance.
`kibana.index:`:: *Default: ".kibana"* Kibana uses an index in Elasticsearch to store saved searches, visualizations and
dashboards. Kibana creates a new index if the index doesn’t already exist.
`kibana.defaultAppId:`:: *Default: "discover"* The default application to load.
`kibana.addDataMaxBytes:`:: *Default: 1073741824* The maximum upload size in bytes for the CSV Upload wizard
[[tilemap-settings]]`tilemap.url:`:: *Default: `"https://tiles.elastic.co/v1/default/{z}/{x}/{y}.png?elastic_tile_service_tos=agree&my_app_name=kibana"`* The URL to the tile
service that Kibana uses to display map tiles in tilemap visualizations.
`tilemap.options.minZoom:`:: *Default: 1* The minimum zoom level.
Expand Down
8 changes: 6 additions & 2 deletions src/core_plugins/kibana/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ module.exports = function (kibana) {
return new kibana.Plugin({
id: 'kibana',
config: function (Joi) {
const ONE_GIGABYTE = 1024 * 1024 * 1024;

return Joi.object({
enabled: Joi.boolean().default(true),
defaultAppId: Joi.string().default('discover'),
index: Joi.string().default('.kibana')
index: Joi.string().default('.kibana'),
addDataMaxBytes: Joi.number().default(ONE_GIGABYTE)
}).default();
},

Expand All @@ -41,7 +44,8 @@ module.exports = function (kibana) {
let config = server.config();
return {
kbnDefaultAppId: config.get('kibana.defaultAppId'),
tilemap: config.get('tilemap')
tilemap: config.get('tilemap'),
addDataMaxBytes: config.get('kibana.addDataMaxBytes')
};
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h2><em>Pick a CSV file to get started.</em>
<button class="btn btn-primary btn-lg controls upload" ng-click>
Select File
</button>
<div>Maximum upload file size: 1 GB</div>
<div>Maximum upload file size: {{ wizard.maxBytesFormatted }}</div>
</div>
</file-upload>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import modules from 'ui/modules';
import validateHeaders from './lib/validate_headers';
import template from './parse_csv_step.html';
import './styles/_add_data_parse_csv_step.less';
import numeral from '@spalger/numeral';

modules.get('apps/management')
.directive('parseCsvStep', function () {
.directive('parseCsvStep', function (addDataMaxBytes) {
return {
restrict: 'E',
template: template,
Expand All @@ -21,6 +22,8 @@ modules.get('apps/management')
const maxSampleRows = 10;
const maxSampleColumns = 20;

this.maxBytesFormatted = numeral(addDataMaxBytes).format('0 b');

this.delimiterOptions = [
{
label: 'comma',
Expand Down Expand Up @@ -55,6 +58,13 @@ modules.get('apps/management')
this.formattedErrors = [];
this.formattedWarnings = [];

if (this.file.size > addDataMaxBytes) {
this.formattedErrors.push(
`File size (${this.file.size} bytes) is greater than the configured limit of ${addDataMaxBytes} bytes`
);
return;
}

const config = _.assign(
{
header: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import { patternToIngest } from '../../../../common/lib/convert_pattern_and_inge
import { PassThrough } from 'stream';
import JSONStream from 'JSONStream';

const ONE_GIGABYTE = 1024 * 1024 * 1024;

export function registerData(server) {
const maxBytes = server.config().get('kibana.addDataMaxBytes');

server.route({
path: '/api/kibana/{id}/_data',
method: 'POST',
config: {
payload: {
output: 'stream',
maxBytes: ONE_GIGABYTE
maxBytes
}
},
handler: function (req, reply) {
Expand Down

0 comments on commit 0503aa8

Please sign in to comment.