Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastic/kibana into renameAllFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Mar 15, 2016
2 parents caf7331 + 6a1e087 commit d77de4e
Show file tree
Hide file tree
Showing 18 changed files with 224 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ So, you've been assigned a pull to review. What's that look like?

Remember, someone is blocked by a pull awaiting review, make it count. Be thorough, the more action items you catch in the first review, the less back and forth will be required, and the better chance the pull has of being successful. Don't you like success?

1. **Understand the issue** that is being fixed, or the feature being added. Check the description on the pull, and check out the related issue. If you don't understand something, ask the person the submitter for clarification.
1. **Understand the issue** that is being fixed, or the feature being added. Check the description on the pull, and check out the related issue. If you don't understand something, ask the submitter for clarification.
1. **Reproduce the bug** (or the lack of feature I guess?) in the destination branch, usually `master`. The referenced issue will help you here. If you're unable to reproduce the issue, contact the issue submitter for clarification
1. **Check out the pull** and test it. Is the issue fixed? Does it have nasty side effects? Try to create suspect inputs. If it operates on the value of a field try things like: strings (including an empty string), null, numbers, dates. Try to think of edge cases that might break the code.
1. **Merge the target branch**. It is possible that tests or the linter have been updated in the target branch since the pull was submitted. Merging the pull could cause core to start failing.
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
"grunt-cli": "0.1.13",
"grunt-contrib-clean": "0.6.0",
"grunt-contrib-copy": "0.8.1",
"grunt-esvm": "2.1.1",
"grunt-esvm": "3.0.3",
"grunt-karma": "0.12.0",
"grunt-run": "0.5.0",
"grunt-s3": "0.2.0-alpha.3",
Expand All @@ -174,7 +174,6 @@
"karma-ie-launcher": "0.2.0",
"karma-mocha": "0.2.0",
"karma-safari-launcher": "0.1.1",
"libesvm": "3.3.0",
"license-checker": "3.1.0",
"load-grunt-config": "0.19.1",
"makelogs": "3.0.0-beta3",
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/elasticsearch/lib/__tests__/check_es_version.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import _ from 'lodash';
import Promise from 'bluebird';
import sinon from 'sinon';
import url from 'url';

import serverConfig from '../../../../../test/server_config';
import checkEsVersion from '../check_es_version';

describe('plugins/elasticsearch', function () {
Expand All @@ -23,7 +25,7 @@ describe('plugins/elasticsearch', function () {
status: {
red: sinon.stub()
},
url: 'http://localhost:9210'
url: url.format(serverConfig.servers.elasticsearch)
}
}
};
Expand Down
16 changes: 11 additions & 5 deletions src/plugins/elasticsearch/lib/__tests__/health_check.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import Promise from 'bluebird';
import sinon from 'sinon';
import expect from 'expect.js';
import url from 'url';

const NoConnections = require('elasticsearch').errors.NoConnections;

import healthCheck from '../health_check';
import serverConfig from '../../../../../test/server_config';

const esPort = serverConfig.servers.elasticsearch.port;
const esUrl = url.format(serverConfig.servers.elasticsearch);

describe('plugins/elasticsearch', function () {
describe('lib/health_check', function () {
Expand Down Expand Up @@ -39,7 +45,7 @@ describe('plugins/elasticsearch', function () {
nodes: {
'node-01': {
version: '1.5.0',
http_address: 'inet[/127.0.0.1:9210]',
http_address: `inet[/127.0.0.1:${esPort}]`,
ip: '127.0.0.1'
}
}
Expand Down Expand Up @@ -73,7 +79,7 @@ describe('plugins/elasticsearch', function () {

it('should set the cluster red if the ping fails, then to green', function () {

get.withArgs('elasticsearch.url').returns('http://localhost:9210');
get.withArgs('elasticsearch.url').returns(esUrl);
get.withArgs('elasticsearch.engineVersion').returns('^1.4.4');
get.withArgs('kibana.index').returns('.my-kibana');
client.ping.onCall(0).returns(Promise.reject(new NoConnections()));
Expand All @@ -85,7 +91,7 @@ describe('plugins/elasticsearch', function () {
expect(plugin.status.yellow.args[0][0]).to.be('Waiting for Elasticsearch');
sinon.assert.calledOnce(plugin.status.red);
expect(plugin.status.red.args[0][0]).to.be(
'Unable to connect to Elasticsearch at http://localhost:9210.'
`Unable to connect to Elasticsearch at ${esUrl}.`
);
sinon.assert.calledTwice(client.ping);
sinon.assert.calledOnce(client.nodes.info);
Expand All @@ -97,7 +103,7 @@ describe('plugins/elasticsearch', function () {
});

it('should set the cluster red if the health check status is red, then to green', function () {
get.withArgs('elasticsearch.url').returns('http://localhost:9210');
get.withArgs('elasticsearch.url').returns(esUrl);
get.withArgs('elasticsearch.engineVersion').returns('^1.4.4');
get.withArgs('kibana.index').returns('.my-kibana');
client.ping.returns(Promise.resolve());
Expand All @@ -120,7 +126,7 @@ describe('plugins/elasticsearch', function () {
});

it('should set the cluster yellow if the health check timed_out and create index', function () {
get.withArgs('elasticsearch.url').returns('http://localhost:9210');
get.withArgs('elasticsearch.url').returns(esUrl);
get.withArgs('elasticsearch.engineVersion').returns('^1.4.4');
get.withArgs('kibana.index').returns('.my-kibana');
client.ping.returns(Promise.resolve());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ module.exports = function registerDelete(server) {
path: '/api/kibana/ingest/{id}',
method: 'DELETE',
handler: function (req, reply) {
const kibanaIndex = server.config().get('kibana.index');
const callWithRequest = server.plugins.elasticsearch.callWithRequest;
const deletePatternParams = {
index: '.kibana',
index: kibanaIndex,
type: 'index-pattern',
id: req.params.id
};
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/kibana/server/routes/api/ingest/register_post.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = function registerPost(server) {
}
},
handler: function (req, reply) {
const kibanaIndex = server.config().get('kibana.index');
const callWithRequest = server.plugins.elasticsearch.callWithRequest;
const requestDocument = _.cloneDeep(req.payload);
const indexPatternId = requestDocument.id;
Expand All @@ -36,7 +37,7 @@ module.exports = function registerPost(server) {
}

const patternCreateParams = {
index: '.kibana',
index: kibanaIndex,
type: 'index-pattern',
id: indexPatternId,
body: indexPattern
Expand Down Expand Up @@ -74,7 +75,7 @@ module.exports = function registerPost(server) {
return callWithRequest(req, 'indices.putTemplate', templateParams)
.catch((templateError) => {
const deleteParams = {
index: '.kibana',
index: kibanaIndex,
type: 'index-pattern',
id: indexPatternId
};
Expand Down
1 change: 1 addition & 0 deletions src/ui/public/stringify/__tests__/_conformance.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var config;
var formatIds = [
'bytes',
'date',
'duration',
'ip',
'number',
'percent',
Expand Down
50 changes: 50 additions & 0 deletions src/ui/public/stringify/__tests__/_duration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import expect from 'expect.js';
import ngMock from 'ng_mock';
import RegistryFieldFormatsProvider from 'ui/registry/field_formats';

describe('Duration Format', function () {
let fieldFormats;
let DurationFormat;

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
fieldFormats = Private(RegistryFieldFormatsProvider);
DurationFormat = fieldFormats.getType('duration');
}));

test({ inputFormat: 'seconds', outputFormat: 'humanize' })
(-60, 'minus a minute')
(60, 'a minute')
(125, '2 minutes');

test({ inputFormat: 'minutes', outputFormat: 'humanize' })
(-60, 'minus an hour')
(60, 'an hour')
(125, '2 hours');

test({ inputFormat: 'minutes', outputFormat: 'asHours' }) // outputPrecision defaults to: 2
(-60, '-1.00')
(60, '1.00')
(125, '2.08');

test({ inputFormat: 'seconds', outputFormat: 'asSeconds', outputPrecision: 0 })
(-60, '-60')
(60, '60')
(125, '125');

test({ inputFormat: 'seconds', outputFormat: 'asSeconds', outputPrecision: 2 })
(-60, '-60.00')
(-32.333, '-32.33')
(60, '60.00')
(125, '125.00');

function test({ inputFormat, outputFormat, outputPrecision }) {
return function testFixture(input, output) {
it(`should format ${input} ${inputFormat} through ${outputFormat}${outputPrecision ? `, ${outputPrecision} decimals` : ''}`, () => {
const duration = new DurationFormat({ inputFormat, outputFormat, outputPrecision });
expect(duration.convert(input)).to.eql(output);
});
return testFixture;
};
}
});
1 change: 1 addition & 0 deletions src/ui/public/stringify/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import './_string';
import './_url';
import './_color';
import './_date';
import './_duration';
import './_truncate';
describe('Stringify Component', function () {
});
28 changes: 28 additions & 0 deletions src/ui/public/stringify/editors/duration.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<div class="editor-duration">
<div class="form-group">
<label>Input Format</label>
<select
ng-model="editor.formatParams.inputFormat"
ng-options="inputFormat.kind as inputFormat.text for inputFormat in editor.field.format.type.inputFormats"
class="form-control">
</select>
</div>
<div class="form-group">
<label>Output Format</label>
<select
ng-model="editor.formatParams.outputFormat"
ng-options="outputFormat.method as outputFormat.text for outputFormat in editor.field.format.type.outputFormats"
class="form-control">
</select>
</div>
<div class="form-group" ng-hide="editor.field.format.isHuman()">
<label>Decimal Places</label>
<input type="number" min="0" max="20" ng-model="editor.formatParams.outputPrecision" class="form-control" />
</div>
</div>
<div>
<field-format-editor-samples
ng-model="editor.formatParams"
inputs="cntrl.sampleInputs">
</field-format-editor-samples>
</div>
10 changes: 10 additions & 0 deletions src/ui/public/stringify/editors/duration.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.editor-duration {
display: flex;
> .form-group {
flex: 1 1 1%;
padding-right: 5px;
&:last-child {
padding-right: 0;
}
}
}
3 changes: 3 additions & 0 deletions src/ui/public/stringify/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ import fieldFormats from 'ui/registry/field_formats';
import stringifyUrl from 'ui/stringify/types/url';
import stringifyBytes from 'ui/stringify/types/bytes';
import stringifyDate from 'ui/stringify/types/date';
import stringifyDuration from 'ui/stringify/types/duration';
import stringifyIp from 'ui/stringify/types/ip';
import stringifyNumber from 'ui/stringify/types/number';
import stringifyPercent from 'ui/stringify/types/percent';
import stringifyString from 'ui/stringify/types/string';
import stringifySource from 'ui/stringify/types/source';
import stringifyColor from 'ui/stringify/types/color';
import stringifyTruncate from 'ui/stringify/types/truncate';

fieldFormats.register(stringifyUrl);
fieldFormats.register(stringifyBytes);
fieldFormats.register(stringifyDate);
fieldFormats.register(stringifyDuration);
fieldFormats.register(stringifyIp);
fieldFormats.register(stringifyNumber);
fieldFormats.register(stringifyPercent);
Expand Down
98 changes: 98 additions & 0 deletions src/ui/public/stringify/types/duration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import 'ui/stringify/editors/duration.less';
import _ from 'lodash';
import moment from 'moment';
import IndexPatternsFieldFormatProvider from 'ui/index_patterns/_field_format/field_format';
import durationTemplate from 'ui/stringify/editors/duration.html';

export default function DurationFormatProvider(Private) {
const ratioToSeconds = {
picoseconds: 0.000000000001,
nanoseconds: 0.000000001,
microseconds: 0.000001
};
const FieldFormat = Private(IndexPatternsFieldFormatProvider);
const HUMAN_FRIENDLY = 'humanize';
const DEFAULT_OUTPUT_PRECISION = 2;
const DEFAULT_INPUT_FORMAT = { text: 'Seconds', kind: 'seconds' };
const inputFormats = [
{ text: 'Picoseconds', kind: 'picoseconds' },
{ text: 'Nanoseconds', kind: 'nanoseconds' },
{ text: 'Microseconds', kind: 'microseconds' },
{ text: 'Milliseconds', kind: 'milliseconds' },
DEFAULT_INPUT_FORMAT,
{ text: 'Minutes', kind: 'minutes' },
{ text: 'Hours', kind: 'hours' },
{ text: 'Days', kind: 'days' },
{ text: 'Weeks', kind: 'weeks' },
{ text: 'Months', kind: 'months' },
{ text: 'Years', kind: 'years' }
];
const DEFAULT_OUTPUT_FORMAT = { text: 'Human Readable', method: 'humanize' };
const outputFormats = [
DEFAULT_OUTPUT_FORMAT,
{ text: 'Milliseconds', method: 'asMilliseconds' },
{ text: 'Seconds', method: 'asSeconds' },
{ text: 'Minutes', method: 'asMinutes' },
{ text: 'Hours', method: 'asHours' },
{ text: 'Days', method: 'asDays' },
{ text: 'Weeks', method: 'asWeeks' },
{ text: 'Months', method: 'asMonths' },
{ text: 'Years', method: 'asYears' }
];

class Duration extends FieldFormat {
isHuman() {
return this.param('outputFormat') === HUMAN_FRIENDLY;
}
_convert(val) {
const inputFormat = this.param('inputFormat');
const outputFormat = this.param('outputFormat');
const outputPrecision = this.param('outputPrecision');
const human = this.isHuman();
const prefix = val < 0 && human ? 'minus ' : '';
const duration = parseInputAsDuration(val, inputFormat);
const formatted = duration[outputFormat]();
const precise = human ? formatted : formatted.toFixed(outputPrecision);
return prefix + precise;
}
}

Duration.id = 'duration';
Duration.title = 'Duration';
Duration.fieldType = 'number';

Duration.inputFormats = inputFormats;
Duration.outputFormats = outputFormats;

Duration.editor = {
template: durationTemplate,
controllerAs: 'cntrl',
controller($scope, $interval) {
this.sampleInputs = [
-123,
1,
12,
123,
658,
1988,
3857,
123292,
923528271
];
}
};

Duration.paramDefaults = {
inputFormat: DEFAULT_INPUT_FORMAT.kind,
outputFormat: DEFAULT_OUTPUT_FORMAT.method,
outputPrecision: DEFAULT_OUTPUT_PRECISION
};

return Duration;

function parseInputAsDuration(val, inputFormat) {
const ratio = ratioToSeconds[inputFormat] || 1;
const kind = inputFormat in ratioToSeconds ? 'seconds' : inputFormat;
return moment.duration(val * ratio, kind);
}
};
5 changes: 4 additions & 1 deletion src/ui/public/utils/__tests__/scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import Bluebird from 'bluebird';
import 'elasticsearch-browser';
import ngMock from 'ng_mock';
import sinon from 'sinon';
import url from 'url';

import serverConfig from '../../../../../test/server_config';

describe('Scanner', function () {
let es;

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (esFactory) {
es = esFactory({
host: 'http://localhost:9210',
host: url.format(serverConfig.servers.elasticsearch),
defer: function () {
return Bluebird.defer();
}
Expand Down
Loading

0 comments on commit d77de4e

Please sign in to comment.