Skip to content

Commit

Permalink
Merge branch 'master' into fix/elastic#1962
Browse files Browse the repository at this point in the history
  • Loading branch information
stormpython committed Feb 3, 2015
2 parents eb92dc3 + f4c8828 commit 32d2552
Show file tree
Hide file tree
Showing 18 changed files with 113 additions and 72 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@
"request": "^2.40.0",
"requirefrom": "^0.2.0",
"semver": "^4.2.0",
"serve-favicon": "~2.2.0",
"ssl-root-cas": "^1.1.7"
"serve-favicon": "~2.2.0"
},
"devDependencies": {
"connect": "~2.19.5",
Expand Down
15 changes: 9 additions & 6 deletions src/kibana/components/agg_types/buckets/terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ define(function (require) {
}
])).all[0];

function isNotType(type) {
return function (agg) {
var field = agg.params.field;
return !field || field.type !== type;
};
}

return new BucketAggType({
name: 'terms',
title: 'Terms',
Expand All @@ -34,17 +41,13 @@ define(function (require) {
name: 'exclude',
type: 'regex',
advanced: true,
disabled: function (aggConfig) {
return aggConfig.params.field.type !== 'string';
}
disabled: isNotType('string')
},
{
name: 'include',
type: 'regex',
advanced: true,
disabled: function (aggConfig) {
return aggConfig.params.field.type !== 'string';
}
disabled: isNotType('string')
},
{
name: 'size',
Expand Down
23 changes: 19 additions & 4 deletions src/kibana/components/doc_table/lib/get_sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,29 @@ define(function (require) {
*/
return function (sort, indexPattern) {
var sortObj = {};
if (_.isArray(sort) && sort.length === 2) {
var field, direction;

function isSortable(field) {
return (indexPattern.fields.byName[field] && indexPattern.fields.byName[field].sortable);
}

if (_.isArray(sort) && sort.length === 2 && isSortable(sort[0])) {
// At some point we need to refact the sorting logic, this array sucks.
sortObj[sort[0]] = sort[1];
} else if (indexPattern.timeFieldName) {
sortObj[indexPattern.timeFieldName] = 'desc';
field = sort[0];
direction = sort[1];
} else if (indexPattern.timeFieldName && isSortable(indexPattern.timeFieldName)) {
field = indexPattern.timeFieldName;
direction = 'desc';
}

if (field) {
sortObj[field] = direction;
} else {
sortObj._score = 'desc';
}



return sortObj;
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ define(function (require) {
charts = obj.rows ? obj.rows : obj.columns;
}

return _.chain(charts ? charts : [obj])
return _(charts ? charts : [obj])
.pluck('series')
.flatten()
.pluck('values')
.flatten()
.filter(Boolean)
.value();
};
};
Expand Down
2 changes: 1 addition & 1 deletion src/kibana/components/vislib/vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ define(function (require) {
return;
}

if (_.isFunction(this.handler.resize)) {
if (this.handler && _.isFunction(this.handler.resize)) {
this._runOnHandler('resize');
} else {
this.render(this.data);
Expand Down
3 changes: 2 additions & 1 deletion src/kibana/components/visualize/spy/_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ define(function (require) {

$scope.table = tabifyAggResponse($scope.vis, $scope.esResp, {
canSplit: false,
asAggConfigResults: true
asAggConfigResults: true,
partialRows: true
});
}
});
Expand Down
11 changes: 2 additions & 9 deletions src/kibana/plugins/discover/controllers/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,15 +425,8 @@ define(function (require) {
$scope.searchSource
.size($scope.opts.sampleSize)
.sort(function () {
var sort = {};
if (_.isArray($state.sort) && $state.sort.length === 2) {
sort[$state.sort[0]] = $state.sort[1];
} else if ($scope.indexPattern.timeFieldName) {
// Use the watcher to set sort in this case, the above `if` will now be true
$state.sort = [$scope.indexPattern.timeFieldName, 'desc'];
} else {
sort._score = 'desc';
}
var sort = getSort($state.sort, $scope.indexPattern);
$state.sort = _.pairs(sort)[0];
return sort;
})
.query(!$state.query ? null : $state.query)
Expand Down
1 change: 0 additions & 1 deletion src/kibana/plugins/metric_vis/metric_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ define(function (require) {
name: 'metric',
title: 'Metric',
min: 1,
max: 1,
defaults: [
{ type: 'count', schema: 'metric' }
]
Expand Down
Binary file modified src/kibana/plugins/settings/sections/about/elk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 12 additions & 8 deletions src/kibana/plugins/vis_types/vislib/_build_chart_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ define(function (require) {
return aggResponse.hierarchical(vis, esResponse);
}

var tableGroup = aggResponse.tabify(this.vis, esResponse, {
var tableGroup = aggResponse.tabify(vis, esResponse, {
canSplit: true,
asAggConfigResults: true
});

var converted = convertTableGroup(vis, tableGroup);
if (!converted) {
// mimic a row of tables that doesn't have any tables
// https://github.com/elasticsearch/kibana/blob/7bfb68cd24ed42b1b257682f93c50cd8d73e2520/src/kibana/components/vislib/components/zero_injection/inject_zeros.js#L32
converted = { rows: [] };
}

converted.hits = esResponse.hits.total;

Expand All @@ -35,6 +41,7 @@ define(function (require) {
return chart;
}

if (!tables.length) return;
var out = {};
var outList;

Expand All @@ -45,15 +52,12 @@ define(function (require) {
outList = out[direction] = [];
}

outList.push(convertTableGroup(vis, table));
var output;
if (output = convertTableGroup(vis, table)) {
outList.push(output);
}
});

if (!tables.length) {
// mimic a row of tables that doesn't have any tables
// https://github.com/elasticsearch/kibana/blob/7bfb68cd24ed42b1b257682f93c50cd8d73e2520/src/kibana/components/vislib/components/zero_injection/inject_zeros.js#L32
out.rows = [];
}

return out;
}

Expand Down
Binary file modified src/kibana/styles/theme/elk.ico
Binary file not shown.
8 changes: 7 additions & 1 deletion src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ function start() {
module.exports = {
server: server,
start: function (cb) {
return initialization().then(start).nodeify(cb);
return initialization()
.then(start)
.catch(function (err) {
logger.error({ err: err });
throw err;
})
.nodeify(cb);
}
};

Expand Down
13 changes: 4 additions & 9 deletions src/server/routes/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,9 @@ var join = require('path').join;

// If the target is backed by an SSL and a CA is provided via the config
// then we need to inject the CA
var hasCustomCA = false;
var customCA;
if (/^https/.test(target.protocol) && config.kibana.ca) {
var sslRootCAs = require('ssl-root-cas/latest');
sslRootCAs.inject();
var ca = fs.readFileSync(config.kibana.ca, 'utf8');
var https = require('https');
https.globalAgent.options.ca.push(ca);
hasCustomCA = true;
customCA = fs.readFileSync(config.kibana.ca, 'utf8');
}

// Create the router
Expand Down Expand Up @@ -59,8 +54,8 @@ router.use(function (req, res, next) {
options.headers['x-forward-proto'] = req.connection.pair ? 'https' : 'http';

// If the server has a custom CA we need to add it to the agent options
if (hasCustomCA) {
options.agentOptions = { ca: https.globalAgent.options.ca };
if (customCA) {
options.agentOptions = { ca: [customCA] };
}

// Only send the body if it's a PATCH, PUT, or POST
Expand Down
3 changes: 2 additions & 1 deletion tasks/kibana_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module.exports = function (grunt) {
config.quiet = true;
var server = require('../src/server');

server.start(function () {
server.start(function (err) {
if (err) return done(err);
grunt.log.ok('Server started on port', config.kibana.port);
if (keepalive !== 'keepalive') done();
});
Expand Down
29 changes: 15 additions & 14 deletions test/unit/fixtures/logstash_fields.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
define(function (require) {
function stubbedLogstashFields() {
var sourceData = [
{ name: 'bytes', type: 'number', indexed: true, analyzed: true, count: 10 },
{ name: 'ssl', type: 'boolean', indexed: true, analyzed: true, count: 20 },
{ name: '@timestamp', type: 'date', indexed: true, analyzed: true, count: 30 },
{ name: 'time', type: 'date', indexed: true, analyzed: true, count: 30 },
{ name: 'utc_time', type: 'date', indexed: true, analyzed: true },
{ name: 'phpmemory', type: 'number', indexed: true, analyzed: true },
{ name: 'ip', type: 'ip', indexed: true, analyzed: true },
{ name: 'request_body', type: 'attachment', indexed: true, analyzed: true },
{ name: 'point', type: 'geo_point', indexed: true, analyzed: true },
{ name: 'area', type: 'geo_shape', indexed: true, analyzed: true },
{ name: 'extension', type: 'string', indexed: true, analyzed: true },
{ name: 'machine.os', type: 'string', indexed: true, analyzed: true },
{ name: 'geo.src', type: 'string', indexed: true, analyzed: true },
{ name: '_type', type: 'string', indexed: true, analyzed: true },
{ name: 'bytes', type: 'number', indexed: true, analyzed: true, sortable: true, filterable: true, count: 10 },
{ name: 'ssl', type: 'boolean', indexed: true, analyzed: true, sortable: true, filterable: true, count: 20 },
{ name: '@timestamp', type: 'date', indexed: true, analyzed: true, sortable: true, filterable: true, count: 30 },
{ name: 'time', type: 'date', indexed: true, analyzed: true, sortable: true, filterable: true, count: 30 },
{ name: 'utc_time', type: 'date', indexed: true, analyzed: true, sortable: true, filterable: true },
{ name: 'phpmemory', type: 'number', indexed: true, analyzed: true, sortable: true, filterable: true },
{ name: 'ip', type: 'ip', indexed: true, analyzed: true, sortable: true, filterable: true },
{ name: 'request_body', type: 'attachment', indexed: true, analyzed: true, sortable: false, filterable: true },
{ name: 'point', type: 'geo_point', indexed: true, analyzed: true, sortable: false, filterable: false },
{ name: 'area', type: 'geo_shape', indexed: true, analyzed: true, sortable: true, filterable: false },
{ name: 'extension', type: 'string', indexed: true, analyzed: true, sortable: true, filterable: true },
{ name: 'machine.os', type: 'string', indexed: true, analyzed: true, sortable: true, filterable: true },
{ name: 'geo.src', type: 'string', indexed: true, analyzed: true, sortable: true, filterable: true },
{ name: '_type', type: 'string', indexed: true, analyzed: true, sortable: true, filterable: true },
{ name: '_id', type: 'string', indexed: false, analyzed: false, sortable: false, filterable: true},
{ name: 'custom_user_field', type: 'conflict', indexed: false, analyzed: false },
{ name: 'script string', type: 'string', scripted: true, script: '\'i am a string\''},
{ name: 'script number', type: 'number', scripted: true, script: '1234'},
Expand Down
37 changes: 25 additions & 12 deletions test/unit/specs/components/doc_table/lib/get_sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,43 @@ define(function (require) {
describe('docTable', function () {
describe('getSort function', function () {

var timePattern = {
timeFieldName: 'time'
};
var noTimePattern = {};
beforeEach(module('kibana'));

beforeEach(inject(function (Private, _$rootScope_, Promise) {
indexPattern = Private(require('fixtures/stubbed_logstash_index_pattern'));
}));

it('should be a function', function () {
expect(getSort).to.be.a(Function);
});

it('should return an object if passed a 2 item array', function () {
expect(getSort(['foo', 'bar'], timePattern)).to.eql({foo: 'bar'});
expect(getSort(['foo', 'bar'], noTimePattern)).to.eql({foo: 'bar'});
expect(getSort(['bytes', 'desc'], indexPattern)).to.eql({bytes: 'desc'});

delete indexPattern.timeFieldName;
expect(getSort(['bytes', 'desc'], indexPattern)).to.eql({bytes: 'desc'});
});

it('should sort by the default when passed an unsortable field', function () {
expect(getSort(['_id', 'asc'], indexPattern)).to.eql({time: 'desc'});
expect(getSort(['lol_nope', 'asc'], indexPattern)).to.eql({time: 'desc'});

delete indexPattern.timeFieldName;
expect(getSort(['_id', 'asc'], indexPattern)).to.eql({_score: 'desc'});
});

it('should sort in reverse chrono order otherwise on time based patterns', function () {
expect(getSort([], timePattern)).to.eql({time: 'desc'});
expect(getSort(['foo'], timePattern)).to.eql({time: 'desc'});
expect(getSort({foo: 'bar'}, timePattern)).to.eql({time: 'desc'});
expect(getSort([], indexPattern)).to.eql({time: 'desc'});
expect(getSort(['foo'], indexPattern)).to.eql({time: 'desc'});
expect(getSort({foo: 'bar'}, indexPattern)).to.eql({time: 'desc'});
});

it('should sort by score on non-time patterns', function () {
expect(getSort([], noTimePattern)).to.eql({_score: 'desc'});
expect(getSort(['foo'], noTimePattern)).to.eql({_score: 'desc'});
expect(getSort({foo: 'bar'}, noTimePattern)).to.eql({_score: 'desc'});
delete indexPattern.timeFieldName;

expect(getSort([], indexPattern)).to.eql({_score: 'desc'});
expect(getSort(['foo'], indexPattern)).to.eql({_score: 'desc'});
expect(getSort({foo: 'bar'}, indexPattern)).to.eql({_score: 'desc'});
});

});
Expand Down
6 changes: 4 additions & 2 deletions test/unit/specs/components/index_pattern/_index_pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ define(function (require) {

describe('getFields', function () {
it('should return all non-scripted fields', function () {
var indexed = _.where(mockLogstashFields, { scripted: false });
expect(indexPattern.getFields()).to.eql(indexed);
var expected = _.pluck(_.where(mockLogstashFields, { scripted: false }), name).sort();
var result = _.pluck(indexPattern.getFields(), name).sort();

expect(result).to.eql(expected);
});

it('should return all scripted fields', function () {
Expand Down
8 changes: 8 additions & 0 deletions test/utils/stub_index_pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ define(function (require) {
var sinon = require('sinon/sinon');
var IndexedArray = require('utils/indexed_array/index');
var fieldFormats = Private(require('components/index_patterns/_field_formats'));
var flattenSearchResponse = require('components/index_patterns/_flatten_search_response');
var flattenHit = require('components/index_patterns/_flatten_hit');
var getComputedFields = require('components/index_patterns/_get_computed_fields');


function StubIndexPattern(pattern, timeField, fields) {
this.popularizeField = sinon.spy();
Expand All @@ -27,6 +31,10 @@ define(function (require) {
});
this.getFields = sinon.spy();
this.toIndexList = _.constant([pattern]);
this.getComputedFields = getComputedFields;
this.flattenSearchResponse = flattenSearchResponse;
this.flattenHit = flattenHit;
this.metaFields = ['_id', '_type', '_source'];
}

return StubIndexPattern;
Expand Down

0 comments on commit 32d2552

Please sign in to comment.