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

Time Series Visual Builder: Modify Behavior for Aggregation Selection #10890

Merged
merged 13 commits into from
Mar 28, 2017
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
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,11 @@
"auto-release-sinon": "1.0.3",
"babel-eslint": "6.1.2",
"chai": "3.5.0",
"chance": "1.0.6",
"cheerio": "0.22.0",
"chokidar": "1.6.0",
"chromedriver": "2.24.1",
"classnames": "2.2.5",
"del": "1.2.1",
"elasticdump": "2.1.1",
"enzyme": "2.7.0",
"eslint": "3.11.1",
"eslint-plugin-babel": "4.0.0",
Expand Down
16 changes: 16 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# kibana dev scripts

This directory contains scripts useful for interacting with Kibana tools in development. Use the node executable and `--help` flag to learn about how they work:

```sh
node scripts/{{script name}} --help
```

## for developers

This directory is excluded from the build and tools within it should help users discover their capabilities. Each script in this directory must:

- include the `../src/optimize/babel/register` module to bootstrap babel
- call out to source code that is in the `src` directory
- react to the `--help` flag
- run everywhere OR check and fail fast when a required OS or toolchain is not available
2 changes: 2 additions & 0 deletions scripts/es_archiver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require('../src/optimize/babel/register');
require('../src/es_archiver/cli');
1 change: 0 additions & 1 deletion src/core_plugins/console/public/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ rules:
no-nested-ternary: off
no-proto: off
no-sequences: off
no-undef: off
no-use-before-define: off
one-var: off
quotes: off
Expand Down
2 changes: 0 additions & 2 deletions src/core_plugins/console/public/src/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ module.exports = function (editor) {
case "url.part":
case "url.param":
case "url.value":
insertingRelativeToToken = 0;
context.rangeToReplace = new AceRange(
pos.row, anchorToken.start, pos.row,
context.updatedForToken.start + context.updatedForToken.value.length
Expand All @@ -340,7 +339,6 @@ module.exports = function (editor) {
break;
default:
if (replacingTerm && context.updatedForToken.value == replacingTerm) {
insertingRelativeToToken = 0;
context.rangeToReplace = new AceRange(
pos.row, anchorToken.start, pos.row,
context.updatedForToken.start + context.updatedForToken.value.length
Expand Down
1 change: 1 addition & 0 deletions src/core_plugins/console/public/src/output.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from 'lodash';
let ace = require('ace');
let settings = require('./settings');
let OutputMode = require('./sense_editor/mode/output');
Expand Down
2 changes: 2 additions & 0 deletions src/core_plugins/console/public/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import _ from 'lodash';

var utils = {};

utils.textFromRequest = function (request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let _ = require('lodash');
let curl = require('../../src/curl');
let curlTests = require('raw!./curl_parsing_tests.txt');

var { test, module, ok, equal } = QUnit;
var { test, module, ok, equal } = window.QUnit;

module("CURL");

Expand Down
4 changes: 3 additions & 1 deletion src/core_plugins/console/public/tests/src/editor_tests.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import $ from 'jquery';
import _ from 'lodash';
let ace = require('ace');
import { initializeInput } from '../../src/input';
let editor_input1 = require('raw!./editor_input1.txt');
let utils = require('../../src/utils');

var aceRange = ace.require("ace/range");
var { module, asyncTest, deepEqual, equal, start } = QUnit;
var { module, asyncTest, deepEqual, equal, start } = window.QUnit;

let input;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { initializeInput } from '../../src/input';
let input;

var token_iterator = ace.require("ace/token_iterator");
var { module, asyncTest, deepEqual, start } = QUnit;
var { module, asyncTest, deepEqual, start } = window.QUnit;


module("Input Tokenization", {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { initializeInput } from '../../src/input';
import _ from 'lodash';
let input;
let kb = require('../../src/kb');
let mappings = require('../../src/mappings');
let $ = require('jquery');

var { module, ok, asyncTest, deepEqual, equal, start } = QUnit;
var { module, ok, asyncTest, deepEqual, equal, start } = window.QUnit;

module("Integration", {
setup: function () {
Expand Down
3 changes: 2 additions & 1 deletion src/core_plugins/console/public/tests/src/kb_tests.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import _ from 'lodash';
let kb = require('../../src/kb');
let mappings = require('../../src/mappings');
let autocomplete_engine = require('../../src/autocomplete/engine');

var { test, module, deepEqual } = QUnit;
var { test, module, deepEqual } = window.QUnit;

module("Knowledge base", {
setup: function () {
Expand Down
8 changes: 4 additions & 4 deletions src/core_plugins/console/public/tests/src/mapping_tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let mappings = require('../../src/mappings');

var { test, module, deepEqual } = QUnit;
var { test, module, deepEqual } = window.QUnit;

module("Mappings", {
setup: function () {
Expand Down Expand Up @@ -82,7 +82,7 @@ test("Multi fields 1.0 style", function () {
f("any_name", "string"), f("first_name", "string"), f("last_name", "string"), f("last_name.raw", "string")]);
});

QUnit.test("Simple fields", function () {
test("Simple fields", function () {
mappings.loadMappings({
"index": {
"tweet": {
Expand All @@ -101,7 +101,7 @@ QUnit.test("Simple fields", function () {
deepEqual(mappings.getFields("index").sort(fc), [f("number", "int"), f("str", "string")]);
});

QUnit.test("Simple fields - 1.0 style", function () {
test("Simple fields - 1.0 style", function () {
mappings.loadMappings({
"index": {
"mappings": {
Expand All @@ -122,7 +122,7 @@ QUnit.test("Simple fields - 1.0 style", function () {
deepEqual(mappings.getFields("index").sort(fc), [f("number", "int"), f("str", "string")]);
});

QUnit.test("Nested fields", function () {
test("Nested fields", function () {
mappings.loadMappings({
"index": {
"tweet": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { initializeOutput } from '../../src/output';
let output;

var token_iterator = ace.require("ace/token_iterator");
var { module, asyncTest, deepEqual, start } = QUnit;
var { module, asyncTest, deepEqual, start } = window.QUnit;


module("Output Tokenization", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let _ = require('lodash');
let url_pattern_matcher = require('../../src/autocomplete/url_pattern_matcher');
let autocomplete_engine = require('../../src/autocomplete/engine');

var { test, module, deepEqual } = QUnit;
var { test, module, deepEqual } = window.QUnit;

module("Url autocomplete");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let _ = require('lodash');
let url_params = require('../../src/autocomplete/url_params');
let autocomplete_engine = require('../../src/autocomplete/engine');

var { test, module, deepEqual } = QUnit;
var { test, module, deepEqual } = window.QUnit;

module("Url params");

Expand Down
2 changes: 1 addition & 1 deletion src/core_plugins/console/public/tests/src/utils_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ let utils = require('../../src/utils');
let collapsingTests = require('raw!./utils_string_collapsing.txt');
let expandingTests = require('raw!./utils_string_expanding.txt');

var { test, module, deepEqual } = QUnit;
var { test, module, deepEqual } = window.QUnit;

module("Utils class");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import sinon from 'sinon';
import expect from 'expect.js';

import { ensureAllowExplicitIndex } from '../ensure_allow_explicit_index';

const createStubCallWithInternal = responders => (
sinon.spy(async (params) => {
if (responders.length) {
return await responders.shift()(params);
}

throw new Error('Unexpected client.mget call');
})
);

const createStubConfig = () => ({
get: sinon.spy((key) => {
switch (key) {
case 'kibana.index': return '.kibana';
case 'pkg.version': return '0.0.0';
default: throw new Error(`Unexpected config.get('${key}') call`);
}
})
});

describe('ensureAllowExplicitIndex()', () => {
it('attempts an mget with index in request', async () => {
const config = createStubConfig();
const callWithInternalUser = createStubCallWithInternal([
() => ({ ok: true })
]);

const resp = await ensureAllowExplicitIndex(callWithInternalUser, config);
expect(resp).to.be(true);
});

it(`reports "illegal_argument_exception" that mentions "explicit index"`, async () => {
const config = createStubConfig();
const callWithInternalUser = createStubCallWithInternal([
() => ({
error: {
type: 'illegal_argument_exception',
reason: 'explicit index not supported'
}
})
]);

try {
await ensureAllowExplicitIndex(callWithInternalUser, config);
throw new Error('expected ensureAllowExplicitIndex() to throw error');
} catch (error) {
expect(error.message).to.contain('rest.action.multi.allow_explicit_index');
}
});

it('reports unexpected errors', async () => {
const config = createStubConfig();
const callWithInternalUser = createStubCallWithInternal([
() => ({
error: {
type: 'foo',
reason: 'bar'
}
})
]);

try {
await ensureAllowExplicitIndex(callWithInternalUser, config);
throw new Error('expected ensureAllowExplicitIndex() to throw error');
} catch (error) {
expect(error.message).to.contain('[foo]');
expect(error.message).to.contain('bar');
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('plugins/elasticsearch', () => {

cluster = { callWithInternalUser: sinon.stub() };
cluster.callWithInternalUser.withArgs('index', sinon.match.any).returns(Promise.resolve());
cluster.callWithInternalUser.withArgs('mget', sinon.match.any).returns(Promise.resolve({ ok: true }));
cluster.callWithInternalUser.withArgs('get', sinon.match.any).returns(Promise.resolve({ found: false }));
cluster.callWithInternalUser.withArgs('search', sinon.match.any).returns(Promise.resolve({ hits: { hits: [] } }));
cluster.callWithInternalUser.withArgs('nodes.info', sinon.match.any).returns(Promise.resolve({
Expand Down
9 changes: 9 additions & 0 deletions src/core_plugins/elasticsearch/lib/__tests__/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,27 @@ describe('plugins/elasticsearch', function () {
testRoute({
method: 'POST',
url: '/elasticsearch/.kibana/__kibanaQueryValidator/_validate/query?explain=true&ignore_unavailable=true',
headers: {
'content-type': 'application/json'
},
payload: { query: { query_string: { analyze_wildcard: true, query: '*' } } }
});

testRoute({
method: 'POST',
url: '/elasticsearch/_mget',
headers: {
'content-type': 'application/json'
},
payload: { docs: [{ _index: '.kibana', _type: 'index-pattern', _id: '[logstash-]YYYY.MM.DD' }] }
});

testRoute({
method: 'POST',
url: '/elasticsearch/_msearch',
headers: {
'content-type': 'application/json'
},
payload: '{"index":"logstash-2015.04.21","ignore_unavailable":true}\n{"size":500,"sort":{"@timestamp":"desc"},"query":{"bool":{"must":[{"query_string":{"analyze_wildcard":true,"query":"*"}},{"bool":{"must":[{"range":{"@timestamp":{"gte":1429577068175,"lte":1429577968175}}}],"must_not":[]}}],"must_not":[]}},"highlight":{"pre_tags":["@kibana-highlighted-field@"],"post_tags":["@/kibana-highlighted-field@"],"fields":{"*":{}}},"aggs":{"2":{"date_histogram":{"field":"@timestamp","interval":"30s","min_doc_count":0,"extended_bounds":{"min":1429577068175,"max":1429577968175}}}},"stored_fields":["*"],"_source": true,"script_fields":{},"docvalue_fields":["timestamp_offset","@timestamp","utc_time"]}\n' // eslint-disable-line max-len
});

Expand Down
36 changes: 36 additions & 0 deletions src/core_plugins/elasticsearch/lib/ensure_allow_explicit_index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export async function ensureAllowExplicitIndex(callWithInternalUser, config) {
const resp = await callWithInternalUser('mget', {
ignore: [400],
body: {
docs: [
{
_index: config.get('kibana.index'),
_type: 'config',
_id: config.get('pkg.version'),
},
],
},
});

if (!resp.error) {
return true;
}

const error = resp.error || {};
const errorReason = error.reason || '';

const isArgError = error.type === 'illegal_argument_exception';
const isExplicitIndexException = isArgError && errorReason.includes('explicit index');

if (isExplicitIndexException) {
throw new Error(
'Kibana must be able to specify the index within Elasticsearch multi-requests ' +
'(rest.action.multi.allow_explicit_index=true).'
);
}

throw new Error(
'Unable to ensure that rest.action.multi.allow_explicit_index=true: ' +
`[${error.type}] ${errorReason}`
);
}
4 changes: 3 additions & 1 deletion src/core_plugins/elasticsearch/lib/health_check.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import createKibanaIndex from './create_kibana_index';
import kibanaVersion from './kibana_version';
import { ensureEsVersion } from './ensure_es_version';
import { ensureNotTribe } from './ensure_not_tribe';
import { ensureAllowExplicitIndex } from './ensure_allow_explicit_index';

const NoConnections = elasticsearch.errors.NoConnections;
import util from 'util';
Expand Down Expand Up @@ -94,7 +95,8 @@ module.exports = function (plugin, server) {
const healthCheck =
waitForPong(callAdminAsKibanaUser, config.get('elasticsearch.url'))
.then(waitForEsVersion)
.then(ensureNotTribe.bind(this, callAdminAsKibanaUser))
.then(() => ensureNotTribe(callAdminAsKibanaUser))
.then(() => ensureAllowExplicitIndex(callAdminAsKibanaUser, config))
.then(waitForShards)
.then(_.partial(migrateConfig, server))
.then(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ module.directive('vislibSeries', function () {
});

// update labels for existing params or create new one
$scope.vis.params.seriesParams = metrics.map((agg, i) => {
const params = $scope.vis.params.seriesParams[i];
$scope.vis.params.seriesParams = metrics.map(agg => {
const params = $scope.vis.params.seriesParams.find(param => param.data.id === agg.id);
if (params) {
params.data.id = agg.id;
params.data.label = agg.makeLabel();
return params;
} else {
Expand All @@ -74,11 +73,11 @@ module.directive('vislibSeries', function () {

$scope.changeValueAxis = (index) => {
const series = $scope.vis.params.seriesParams[index];
$scope.updateAxisTitle();
if (series.valueAxis === 'new') {
const axis = $scope.addValueAxis();
series.valueAxis = axis.id;
}
$scope.updateAxisTitle();
};
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/core_plugins/kibana/public/management/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
ng-if="sectionName"
ng-repeat="item in section.visibleItems"
class="kuiLocalTab"
ng-class="{ 'kuiLocalTab-isSelected': item.active, 'kuiLocalTab-disabled': item.disabled || !item.url }"
ng-class="{ 'kuiLocalTab-isSelected': item.active, 'kuiLocalTab-isDisabled': !item.active && (item.disabled || !item.url) }"
kbn-href="{{::item.disabled ? '' : item.url}}"
data-test-subj="{{::item.name}}"
tooltip="{{::item.tooltip}}"
Expand Down
Loading