diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6cbdae5c3e23..19dffe7114a1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. diff --git a/config/kibana.yml b/config/kibana.yml index 0f506c91579b..37c4292d6e42 100644 --- a/config/kibana.yml +++ b/config/kibana.yml @@ -19,7 +19,7 @@ # that connects to this Kibana instance. # elasticsearch.preserveHost: true -# Kibana uses an index in Elasticsearch to store saved searches, visualizations and +# 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.index: ".kibana" @@ -28,12 +28,12 @@ # If your Elasticsearch is protected with basic authentication, these settings provide # the username and password that the Kibana server uses to perform maintenance on the Kibana -# index at startup. Your Kibana users still need to authenticate with Elasticsearch, which +# index at startup. Your Kibana users still need to authenticate with Elasticsearch, which # is proxied through the Kibana server. # elasticsearch.username: "user" # elasticsearch.password: "pass" -# Paths to the PEM-format SSL certificate and SSL key files, respectively. These +# Paths to the PEM-format SSL certificate and SSL key files, respectively. These # files enable SSL for outgoing requests from the Kibana server to the browser. # server.ssl.cert: /path/to/your/server.crt # server.ssl.key: /path/to/your/server.key @@ -43,7 +43,7 @@ # elasticsearch.ssl.cert: /path/to/your/client.crt # elasticsearch.ssl.key: /path/to/your/client.key -# Optional setting that enables you to specify a path to the PEM file for the certificate +# Optional setting that enables you to specify a path to the PEM file for the certificate # authority for your Elasticsearch instance. # elasticsearch.ssl.ca: /path/to/your/CA.pem @@ -54,7 +54,7 @@ # the elasticsearch.requestTimeout setting. # elasticsearch.pingTimeout: 1500 -# Time in milliseconds to wait for responses from the back end or Elasticsearch. This value +# Time in milliseconds to wait for responses from the back end or Elasticsearch. This value # must be a positive integer. # elasticsearch.requestTimeout: 30000 @@ -76,6 +76,10 @@ # Set the value of this setting to true to suppress all logging output other than error messages. # logging.quiet: false -# Set the value of this setting to true to log all events, including system usage information +# Set the value of this setting to true to log all events, including system usage information # and all requests. # logging.verbose: false + +# Set the interval in milliseconds to sample system and process performance +# metrics. Minimum is 100ms. Defaults to 10000. +# ops.interval: 10000 diff --git a/docs/kibana-yml.asciidoc b/docs/kibana-yml.asciidoc index 310ca2005f00..3e0e4ded41a8 100644 --- a/docs/kibana-yml.asciidoc +++ b/docs/kibana-yml.asciidoc @@ -39,3 +39,4 @@ retrying. error messages. `logging.verbose`:: *Default: false* Set the value of this setting to `true` to log all events, including system usage information and all requests. +`ops.interval`:: *Default: 10000* Set the interval in milliseconds to sample system and process performance metrics. Minimum is 100ms. Defaults to 10 seconds. diff --git a/docs/x-axis-aggs.asciidoc b/docs/x-axis-aggs.asciidoc index a39eb8a48a20..802625b0afac 100644 --- a/docs/x-axis-aggs.asciidoc +++ b/docs/x-axis-aggs.asciidoc @@ -28,7 +28,7 @@ remove a range. or bottom _n_ elements of a given field to display, ordered by count or a custom metric. *Filters*:: You can specify a set of {ref}/search-aggregations-bucket-filters-aggregation.html[_filters_] for the data. You can specify a filter as a query string or in JSON format, just as in the Discover search bar. Click *Add Filter* to -add another filter. Click the images:labelbutton.png[] *label* button to open the label field, where you can type in a +add another filter. Click the image:images/labelbutton.png[] *label* button to open the label field, where you can type in a name to display on the visualization. *Significant Terms*:: Displays the results of the experimental {ref}/search-aggregations-bucket-significantterms-aggregation.html[_significant terms_] aggregation. diff --git a/package.json b/package.json index c4e6ba5202e2..54d63bb954fc 100644 --- a/package.json +++ b/package.json @@ -87,9 +87,9 @@ "babel-runtime": "5.8.20", "bluebird": "2.9.34", "boom": "2.8.0", - "bootstrap": "3.3.5", + "bootstrap": "3.3.6", "brace": "0.5.1", - "bunyan": "1.4.0", + "bunyan": "1.7.1", "clipboard": "1.5.5", "commander": "2.8.1", "css-loader": "0.17.0", @@ -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", @@ -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.7.2", "makelogs": "3.0.0-beta3", diff --git a/src/plugins/elasticsearch/index.js b/src/plugins/elasticsearch/index.js index b9debc020ec6..76a44285d9ef 100644 --- a/src/plugins/elasticsearch/index.js +++ b/src/plugins/elasticsearch/index.js @@ -54,7 +54,7 @@ module.exports = function ({ Plugin }) { return reply.continue(); } - function noCreateIndex({ path }, reply) { + function noDirectIndex({ path }, reply) { const requestPath = trimRight(trim(path), '/'); const matchPath = createPath(kibanaIndex); @@ -75,7 +75,7 @@ module.exports = function ({ Plugin }) { ['PUT', 'POST', 'DELETE'], `/${kibanaIndex}/{paths*}`, { - pre: [ noCreateIndex, noBulkCheck ] + pre: [ noDirectIndex, noBulkCheck ] } ); diff --git a/src/plugins/elasticsearch/lib/__tests__/check_es_version.js b/src/plugins/elasticsearch/lib/__tests__/check_es_version.js index 51424a841af4..1c1ece01c412 100644 --- a/src/plugins/elasticsearch/lib/__tests__/check_es_version.js +++ b/src/plugins/elasticsearch/lib/__tests__/check_es_version.js @@ -1,7 +1,9 @@ import _ from 'lodash'; import Promise from 'bluebird'; import sinon from 'sinon'; +import url from 'url'; +import serverConfig from '../../../../../test/serverConfig'; import checkEsVersion from '../check_es_version'; describe('plugins/elasticsearch', function () { @@ -23,7 +25,7 @@ describe('plugins/elasticsearch', function () { status: { red: sinon.stub() }, - url: 'http://localhost:9210' + url: url.format(serverConfig.servers.elasticsearch) } } }; diff --git a/src/plugins/elasticsearch/lib/__tests__/health_check.js b/src/plugins/elasticsearch/lib/__tests__/health_check.js index 3292ba67abb0..5065e7bc59ce 100644 --- a/src/plugins/elasticsearch/lib/__tests__/health_check.js +++ b/src/plugins/elasticsearch/lib/__tests__/health_check.js @@ -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/serverConfig'; + +const esPort = serverConfig.servers.elasticsearch.port; +const esUrl = url.format(serverConfig.servers.elasticsearch); describe('plugins/elasticsearch', function () { describe('lib/health_check', function () { @@ -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' } } @@ -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())); @@ -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); @@ -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()); @@ -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()); diff --git a/src/plugins/kibana/public/dashboard/index.html b/src/plugins/kibana/public/dashboard/index.html index 9a3f94fa3832..6a4353e0bc29 100644 --- a/src/plugins/kibana/public/dashboard/index.html +++ b/src/plugins/kibana/public/dashboard/index.html @@ -1,6 +1,6 @@
- +
Quick Count ( - {{::field.details.exists}} - {{::field.details.exists}} + + {{::field.details.exists}} + + + {{::field.details.exists}} + /{{::field.details.total}} records ) diff --git a/src/server/config/schema.js b/src/server/config/schema.js index 6f000908579f..e6306282c2fc 100644 --- a/src/server/config/schema.js +++ b/src/server/config/schema.js @@ -81,6 +81,10 @@ module.exports = () => Joi.object({ }) .default(), + ops: Joi.object({ + interval: Joi.number().default(10000), + }), + plugins: Joi.object({ paths: Joi.array().items(Joi.string()).default([]), scanDirs: Joi.array().items(Joi.string()).default([]), diff --git a/src/server/logging/index.js b/src/server/logging/index.js index ba3bbe3ece35..7164216e15a6 100644 --- a/src/server/logging/index.js +++ b/src/server/logging/index.js @@ -39,7 +39,7 @@ module.exports = function (kbnServer, server, config) { server.register({ register: require('good'), options: { - opsInterval: 5000, + opsInterval: config.get('ops.interval'), requestHeaders: true, requestPayload: true, reporters: [ diff --git a/src/ui/public/agg_types/__tests__/buckets/_histogram.js b/src/ui/public/agg_types/__tests__/buckets/_histogram.js index 0aa6a3122bd5..ea14171d32e6 100644 --- a/src/ui/public/agg_types/__tests__/buckets/_histogram.js +++ b/src/ui/public/agg_types/__tests__/buckets/_histogram.js @@ -82,6 +82,7 @@ describe('Histogram Agg', function () { describe('extended_bounds', function () { it('writes when only eb.min is set', function () { var output = paramWriter.write({ + min_doc_count: true, extended_bounds: { min: 0 } }); expect(output.params.extended_bounds).to.have.property('min', 0); @@ -90,6 +91,7 @@ describe('Histogram Agg', function () { it('writes when only eb.max is set', function () { var output = paramWriter.write({ + min_doc_count: true, extended_bounds: { max: 0 } }); expect(output.params.extended_bounds).to.have.property('min', undefined); @@ -98,6 +100,7 @@ describe('Histogram Agg', function () { it('writes when both eb.min and eb.max are set', function () { var output = paramWriter.write({ + min_doc_count: true, extended_bounds: { min: 99, max: 100 } }); expect(output.params.extended_bounds).to.have.property('min', 99); @@ -106,10 +109,19 @@ describe('Histogram Agg', function () { it('does not write when nothing is set', function () { var output = paramWriter.write({ + min_doc_count: true, extended_bounds: {} }); expect(output.params).to.not.have.property('extended_bounds'); }); + + it('does not write when min_doc_count is false', function () { + var output = paramWriter.write({ + min_doc_count: false, + extended_bounds: { min: 99, max: 100 } + }); + expect(output.params).to.not.have.property('extended_bounds'); + }); }); }); }); diff --git a/src/ui/public/agg_types/buckets/filters.js b/src/ui/public/agg_types/buckets/filters.js index b5f5fd4c01e3..af54504c8fa3 100644 --- a/src/ui/public/agg_types/buckets/filters.js +++ b/src/ui/public/agg_types/buckets/filters.js @@ -2,12 +2,12 @@ import _ from 'lodash'; import angular from 'angular'; import AggTypesBucketsBucketAggTypeProvider from 'ui/agg_types/buckets/_bucket_agg_type'; import AggTypesBucketsCreateFilterFiltersProvider from 'ui/agg_types/buckets/create_filter/filters'; -import CourierDataSourceDecorateQueryProvider from 'ui/courier/data_source/_decorate_query'; +import DecorateQueryProvider from 'ui/courier/data_source/_decorate_query'; import filtersTemplate from 'ui/agg_types/controls/filters.html'; export default function FiltersAggDefinition(Private, Notifier) { var BucketAggType = Private(AggTypesBucketsBucketAggTypeProvider); var createFilter = Private(AggTypesBucketsCreateFilterFiltersProvider); - var decorateQuery = Private(CourierDataSourceDecorateQueryProvider); + var decorateQuery = Private(DecorateQueryProvider); var notif = new Notifier({ location: 'Filters Agg' }); return new BucketAggType({ diff --git a/src/ui/public/agg_types/buckets/histogram.js b/src/ui/public/agg_types/buckets/histogram.js index 14d292444b83..344ab964d005 100644 --- a/src/ui/public/agg_types/buckets/histogram.js +++ b/src/ui/public/agg_types/buckets/histogram.js @@ -51,7 +51,7 @@ export default function HistogramAggDefinition(Private) { write: function (aggConfig, output) { var val = aggConfig.params.extended_bounds; - if (val.min != null || val.max != null) { + if (aggConfig.params.min_doc_count && (val.min != null || val.max != null)) { output.params.extended_bounds = { min: val.min, max: val.max diff --git a/src/ui/public/config/config.js b/src/ui/public/config/config.js index 486e5c4929b2..8bb289a0aae7 100644 --- a/src/ui/public/config/config.js +++ b/src/ui/public/config/config.js @@ -3,7 +3,7 @@ import _ from 'lodash'; import ConfigDefaultsProvider from 'ui/config/defaults'; import ConfigDelayedUpdaterProvider from 'ui/config/_delayed_updater'; import ConfigValsProvider from 'ui/config/_vals'; -import CourierDataSourceDocSourceProvider from 'ui/courier/data_source/doc_source'; +import DocSourceProvider from 'ui/courier/data_source/doc_source'; import uiRoutes from 'ui/routes'; import uiModules from 'ui/modules'; import Notifier from 'ui/notify/notifier'; @@ -30,7 +30,7 @@ module.service('config', function (Private, kbnVersion, kbnIndex, $rootScope, bu // update once it is requested by calling #set() or #clear(). var updater; - var DocSource = Private(CourierDataSourceDocSourceProvider); + var DocSource = Private(DocSourceProvider); var doc = (new DocSource()) .index(kbnIndex) .type('config') diff --git a/src/ui/public/courier/courier.js b/src/ui/public/courier/courier.js index 6fdc80e00d4d..486d5bcb20e8 100644 --- a/src/ui/public/courier/courier.js +++ b/src/ui/public/courier/courier.js @@ -1,45 +1,48 @@ -import errors from 'ui/errors'; import _ from 'lodash'; + +import errors from 'ui/errors'; import 'ui/es'; import 'ui/promises'; import 'ui/safe_confirm'; import 'ui/index_patterns'; -import CourierDataSourceDocSourceProvider from 'ui/courier/data_source/doc_source'; -import CourierDataSourceSearchSourceProvider from 'ui/courier/data_source/search_source'; -import CourierFetchStrategySearchProvider from 'ui/courier/fetch/strategy/search'; -import CourierRequestQueueProvider from 'ui/courier/_request_queue'; -import CourierErrorHandlersProvider from 'ui/courier/_error_handlers'; -import CourierFetchFetchProvider from 'ui/courier/fetch/fetch'; -import CourierLooperDocProvider from 'ui/courier/looper/doc'; -import CourierLooperSearchProvider from 'ui/courier/looper/search'; -import CourierDataSourceRootSearchSourceProvider from 'ui/courier/data_source/_root_search_source'; -import CourierSavedObjectSavedObjectProvider from 'ui/courier/saved_object/saved_object'; -import CourierRedirectWhenMissingProvider from 'ui/courier/_redirect_when_missing'; import uiModules from 'ui/modules'; +import Notifier from 'ui/notify/notifier'; + +import DocSourceProvider from './data_source/doc_source'; +import SearchSourceProvider from './data_source/search_source'; +import SearchStrategyProvider from './fetch/strategy/search'; +import RequestQueueProvider from './_request_queue'; +import ErrorHandlersProvider from './_error_handlers'; +import FetchProvider from './fetch'; +import DocLooperProvider from './looper/doc'; +import SearchLooperProvider from './looper/search'; +import RootSearchSourceProvider from './data_source/_root_search_source'; +import SavedObjectProvider from './saved_object'; +import RedirectWhenMissingProvider from './_redirect_when_missing'; uiModules.get('kibana/courier') -.service('courier', function ($rootScope, Private, Promise, indexPatterns, Notifier) { +.service('courier', function ($rootScope, Private, Promise, indexPatterns) { function Courier() { var self = this; - var DocSource = Private(CourierDataSourceDocSourceProvider); - var SearchSource = Private(CourierDataSourceSearchSourceProvider); - var searchStrategy = Private(CourierFetchStrategySearchProvider); + var DocSource = Private(DocSourceProvider); + var SearchSource = Private(SearchSourceProvider); + var searchStrategy = Private(SearchStrategyProvider); - var requestQueue = Private(CourierRequestQueueProvider); - var errorHandlers = Private(CourierErrorHandlersProvider); + var requestQueue = Private(RequestQueueProvider); + var errorHandlers = Private(ErrorHandlersProvider); - var fetch = Private(CourierFetchFetchProvider); - var docLooper = self.docLooper = Private(CourierLooperDocProvider); - var searchLooper = self.searchLooper = Private(CourierLooperSearchProvider); + var fetch = Private(FetchProvider); + var docLooper = self.docLooper = Private(DocLooperProvider); + var searchLooper = self.searchLooper = Private(SearchLooperProvider); // expose some internal modules - self.setRootSearchSource = Private(CourierDataSourceRootSearchSourceProvider).set; + self.setRootSearchSource = Private(RootSearchSourceProvider).set; - self.SavedObject = Private(CourierSavedObjectSavedObjectProvider); + self.SavedObject = Private(SavedObjectProvider); self.indexPatterns = indexPatterns; - self.redirectWhenMissing = Private(CourierRedirectWhenMissingProvider); + self.redirectWhenMissing = Private(RedirectWhenMissingProvider); self.DocSource = DocSource; self.SearchSource = SearchSource; diff --git a/src/ui/public/courier/data_source/__tests__/decorate_query.js b/src/ui/public/courier/data_source/__tests__/decorate_query.js index 68faabfe947e..c6aab0007cd8 100644 --- a/src/ui/public/courier/data_source/__tests__/decorate_query.js +++ b/src/ui/public/courier/data_source/__tests__/decorate_query.js @@ -2,7 +2,7 @@ import moment from 'moment'; import expect from 'expect.js'; import ngMock from 'ngMock'; import _ from 'lodash'; -import CourierDataSourceDecorateQueryProvider from 'ui/courier/data_source/_decorate_query'; +import DecorateQueryProvider from 'ui/courier/data_source/_decorate_query'; describe('Query decorator', function () { @@ -29,7 +29,7 @@ describe('Query decorator', function () { beforeEach(ngMock.inject(function (Private, $injector, _config_) { config = _config_; - fn = Private(CourierDataSourceDecorateQueryProvider); + fn = Private(DecorateQueryProvider); })); it('should be a function', function () { diff --git a/src/ui/public/courier/data_source/__tests__/normalize_sort_request.js b/src/ui/public/courier/data_source/__tests__/normalize_sort_request.js index 1c255c8383db..00cdcc8f2605 100644 --- a/src/ui/public/courier/data_source/__tests__/normalize_sort_request.js +++ b/src/ui/public/courier/data_source/__tests__/normalize_sort_request.js @@ -1,19 +1,17 @@ import 'ui/private'; import ngMock from 'ngMock'; import expect from 'expect.js'; -import CourierDataSourceNormalizeSortRequestProvider from 'ui/courier/data_source/_normalize_sort_request'; +import NormalizeSortRequestProvider from 'ui/courier/data_source/_normalize_sort_request'; import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern'; describe('SearchSource#normalizeSortRequest', function () { - - var normalizeSortRequest; var indexPattern; var normalizedSort; beforeEach(ngMock.module('kibana')); beforeEach(ngMock.inject(function (Private) { - normalizeSortRequest = Private(CourierDataSourceNormalizeSortRequestProvider); + normalizeSortRequest = Private(NormalizeSortRequestProvider); indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider); normalizedSort = [{ diff --git a/src/ui/public/courier/data_source/_abstract.js b/src/ui/public/courier/data_source/_abstract.js index 0475e2cd32a0..d666db7ff5c5 100644 --- a/src/ui/public/courier/data_source/_abstract.js +++ b/src/ui/public/courier/data_source/_abstract.js @@ -1,14 +1,17 @@ import _ from 'lodash'; import angular from 'angular'; -import CourierRequestQueueProvider from 'ui/courier/_request_queue'; -import CourierErrorHandlersProvider from 'ui/courier/_error_handlers'; -import CourierFetchFetchProvider from 'ui/courier/fetch/fetch'; -import CourierDataSourceDecorateQueryProvider from 'ui/courier/data_source/_decorate_query'; + +import 'ui/promises'; + +import RequestQueueProvider from '../_request_queue'; +import ErrorHandlersProvider from '../_error_handlers'; +import FetchProvider from '../fetch'; +import DecorateQueryProvider from './_decorate_query'; export default function SourceAbstractFactory(Private, Promise, PromiseEmitter) { - var requestQueue = Private(CourierRequestQueueProvider); - var errorHandlers = Private(CourierErrorHandlersProvider); - var courierFetch = Private(CourierFetchFetchProvider); + var requestQueue = Private(RequestQueueProvider); + var errorHandlers = Private(ErrorHandlersProvider); + var courierFetch = Private(FetchProvider); function SourceAbstract(initialState, strategy) { var self = this; @@ -268,7 +271,7 @@ export default function SourceAbstractFactory(Private, Promise, PromiseEmitter) .then(function () { if (type === 'search') { // This is down here to prevent the circular dependency - var decorateQuery = Private(CourierDataSourceDecorateQueryProvider); + var decorateQuery = Private(DecorateQueryProvider); flatState.body = flatState.body || {}; diff --git a/src/ui/public/courier/data_source/_decorate_query.js b/src/ui/public/courier/data_source/_decorate_query.js index 4de2f9c8258c..a97740b0508b 100644 --- a/src/ui/public/courier/data_source/_decorate_query.js +++ b/src/ui/public/courier/data_source/_decorate_query.js @@ -1,4 +1,5 @@ import _ from 'lodash'; + export default function DecorateQuery(config) { /** * Decorate queries with default parameters diff --git a/src/ui/public/courier/data_source/_doc_send_to_es.js b/src/ui/public/courier/data_source/_doc_send_to_es.js index 2b1652e8bcc8..97a2ce64004e 100644 --- a/src/ui/public/courier/data_source/_doc_send_to_es.js +++ b/src/ui/public/courier/data_source/_doc_send_to_es.js @@ -1,11 +1,12 @@ import _ from 'lodash'; + import errors from 'ui/errors'; -import CourierRequestQueueProvider from 'ui/courier/_request_queue'; -import CourierFetchFetchProvider from 'ui/courier/fetch/fetch'; +import RequestQueueProvider from 'ui/courier/_request_queue'; +import FetchProvider from 'ui/courier/fetch/fetch'; export default function (Promise, Private, es) { - var requestQueue = Private(CourierRequestQueueProvider); - var courierFetch = Private(CourierFetchFetchProvider); + var requestQueue = Private(RequestQueueProvider); + var courierFetch = Private(FetchProvider); /** * Backend for doUpdate and doIndex diff --git a/src/ui/public/courier/data_source/_normalize_sort_request.js b/src/ui/public/courier/data_source/_normalize_sort_request.js index 220ca70c6fa3..f43a4fc2ccbe 100644 --- a/src/ui/public/courier/data_source/_normalize_sort_request.js +++ b/src/ui/public/courier/data_source/_normalize_sort_request.js @@ -1,4 +1,5 @@ import _ from 'lodash'; + export default function normalizeSortRequest(config) { var defaultSortOptions = config.get('sort:options'); @@ -48,4 +49,3 @@ export default function normalizeSortRequest(config) { return normalized; } }; - diff --git a/src/ui/public/courier/data_source/_root_search_source.js b/src/ui/public/courier/data_source/_root_search_source.js index 385cdea47847..128f922b8a6c 100644 --- a/src/ui/public/courier/data_source/_root_search_source.js +++ b/src/ui/public/courier/data_source/_root_search_source.js @@ -1,7 +1,7 @@ -import CourierDataSourceSearchSourceProvider from 'ui/courier/data_source/search_source'; +import SearchSourceProvider from 'ui/courier/data_source/search_source'; export default function RootSearchSource(Private, $rootScope, timefilter, Notifier) { - var SearchSource = Private(CourierDataSourceSearchSourceProvider); + var SearchSource = Private(SearchSourceProvider); var notify = new Notifier({ location: 'Root Search Source' }); diff --git a/src/ui/public/courier/data_source/doc_source.js b/src/ui/public/courier/data_source/doc_source.js index 6d93ac0c5b9c..c2725309bfb7 100644 --- a/src/ui/public/courier/data_source/doc_source.js +++ b/src/ui/public/courier/data_source/doc_source.js @@ -1,16 +1,18 @@ import _ from 'lodash'; -import CourierDataSourceDocSendToEsProvider from 'ui/courier/data_source/_doc_send_to_es'; -import CourierDataSourceAbstractProvider from 'ui/courier/data_source/_abstract'; -import CourierFetchRequestDocProvider from 'ui/courier/fetch/request/doc'; -import CourierFetchStrategyDocProvider from 'ui/courier/fetch/strategy/doc'; + import 'ui/es'; import 'ui/storage'; +import DocSendToEsProvider from './_doc_send_to_es'; +import AbstractDataSourceProvider from './_abstract'; +import DocRequestProvider from '../fetch/request/doc'; +import DocStrategyProvider from '../fetch/strategy/doc'; + export default function DocSourceFactory(Private, Promise, es, sessionStorage) { - var sendToEs = Private(CourierDataSourceDocSendToEsProvider); - var SourceAbstract = Private(CourierDataSourceAbstractProvider); - var DocRequest = Private(CourierFetchRequestDocProvider); - var docStrategy = Private(CourierFetchStrategyDocProvider); + var sendToEs = Private(DocSendToEsProvider); + var SourceAbstract = Private(AbstractDataSourceProvider); + var DocRequest = Private(DocRequestProvider); + var docStrategy = Private(DocStrategyProvider); _.class(DocSource).inherits(SourceAbstract); function DocSource(initialState) { diff --git a/src/ui/public/courier/data_source/search_source.js b/src/ui/public/courier/data_source/search_source.js index c01f606376c0..0cd2a14d749b 100644 --- a/src/ui/public/courier/data_source/search_source.js +++ b/src/ui/public/courier/data_source/search_source.js @@ -1,16 +1,18 @@ import _ from 'lodash'; -import rootSearchSource from 'ui/courier/data_source/_root_search_source'; -import CourierDataSourceAbstractProvider from 'ui/courier/data_source/_abstract'; -import CourierFetchRequestSearchProvider from 'ui/courier/fetch/request/search'; -import CourierFetchRequestSegmentedProvider from 'ui/courier/fetch/request/segmented'; -import CourierFetchStrategySearchProvider from 'ui/courier/fetch/strategy/search'; -import CourierDataSourceNormalizeSortRequestProvider from 'ui/courier/data_source/_normalize_sort_request'; + +import NormalizeSortRequestProvider from './_normalize_sort_request'; +import rootSearchSource from './_root_search_source'; +import AbstractDataSourceProvider from './_abstract'; +import SearchRequestProvider from '../fetch/request/search'; +import SegmentedRequestProvider from '../fetch/request/segmented'; +import SearchStrategyProvider from '../fetch/strategy/search'; + export default function SearchSourceFactory(Promise, Private) { - var SourceAbstract = Private(CourierDataSourceAbstractProvider); - var SearchRequest = Private(CourierFetchRequestSearchProvider); - var SegmentedRequest = Private(CourierFetchRequestSegmentedProvider); - var searchStrategy = Private(CourierFetchStrategySearchProvider); - var normalizeSortRequest = Private(CourierDataSourceNormalizeSortRequestProvider); + var SourceAbstract = Private(AbstractDataSourceProvider); + var SearchRequest = Private(SearchRequestProvider); + var SegmentedRequest = Private(SegmentedRequestProvider); + var searchStrategy = Private(SearchStrategyProvider); + var normalizeSortRequest = Private(NormalizeSortRequestProvider); _.class(SearchSource).inherits(SourceAbstract); function SearchSource(initialState) { diff --git a/src/ui/public/courier/fetch/__tests__/doc.js b/src/ui/public/courier/fetch/__tests__/doc.js index 25c7e7867791..6ce8059c14ba 100644 --- a/src/ui/public/courier/fetch/__tests__/doc.js +++ b/src/ui/public/courier/fetch/__tests__/doc.js @@ -1,22 +1,22 @@ import sinon from 'auto-release-sinon'; import expect from 'expect.js'; import ngMock from 'ngMock'; -import CourierDataSourceDocSourceProvider from 'ui/courier/data_source/doc_source'; -import CourierFetchRequestDocProvider from 'ui/courier/fetch/request/doc'; + +import DocSourceProvider from '../../data_source/doc_source'; +import DocRequestProvider from '../request/doc'; describe('Courier DocFetchRequest class', function () { + let storage; + let source; + let defer; + let req; - var storage; - var source; - var defer; - var req; - - var setVersion; + let setVersion; beforeEach(ngMock.module('kibana')); beforeEach(ngMock.inject(function (Private, Promise, $injector) { - var DocSource = Private(CourierDataSourceDocSourceProvider); - var DocFetchRequest = Private(CourierFetchRequestDocProvider); + const DocSource = Private(DocSourceProvider); + const DocFetchRequest = Private(DocRequestProvider); storage = $injector.get('localStorage').store = diff --git a/src/ui/public/courier/fetch/__tests__/fetch.js b/src/ui/public/courier/fetch/__tests__/fetch.js index dad88dd6c93d..1c5c6b107c9a 100644 --- a/src/ui/public/courier/fetch/__tests__/fetch.js +++ b/src/ui/public/courier/fetch/__tests__/fetch.js @@ -2,11 +2,12 @@ import ngMock from 'ngMock'; import expect from 'expect.js'; import sinon from 'auto-release-sinon'; -import FetchProvider from 'ui/courier/fetch'; import IndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern'; import searchResp from 'fixtures/search_response'; -import CourierDataSourceDocSourceProvider from 'ui/courier/data_source/doc_source'; -import CourierDataSourceSearchSourceProvider from 'ui/courier/data_source/search_source'; + +import FetchProvider from '../fetch'; +import DocSourceProvider from '../../data_source/doc_source'; +import SearchSourceProvider from '../../data_source/search_source'; describe('Fetch service', function () { require('testUtils/noDigestPromises').activateForSuite(); @@ -24,8 +25,8 @@ describe('Fetch service', function () { Promise = $injector.get('Promise'); fetch = Private(FetchProvider); indexPattern = Private(IndexPatternProvider); - DocSource = Private(CourierDataSourceDocSourceProvider); - SearchSource = Private(CourierDataSourceSearchSourceProvider); + DocSource = Private(DocSourceProvider); + SearchSource = Private(SearchSourceProvider); })); describe('#doc(docSource)', function () { diff --git a/src/ui/public/courier/fetch/__tests__/fetch_these.js b/src/ui/public/courier/fetch/__tests__/fetch_these.js index 57d085394bb0..513373af11b7 100644 --- a/src/ui/public/courier/fetch/__tests__/fetch_these.js +++ b/src/ui/public/courier/fetch/__tests__/fetch_these.js @@ -1,8 +1,9 @@ -import _ from 'lodash'; import sinon from 'auto-release-sinon'; import expect from 'expect.js'; import ngMock from 'ngMock'; -import CourierFetchFetchTheseProvider from 'ui/courier/fetch/_fetch_these'; + +import FetchTheseProvider from '../fetch_these'; + describe('ui/courier/fetch/_fetch_these', () => { let Promise; @@ -22,15 +23,15 @@ describe('ui/courier/fetch/_fetch_these', () => { return fakeResponses; } - PrivateProvider.swap(require('ui/courier/fetch/_call_client'), FakeResponsesProvider); - PrivateProvider.swap(require('ui/courier/fetch/_call_response_handlers'), FakeResponsesProvider); - PrivateProvider.swap(require('ui/courier/fetch/_continue_incomplete'), FakeResponsesProvider); + PrivateProvider.swap(require('ui/courier/fetch/call_client'), FakeResponsesProvider); + PrivateProvider.swap(require('ui/courier/fetch/call_response_handlers'), FakeResponsesProvider); + PrivateProvider.swap(require('ui/courier/fetch/continue_incomplete'), FakeResponsesProvider); })); beforeEach(ngMock.inject((Private, $injector) => { $rootScope = $injector.get('$rootScope'); Promise = $injector.get('Promise'); - fetchThese = Private(CourierFetchFetchTheseProvider); + fetchThese = Private(FetchTheseProvider); request = mockRequest(); requests = [ request ]; })); diff --git a/src/ui/public/courier/fetch/_is_request.js b/src/ui/public/courier/fetch/_is_request.js deleted file mode 100644 index 5f85fede4345..000000000000 --- a/src/ui/public/courier/fetch/_is_request.js +++ /dev/null @@ -1,9 +0,0 @@ -import CourierFetchRequestRequestProvider from 'ui/courier/fetch/request/request'; - -export default function CourierFetchIsRequestProvider(Private) { - var AbstractRequest = Private(CourierFetchRequestRequestProvider); - - return function isRequest(obj) { - return obj instanceof AbstractRequest; - }; -}; diff --git a/src/ui/public/courier/fetch/_call_client.js b/src/ui/public/courier/fetch/call_client.js similarity index 77% rename from src/ui/public/courier/fetch/_call_client.js rename to src/ui/public/courier/fetch/call_client.js index db21eaba6cb7..2157e4420d95 100644 --- a/src/ui/public/courier/fetch/_call_client.js +++ b/src/ui/public/courier/fetch/call_client.js @@ -1,29 +1,31 @@ import _ from 'lodash'; -import CourierFetchIsRequestProvider from 'ui/courier/fetch/_is_request'; -import CourierFetchMergeDuplicateRequestsProvider from 'ui/courier/fetch/_merge_duplicate_requests'; -import CourierFetchReqStatusProvider from 'ui/courier/fetch/_req_status'; + +import IsRequestProvider from './is_request'; +import MergeDuplicatesRequestProvider from './merge_duplicate_requests'; +import ReqStatusProvider from './req_status'; + export default function CourierFetchCallClient(Private, Promise, es, esShardTimeout, sessionId) { - var isRequest = Private(CourierFetchIsRequestProvider); - var mergeDuplicateRequests = Private(CourierFetchMergeDuplicateRequestsProvider); + const isRequest = Private(IsRequestProvider); + const mergeDuplicateRequests = Private(MergeDuplicatesRequestProvider); - var ABORTED = Private(CourierFetchReqStatusProvider).ABORTED; - var DUPLICATE = Private(CourierFetchReqStatusProvider).DUPLICATE; + const ABORTED = Private(ReqStatusProvider).ABORTED; + const DUPLICATE = Private(ReqStatusProvider).DUPLICATE; function callClient(strategy, requests) { // merging docs can change status to DUPLICATE, capture new statuses - var statuses = mergeDuplicateRequests(requests); + const statuses = mergeDuplicateRequests(requests); // get the actual list of requests that we will be fetching - var executable = statuses.filter(isRequest); - var execCount = executable.length; + const executable = statuses.filter(isRequest); + let execCount = executable.length; // resolved by respond() - var esPromise; - var defer = Promise.defer(); + let esPromise; + const defer = Promise.defer(); // for each respond with either the response or ABORTED - var respond = function (responses) { + const respond = function (responses) { responses = responses || []; return Promise.map(requests, function (req, i) { switch (statuses[i]) { @@ -43,7 +45,7 @@ export default function CourierFetchCallClient(Private, Promise, es, esShardTime // handle a request being aborted while being fetched - var requestWasAborted = Promise.method(function (req, i) { + const requestWasAborted = Promise.method(function (req, i) { if (statuses[i] === ABORTED) { defer.reject(new Error('Request was aborted twice?')); } diff --git a/src/ui/public/courier/fetch/_call_response_handlers.js b/src/ui/public/courier/fetch/call_response_handlers.js similarity index 68% rename from src/ui/public/courier/fetch/_call_response_handlers.js rename to src/ui/public/courier/fetch/call_response_handlers.js index 3dfcd3379372..41b4c2bc2020 100644 --- a/src/ui/public/courier/fetch/_call_response_handlers.js +++ b/src/ui/public/courier/fetch/call_response_handlers.js @@ -1,12 +1,12 @@ -import { SearchTimeout } from 'ui/errors'; -import { RequestFailure } from 'ui/errors'; -import { ShardFailure } from 'ui/errors'; -import CourierFetchReqStatusProvider from 'ui/courier/fetch/_req_status'; -import CourierFetchNotifierProvider from 'ui/courier/fetch/_notifier'; +import { RequestFailure, SearchTimeout, ShardFailure } from 'ui/errors'; + +import ReqStatusProvider from './req_status'; +import NotifierProvider from './notifier'; + export default function CourierFetchCallResponseHandlers(Private, Promise) { - var ABORTED = Private(CourierFetchReqStatusProvider).ABORTED; - var INCOMPLETE = Private(CourierFetchReqStatusProvider).INCOMPLETE; - var notify = Private(CourierFetchNotifierProvider); + const ABORTED = Private(ReqStatusProvider).ABORTED; + const INCOMPLETE = Private(ReqStatusProvider).INCOMPLETE; + const notify = Private(NotifierProvider); function callResponseHandlers(requests, responses) { @@ -15,7 +15,7 @@ export default function CourierFetchCallResponseHandlers(Private, Promise) { return ABORTED; } - var resp = responses[i]; + let resp = responses[i]; if (resp.timed_out) { notify.warning(new SearchTimeout()); diff --git a/src/ui/public/courier/fetch/_continue_incomplete.js b/src/ui/public/courier/fetch/continue_incomplete.js similarity index 79% rename from src/ui/public/courier/fetch/_continue_incomplete.js rename to src/ui/public/courier/fetch/continue_incomplete.js index bff84e5ef4a9..12433548a32e 100644 --- a/src/ui/public/courier/fetch/_continue_incomplete.js +++ b/src/ui/public/courier/fetch/continue_incomplete.js @@ -1,10 +1,10 @@ -import CourierFetchReqStatusProvider from 'ui/courier/fetch/_req_status'; +import ReqStatusProvider from './req_status'; export default function CourierFetchContinueIncompleteRequests(Private) { - var INCOMPLETE = Private(CourierFetchReqStatusProvider).INCOMPLETE; + const INCOMPLETE = Private(ReqStatusProvider).INCOMPLETE; function continueIncompleteRequests(strategy, requests, responses, fetchWithStrategy) { - var incomplete = []; + const incomplete = []; responses.forEach(function (resp, i) { if (resp === INCOMPLETE) { diff --git a/src/ui/public/courier/fetch/fetch.js b/src/ui/public/courier/fetch/fetch.js index 4f34135820d4..f6bf27754073 100644 --- a/src/ui/public/courier/fetch/fetch.js +++ b/src/ui/public/courier/fetch/fetch.js @@ -1,18 +1,20 @@ import _ from 'lodash'; -import CourierRequestQueueProvider from 'ui/courier/_request_queue'; -import CourierFetchFetchTheseProvider from 'ui/courier/fetch/_fetch_these'; -import CourierFetchCallResponseHandlersProvider from 'ui/courier/fetch/_call_response_handlers'; -import CourierFetchReqStatusProvider from 'ui/courier/fetch/_req_status'; + +import RequestQueueProvider from '../_request_queue'; +import FetchTheseProvider from './fetch_these'; +import CallResponseHandlersProvider from './call_response_handlers'; +import ReqStatusProvider from './req_status'; + export default function fetchService(Private, Promise) { - var requestQueue = Private(CourierRequestQueueProvider); - var fetchThese = Private(CourierFetchFetchTheseProvider); + const requestQueue = Private(RequestQueueProvider); + const fetchThese = Private(FetchTheseProvider); - var callResponseHandlers = Private(CourierFetchCallResponseHandlersProvider); - var INCOMPLETE = Private(CourierFetchReqStatusProvider).INCOMPLETE; + const callResponseHandlers = Private(CallResponseHandlersProvider); + const INCOMPLETE = Private(ReqStatusProvider).INCOMPLETE; function fetchQueued(strategy) { - var requests = requestQueue.getStartable(strategy); + const requests = requestQueue.getStartable(strategy); if (!requests.length) return Promise.resolve(); else return fetchThese(requests); } @@ -20,7 +22,7 @@ export default function fetchService(Private, Promise) { this.fetchQueued = fetchQueued; function fetchASource(source, strategy) { - var defer = Promise.defer(); + const defer = Promise.defer(); fetchThese([ source._createRequest(defer) diff --git a/src/ui/public/courier/fetch/_fetch_these.js b/src/ui/public/courier/fetch/fetch_these.js similarity index 58% rename from src/ui/public/courier/fetch/_fetch_these.js rename to src/ui/public/courier/fetch/fetch_these.js index 006f273f7880..78affdf29ac5 100644 --- a/src/ui/public/courier/fetch/_fetch_these.js +++ b/src/ui/public/courier/fetch/fetch_these.js @@ -1,22 +1,22 @@ -import CourierFetchNotifierProvider from 'ui/courier/fetch/_notifier'; -import CourierFetchForEachStrategyProvider from 'ui/courier/fetch/_for_each_strategy'; -import CourierFetchCallClientProvider from 'ui/courier/fetch/_call_client'; -import CourierFetchCallResponseHandlersProvider from 'ui/courier/fetch/_call_response_handlers'; -import CourierFetchContinueIncompleteProvider from 'ui/courier/fetch/_continue_incomplete'; -import CourierFetchReqStatusProvider from 'ui/courier/fetch/_req_status'; +import NotifierProvider from './notifier'; +import ForEachStrategyProvider from './for_each_strategy'; +import CallClientProvider from './call_client'; +import CallResponseHandlersProvider from './call_response_handlers'; +import ContinueIncompleteProvider from './continue_incomplete'; +import ReqStatusProvider from './req_status'; export default function FetchTheseProvider(Private, Promise) { - var notify = Private(CourierFetchNotifierProvider); - var forEachStrategy = Private(CourierFetchForEachStrategyProvider); + const notify = Private(NotifierProvider); + const forEachStrategy = Private(ForEachStrategyProvider); // core tasks - var callClient = Private(CourierFetchCallClientProvider); - var callResponseHandlers = Private(CourierFetchCallResponseHandlersProvider); - var continueIncomplete = Private(CourierFetchContinueIncompleteProvider); + const callClient = Private(CallClientProvider); + const callResponseHandlers = Private(CallResponseHandlersProvider); + const continueIncomplete = Private(ContinueIncompleteProvider); - var ABORTED = Private(CourierFetchReqStatusProvider).ABORTED; - var DUPLICATE = Private(CourierFetchReqStatusProvider).DUPLICATE; - var INCOMPLETE = Private(CourierFetchReqStatusProvider).INCOMPLETE; + const ABORTED = Private(ReqStatusProvider).ABORTED; + const DUPLICATE = Private(ReqStatusProvider).DUPLICATE; + const INCOMPLETE = Private(ReqStatusProvider).INCOMPLETE; function fetchThese(requests) { return forEachStrategy(requests, function (strategy, reqsForStrategy) { @@ -66,7 +66,7 @@ export default function FetchTheseProvider(Private, Promise) { } return new Promise(function (resolve) { - var action = req.started ? req.continue : req.start; + const action = req.started ? req.continue : req.start; resolve(action.call(req)); }) .catch(err => req.handleFailure(err)); diff --git a/src/ui/public/courier/fetch/_for_each_strategy.js b/src/ui/public/courier/fetch/for_each_strategy.js similarity index 80% rename from src/ui/public/courier/fetch/_for_each_strategy.js rename to src/ui/public/courier/fetch/for_each_strategy.js index 0bebb1a262b5..8eababd7670a 100644 --- a/src/ui/public/courier/fetch/_for_each_strategy.js +++ b/src/ui/public/courier/fetch/for_each_strategy.js @@ -1,13 +1,13 @@ import _ from 'lodash'; -export default function FetchForEachRequestStrategy(Private, Promise) { +export default function FetchForEachRequestStrategy(Private, Promise) { function forEachStrategy(requests, block) { block = Promise.method(block); - var sets = []; + const sets = []; requests.forEach(function (req) { - var strategy = req.strategy; - var set = _.find(sets, { 0: strategy }); + const strategy = req.strategy; + const set = _.find(sets, { 0: strategy }); if (set) set[1].push(req); else sets.push([strategy, [req]]); }); diff --git a/src/ui/public/courier/fetch/is_request.js b/src/ui/public/courier/fetch/is_request.js new file mode 100644 index 000000000000..f64ab1e1ec08 --- /dev/null +++ b/src/ui/public/courier/fetch/is_request.js @@ -0,0 +1,9 @@ +import AbstractRequestProvider from './request'; + +export default function IsRequestProvider(Private) { + const AbstractRequest = Private(AbstractRequestProvider); + + return function isRequest(obj) { + return obj instanceof AbstractRequest; + }; +}; diff --git a/src/ui/public/courier/fetch/_merge_duplicate_requests.js b/src/ui/public/courier/fetch/merge_duplicate_requests.js similarity index 60% rename from src/ui/public/courier/fetch/_merge_duplicate_requests.js rename to src/ui/public/courier/fetch/merge_duplicate_requests.js index 2f1d0c2daffb..5c698f422834 100644 --- a/src/ui/public/courier/fetch/_merge_duplicate_requests.js +++ b/src/ui/public/courier/fetch/merge_duplicate_requests.js @@ -1,17 +1,17 @@ -import CourierFetchIsRequestProvider from 'ui/courier/fetch/_is_request'; -import CourierFetchReqStatusProvider from 'ui/courier/fetch/_req_status'; +import IsRequestProvider from './is_request'; +import ReqStatusProvider from './req_status'; export default function FetchMergeDuplicateRequests(Private) { - var isRequest = Private(CourierFetchIsRequestProvider); - var DUPLICATE = Private(CourierFetchReqStatusProvider).DUPLICATE; + const isRequest = Private(IsRequestProvider); + const DUPLICATE = Private(ReqStatusProvider).DUPLICATE; function mergeDuplicateRequests(requests) { // dedupe requests - var index = {}; + const index = {}; return requests.map(function (req) { if (!isRequest(req)) return req; - var iid = req.source._instanceid; + const iid = req.source._instanceid; if (!index[iid]) { // this request is unique so far index[iid] = req; diff --git a/src/ui/public/courier/fetch/_notifier.js b/src/ui/public/courier/fetch/notifier.js similarity index 100% rename from src/ui/public/courier/fetch/_notifier.js rename to src/ui/public/courier/fetch/notifier.js diff --git a/src/ui/public/courier/fetch/_req_status.js b/src/ui/public/courier/fetch/req_status.js similarity index 100% rename from src/ui/public/courier/fetch/_req_status.js rename to src/ui/public/courier/fetch/req_status.js diff --git a/src/ui/public/courier/fetch/request/__tests__/segmented.js b/src/ui/public/courier/fetch/request/__tests__/segmented.js index 9f2a45d5ad8b..cabfae475a29 100644 --- a/src/ui/public/courier/fetch/request/__tests__/segmented.js +++ b/src/ui/public/courier/fetch/request/__tests__/segmented.js @@ -1,10 +1,11 @@ import sinon from 'auto-release-sinon'; import expect from 'expect.js'; import ngMock from 'ngMock'; -import CourierFetchRequestSegmentedProvider from 'ui/courier/fetch/request/segmented'; -import CourierFetchRequestSearchProvider from 'ui/courier/fetch/request/search'; -describe('ui/courier/fetch/request/segmented', () => { +import SegmentedRequestProvider from '../segmented'; +import SearchRequestProvider from '../search'; + +describe('ui/courier/fetch/request/segmented', () => { let Promise; let $rootScope; let SegmentedReq; @@ -16,8 +17,8 @@ describe('ui/courier/fetch/request/segmented', () => { beforeEach(ngMock.inject((Private, $injector) => { Promise = $injector.get('Promise'); $rootScope = $injector.get('$rootScope'); - SegmentedReq = Private(CourierFetchRequestSegmentedProvider); - searchReqStart = sinon.spy(Private(CourierFetchRequestSearchProvider).prototype, 'start'); + SegmentedReq = Private(SegmentedRequestProvider); + searchReqStart = sinon.spy(Private(SearchRequestProvider).prototype, 'start'); })); describe('#start()', () => { diff --git a/src/ui/public/courier/fetch/request/__tests__/segmented_create_queue.js b/src/ui/public/courier/fetch/request/__tests__/segmented_create_queue.js index c63cc5d0db32..e7a20f988090 100644 --- a/src/ui/public/courier/fetch/request/__tests__/segmented_create_queue.js +++ b/src/ui/public/courier/fetch/request/__tests__/segmented_create_queue.js @@ -1,8 +1,11 @@ import sinon from 'auto-release-sinon'; import expect from 'expect.js'; import ngMock from 'ngMock'; + import StubbedSearchSourceProvider from 'fixtures/stubbed_search_source'; -import CourierFetchRequestSegmentedProvider from 'ui/courier/fetch/request/segmented'; + +import SegmentedRequestProvider from '../segmented'; + describe('ui/courier/fetch/request/segmented/_createQueue', () => { let Promise; @@ -16,7 +19,7 @@ describe('ui/courier/fetch/request/segmented/_createQueue', () => { beforeEach(ngMock.inject((Private, $injector) => { Promise = $injector.get('Promise'); $rootScope = $injector.get('$rootScope'); - SegmentedReq = Private(CourierFetchRequestSegmentedProvider); + SegmentedReq = Private(SegmentedRequestProvider); MockSource = class { constructor() { @@ -29,7 +32,7 @@ describe('ui/courier/fetch/request/segmented/_createQueue', () => { const req = new SegmentedReq(new MockSource()); req._queueCreated = null; - var promise = req._createQueue(); + const promise = req._createQueue(); expect(req._queueCreated).to.be(false); await promise; expect(req._queueCreated).to.be(true); diff --git a/src/ui/public/courier/fetch/request/__tests__/segmented_index_selection.js b/src/ui/public/courier/fetch/request/__tests__/segmented_index_selection.js index 336d7e957083..89a2c1735a95 100644 --- a/src/ui/public/courier/fetch/request/__tests__/segmented_index_selection.js +++ b/src/ui/public/courier/fetch/request/__tests__/segmented_index_selection.js @@ -6,7 +6,8 @@ import sinon from 'auto-release-sinon'; import HitSortFnProv from 'plugins/kibana/discover/_hit_sort_fn'; import NoDigestPromises from 'testUtils/noDigestPromises'; import StubbedSearchSourceProvider from 'fixtures/stubbed_search_source'; -import CourierFetchRequestSegmentedProvider from 'ui/courier/fetch/request/segmented'; + +import SegmentedRequestProvider from '../segmented'; describe('Segmented Request Index Selection', function () { let Promise; @@ -22,7 +23,7 @@ describe('Segmented Request Index Selection', function () { Promise = $injector.get('Promise'); HitSortFn = Private(HitSortFnProv); $rootScope = $injector.get('$rootScope'); - SegmentedReq = Private(CourierFetchRequestSegmentedProvider); + SegmentedReq = Private(SegmentedRequestProvider); MockSource = class { constructor() { diff --git a/src/ui/public/courier/fetch/request/__tests__/segmented_size_picking.js b/src/ui/public/courier/fetch/request/__tests__/segmented_size_picking.js index 7e40a44dea77..3339b21d2e92 100644 --- a/src/ui/public/courier/fetch/request/__tests__/segmented_size_picking.js +++ b/src/ui/public/courier/fetch/request/__tests__/segmented_size_picking.js @@ -6,7 +6,8 @@ import sinon from 'auto-release-sinon'; import HitSortFnProv from 'plugins/kibana/discover/_hit_sort_fn'; import NoDigestPromises from 'testUtils/noDigestPromises'; import StubbedSearchSourceProvider from 'fixtures/stubbed_search_source'; -import CourierFetchRequestSegmentedProvider from 'ui/courier/fetch/request/segmented'; + +import SegmentedRequestProvider from '../segmented'; describe('Segmented Request Size Picking', function () { let Promise; @@ -22,7 +23,7 @@ describe('Segmented Request Size Picking', function () { Promise = $injector.get('Promise'); HitSortFn = Private(HitSortFnProv); $rootScope = $injector.get('$rootScope'); - SegmentedReq = Private(CourierFetchRequestSegmentedProvider); + SegmentedReq = Private(SegmentedRequestProvider); MockSource = class { constructor() { diff --git a/src/ui/public/courier/fetch/request/_segmented_handle.js b/src/ui/public/courier/fetch/request/_segmented_handle.js deleted file mode 100644 index 64739964f782..000000000000 --- a/src/ui/public/courier/fetch/request/_segmented_handle.js +++ /dev/null @@ -1,29 +0,0 @@ -import _ from 'lodash'; -import EventsProvider from 'ui/events'; -export default function CourierSegmentedReqHandle(Private) { - var Events = Private(EventsProvider); - - - /** - * Simple class for creating an object to send to the - * requester of a SegmentedRequest. Since the SegmentedRequest - * extends AbstractRequest, it wasn't able to be the event - * emitter it was born to be. This provides a channel for - * setting values on the segmented request, and an event - * emitter for the request to speak outwardly - * - * @param {SegmentedRequest} - req - the requst this handle relates to - */ - _.class(SegmentedHandle).inherits(Events); - function SegmentedHandle(req) { - SegmentedHandle.Super.call(this); - - // export a couple methods from the request - this.setDirection = _.bindKey(req, 'setDirection'); - this.setSize = _.bindKey(req, 'setSize'); - this.setMaxSegments = _.bindKey(req, 'setMaxSegments'); - this.setSortFn = _.bindKey(req, 'setSortFn'); - } - - return SegmentedHandle; -}; diff --git a/src/ui/public/courier/fetch/request/doc.js b/src/ui/public/courier/fetch/request/doc.js index 0b822e1fc0c6..bbe0d12e7ee6 100644 --- a/src/ui/public/courier/fetch/request/doc.js +++ b/src/ui/public/courier/fetch/request/doc.js @@ -1,42 +1,43 @@ -import _ from 'lodash'; -import CourierFetchStrategyDocProvider from 'ui/courier/fetch/strategy/doc'; -import CourierFetchRequestRequestProvider from 'ui/courier/fetch/request/request'; +import DocStrategyProvider from '../strategy/doc'; +import AbstractRequestProvider from './request'; + export default function DocRequestProvider(Private) { - var docStrategy = Private(CourierFetchStrategyDocProvider); - var AbstractRequest = Private(CourierFetchRequestRequestProvider); + const docStrategy = Private(DocStrategyProvider); + const AbstractRequest = Private(AbstractRequestProvider); - _.class(DocRequest).inherits(AbstractRequest); - function DocRequest(source, defer) { - DocRequest.Super.call(this, source, defer); + class DocRequest extends AbstractRequest { + constructor(...args) { + super(...args); - this.type = 'doc'; - this.strategy = docStrategy; - } - - DocRequest.prototype.canStart = function () { - var parent = DocRequest.Super.prototype.canStart.call(this); - if (!parent) return false; - - var version = this.source._version; - var storedVersion = this.source._getStoredVersion(); - - // conditions that equal "fetch This DOC!" - var unknown = !version && !storedVersion; - var mismatch = version !== storedVersion; - - return Boolean(mismatch || (unknown && !this.started)); - }; - - DocRequest.prototype.handleResponse = function (resp) { - if (resp.found) { - this.source._storeVersion(resp._version); - } else { - this.source._clearVersion(); + this.type = 'doc'; + this.strategy = docStrategy; } - return DocRequest.Super.prototype.handleResponse.call(this, resp); - }; + canStart() { + const parent = super.canStart(); + if (!parent) return false; + + const version = this.source._version; + const storedVersion = this.source._getStoredVersion(); + + // conditions that equal "fetch This DOC!" + const unknown = !version && !storedVersion; + const mismatch = version !== storedVersion; + + return Boolean(mismatch || (unknown && !this.started)); + } + + handleResponse(resp) { + if (resp.found) { + this.source._storeVersion(resp._version); + } else { + this.source._clearVersion(); + } + + return super.handleResponse(resp); + } + } return DocRequest; }; diff --git a/src/ui/public/courier/fetch/request/_error_handler.js b/src/ui/public/courier/fetch/request/error_handler.js similarity index 76% rename from src/ui/public/courier/fetch/request/_error_handler.js rename to src/ui/public/courier/fetch/request/error_handler.js index 69aede3ee21f..91e6c0929df3 100644 --- a/src/ui/public/courier/fetch/request/_error_handler.js +++ b/src/ui/public/courier/fetch/request/error_handler.js @@ -1,15 +1,16 @@ -import CourierErrorHandlersProvider from 'ui/courier/_error_handlers'; import Notifier from 'ui/notify/notifier'; -export default function RequestErrorHandlerFactory(Private) { - var errHandlers = Private(CourierErrorHandlersProvider); +import ErrorHandlersProvider from '../../_error_handlers'; - var notify = new Notifier({ +export default function RequestErrorHandlerFactory(Private) { + const errHandlers = Private(ErrorHandlersProvider); + + const notify = new Notifier({ location: 'Courier Fetch Error' }); function handleError(req, error) { - var myHandlers = []; + const myHandlers = []; errHandlers.splice(0).forEach(function (handler) { (handler.source === req.source ? myHandlers : errHandlers).push(handler); diff --git a/src/ui/public/courier/fetch/request/request.js b/src/ui/public/courier/fetch/request/request.js index 7d828e583adf..1c7cf35abd31 100644 --- a/src/ui/public/courier/fetch/request/request.js +++ b/src/ui/public/courier/fetch/request/request.js @@ -1,115 +1,110 @@ import _ from 'lodash'; import moment from 'moment'; + import errors from 'ui/errors'; -import CourierRequestQueueProvider from 'ui/courier/_request_queue'; -import CourierFetchRequestErrorHandlerProvider from 'ui/courier/fetch/request/_error_handler'; + +import RequestQueueProvider from '../../_request_queue'; +import ErrorHandlerRequestProvider from './error_handler'; + export default function AbstractReqProvider(Private, Promise) { - var requestQueue = Private(CourierRequestQueueProvider); - var requestErrorHandler = Private(CourierFetchRequestErrorHandlerProvider); + const requestQueue = Private(RequestQueueProvider); + const requestErrorHandler = Private(ErrorHandlerRequestProvider); - function AbstractReq(source, defer) { - if (!(this instanceof AbstractReq) || !this.constructor || this.constructor === AbstractReq) { - throw new Error('The AbstractReq class should not be called directly'); + return class AbstractReq { + constructor(source, defer) { + this.source = source; + this.defer = defer || Promise.defer(); + this._whenAbortedHandlers = []; + + requestQueue.push(this); } - this.source = source; - this.defer = defer || Promise.defer(); - - requestQueue.push(this); - } - - AbstractReq.prototype.canStart = function () { - return Boolean(!this.stopped && !this.source._fetchDisabled); - }; - - AbstractReq.prototype.start = function () { - if (this.started) { - throw new TypeError('Unable to start request because it has already started'); + canStart() { + return Boolean(!this.stopped && !this.source._fetchDisabled); } - this.started = true; - this.moment = moment(); + start() { + if (this.started) { + throw new TypeError('Unable to start request because it has already started'); + } - var source = this.source; - if (source.activeFetchCount) { - source.activeFetchCount += 1; - } else { - source.activeFetchCount = 1; + this.started = true; + this.moment = moment(); + + const source = this.source; + if (source.activeFetchCount) { + source.activeFetchCount += 1; + } else { + source.activeFetchCount = 1; + } + + source.history = [this]; } - source.history = [this]; - }; + getFetchParams() { + return this.source._flatten(); + } - AbstractReq.prototype.getFetchParams = function () { - return this.source._flatten(); - }; + transformResponse(resp) { + return resp; + } - AbstractReq.prototype.transformResponse = function (resp) { - return resp; - }; + filterError(resp) { + return false; + } - AbstractReq.prototype.filterError = function (resp) { - return false; - }; + handleResponse(resp) { + this.success = true; + this.resp = resp; + } - AbstractReq.prototype.handleResponse = function (resp) { - this.success = true; - this.resp = resp; - }; + handleFailure(error) { + this.success = false; + this.resp = error && error.resp; + this.retry(); + return requestErrorHandler(this, error); + } - AbstractReq.prototype.handleFailure = function (error) { - this.success = false; - this.resp = error && error.resp; - this.retry(); - return requestErrorHandler(this, error); - }; + isIncomplete() { + return false; + } - AbstractReq.prototype.isIncomplete = function () { - return false; - }; + continue() { + throw new Error('Unable to continue ' + this.type + ' request'); + } - AbstractReq.prototype.continue = function () { - throw new Error('Unable to continue ' + this.type + ' request'); - }; + retry() { + const clone = this.clone(); + this.abort(); + return clone; + } - AbstractReq.prototype.retry = function () { - var clone = this.clone(); - this.abort(); - return clone; - }; - - // don't want people overriding this, so it becomes a natural - // part of .abort() and .complete() - function stop(then) { - return function () { + _markStopped() { if (this.stopped) return; - this.stopped = true; this.source.activeFetchCount -= 1; _.pull(requestQueue, this); - then.call(this); - }; - } + } - AbstractReq.prototype.abort = stop(function () { - this.defer = null; - this.aborted = true; - if (this._whenAborted) _.callEach(this._whenAborted); - }); + abort() { + this._markStopped(); + this.defer = null; + this.aborted = true; + _.callEach(this._whenAbortedHandlers); + } - AbstractReq.prototype.whenAborted = function (cb) { - this._whenAborted = (this._whenAborted || []); - this._whenAborted.push(cb); + whenAborted(cb) { + this._whenAbortedHandlers.push(cb); + } + + complete() { + this._markStopped(); + this.ms = this.moment.diff() * -1; + this.defer.resolve(this.resp); + } + + clone() { + return new this.constructor(this.source, this.defer); + } }; - - AbstractReq.prototype.complete = stop(function () { - this.ms = this.moment.diff() * -1; - this.defer.resolve(this.resp); - }); - - AbstractReq.prototype.clone = function () { - return new this.constructor(this.source, this.defer); - }; - - return AbstractReq; }; diff --git a/src/ui/public/courier/fetch/request/search.js b/src/ui/public/courier/fetch/request/search.js index 9718124ef0c9..9ae5b8398bc7 100644 --- a/src/ui/public/courier/fetch/request/search.js +++ b/src/ui/public/courier/fetch/request/search.js @@ -1,19 +1,17 @@ -import _ from 'lodash'; -import CourierFetchStrategySearchProvider from 'ui/courier/fetch/strategy/search'; -import CourierFetchRequestRequestProvider from 'ui/courier/fetch/request/request'; +import SearchStrategyProvider from '../strategy/search'; +import AbstractRequestProvider from './request'; + export default function SearchReqProvider(Private) { - var searchStrategy = Private(CourierFetchStrategySearchProvider); - var AbstractRequest = Private(CourierFetchRequestRequestProvider); + const searchStrategy = Private(SearchStrategyProvider); + const AbstractRequest = Private(AbstractRequestProvider); - _.class(SearchReq).inherits(AbstractRequest); - var Super = SearchReq.Super; - function SearchReq(source, defer) { - Super.call(this, source, defer); + return class SearchReq extends AbstractRequest { + constructor(...args) { + super(...args); - this.type = 'search'; - this.strategy = searchStrategy; - } - - return SearchReq; + this.type = 'search'; + this.strategy = searchStrategy; + } + }; }; diff --git a/src/ui/public/courier/fetch/request/segmented.js b/src/ui/public/courier/fetch/request/segmented.js index 67013b1caeb2..71ae5e2fa8b8 100644 --- a/src/ui/public/courier/fetch/request/segmented.js +++ b/src/ui/public/courier/fetch/request/segmented.js @@ -1,334 +1,337 @@ -import { isNumber } from 'lodash'; import _ from 'lodash'; -import CourierFetchRequestSearchProvider from 'ui/courier/fetch/request/search'; -import CourierFetchRequestSegmentedHandleProvider from 'ui/courier/fetch/request/_segmented_handle'; -export default function CourierSegmentedReqProvider(es, Private, Promise, Notifier, timefilter, config) { - var SearchReq = Private(CourierFetchRequestSearchProvider); - var SegmentedHandle = Private(CourierFetchRequestSegmentedHandleProvider); +import { isNumber } from 'lodash'; - var notify = new Notifier({ +import Notifier from 'ui/notify/notifier'; + +import SearchRequestProvider from './search'; +import SegmentedHandleProvider from './segmented_handle'; + +export default function SegmentedReqProvider(es, Private, Promise, timefilter, config) { + const SearchReq = Private(SearchRequestProvider); + const SegmentedHandle = Private(SegmentedHandleProvider); + + const notify = new Notifier({ location: 'Segmented Fetch' }); - _.class(SegmentedReq).inherits(SearchReq); - function SegmentedReq(source, defer, initFn) { - SearchReq.call(this, source, defer); + class SegmentedReq extends SearchReq { + constructor(source, defer, initFn) { + super(source, defer); - this.type = 'segmented'; + this.type = 'segmented'; - // segmented request specific state - this._initFn = initFn; + // segmented request specific state + this._initFn = initFn; - this._desiredSize = null; - this._maxSegments = config.get('courier:maxSegmentCount'); - this._direction = 'desc'; - this._sortFn = null; - this._queueCreated = false; - this._handle = new SegmentedHandle(this); + this._desiredSize = null; + this._maxSegments = config.get('courier:maxSegmentCount'); + this._direction = 'desc'; + this._sortFn = null; + this._queueCreated = false; + this._handle = new SegmentedHandle(this); - this._hitWindow = null; + this._hitWindow = null; - // prevent the source from changing between requests, - // all calls will return the same promise - this._getFlattenedSource = _.once(this._getFlattenedSource); - } - - /********* - ** SearchReq overrides - *********/ - - SegmentedReq.prototype.start = function () { - var self = this; - - this._complete = []; - this._active = null; - this._segments = []; - this._all = []; - this._queue = []; - - this._mergedResp = { - took: 0, - hits: { - hits: [], - total: 0, - max_score: 0 - } - }; - - // give the request consumer a chance to receive each segment and set - // parameters via the handle - if (_.isFunction(this._initFn)) this._initFn(this._handle); - return this._createQueue().then(function (queue) { - self._all = queue.slice(0); - - // Send the initial fetch status - self._reportStatus(); - - return SearchReq.prototype.start.call(self); - }); - }; - - SegmentedReq.prototype.continue = function () { - return this._reportStatus(); - }; - - SegmentedReq.prototype.getFetchParams = function () { - var self = this; - - return self._getFlattenedSource().then(function (flatSource) { - var params = _.cloneDeep(flatSource); - - // calculate the number of indices to fetch in this request in order to prevent - // more than self._maxSegments requests. We use Math.max(1, n) to ensure that each request - // has at least one index pattern, and Math.floor() to make sure that if the - // number of indices does not round out evenly the extra index is tacked onto the last - // request, making sure the first request returns faster. - var remainingSegments = self._maxSegments - self._segments.length; - var indexCount = Math.max(1, Math.floor(self._queue.length / remainingSegments)); - - var indices = self._active = self._queue.splice(0, indexCount); - params.index = _.pluck(indices, 'index'); - - if (isNumber(self._desiredSize)) { - params.body.size = self._pickSizeForIndices(indices); - } - - return params; - }); - }; - - SegmentedReq.prototype.handleResponse = function (resp) { - return this._consumeSegment(resp); - }; - - SegmentedReq.prototype.filterError = function (resp) { - if (/ClusterBlockException.*index\sclosed/.test(resp.error)) { - this._consumeSegment(false); - return true; + // prevent the source from changing between requests, + // all calls will return the same promise + this._getFlattenedSource = _.once(this._getFlattenedSource); } - }; - SegmentedReq.prototype.isIncomplete = function () { - var queueNotCreated = !this._queueCreated; - var queueNotEmpty = this._queue.length > 0; - return queueNotCreated || queueNotEmpty; - }; + /********* + ** SearchReq overrides + *********/ - SegmentedReq.prototype.clone = function () { - return new SegmentedReq(this.source, this.defer, this._initFn); - }; + start() { + this._complete = []; + this._active = null; + this._segments = []; + this._all = []; + this._queue = []; - SegmentedReq.prototype.complete = function () { - this._reportStatus(); - this._handle.emit('complete'); - return SearchReq.prototype.complete.call(this); - }; + this._mergedResp = { + took: 0, + hits: { + hits: [], + total: 0, + max_score: 0 + } + }; - /********* - ** SegmentedReq specific methods - *********/ + // give the request consumer a chance to receive each segment and set + // parameters via the handle + if (_.isFunction(this._initFn)) this._initFn(this._handle); + return this._createQueue().then((queue) => { + this._all = queue.slice(0); - /** - * Set the sort total number of segments to emit - * - * @param {number} - */ - SegmentedReq.prototype.setMaxSegments = function (maxSegments) { - this._maxSegments = Math.max(_.parseInt(maxSegments), 1); - }; + // Send the initial fetch status + this._reportStatus(); - /** - * Set the sort direction for the request. - * - * @param {string} dir - one of 'asc' or 'desc' - */ - SegmentedReq.prototype.setDirection = function (dir) { - switch (dir) { - case 'asc': - case 'desc': - return (this._direction = dir); - default: - throw new TypeError('unknown sort direction "' + dir + '"'); - } - }; - - /** - * Set the function that will be used to sort the rows - * - * @param {fn} - */ - SegmentedReq.prototype.setSortFn = function (sortFn) { - this._sortFn = sortFn; - }; - - /** - * Set the sort total number of documents to - * emit - * - * Setting to false will not limit the documents, - * if a number is set the size of the request to es - * will be updated on each new request - * - * @param {number|false} - */ - SegmentedReq.prototype.setSize = function (totalSize) { - this._desiredSize = _.parseInt(totalSize); - if (isNaN(this._desiredSize)) this._desiredSize = null; - }; - - SegmentedReq.prototype._createQueue = function () { - var self = this; - var timeBounds = timefilter.getBounds(); - var indexPattern = self.source.get('index'); - self._queueCreated = false; - - return indexPattern.toDetailedIndexList(timeBounds.min, timeBounds.max, self._direction) - .then(function (queue) { - if (!_.isArray(queue)) queue = [queue]; - - self._queue = queue; - self._queueCreated = true; - - return queue; - }); - }; - - SegmentedReq.prototype._reportStatus = function () { - return this._handle.emit('status', { - total: this._queueCreated ? this._all.length : NaN, - complete: this._queueCreated ? this._complete.length : NaN, - remaining: this._queueCreated ? this._queue.length : NaN, - hitCount: this._queueCreated ? this._mergedResp.hits.hits.length : NaN - }); - }; - - SegmentedReq.prototype._getFlattenedSource = function () { - return this.source._flatten(); - }; - - SegmentedReq.prototype._consumeSegment = function (seg) { - var index = this._active; - this._complete.push(index); - if (!seg) return; // segment was ignored/filtered, don't store it - - var hadHits = _.get(this._mergedResp, 'hits.hits.length') > 0; - var gotHits = _.get(seg, 'hits.hits.length') > 0; - var firstHits = !hadHits && gotHits; - var haveHits = hadHits || gotHits; - - this._mergeSegment(seg); - this.resp = _.omit(this._mergedResp, '_bucketIndex'); - - if (firstHits) this._handle.emit('first', seg); - if (gotHits) this._handle.emit('segment', seg); - if (haveHits) this._handle.emit('mergedSegment', this.resp); - }; - - SegmentedReq.prototype._mergeHits = function (hits) { - var mergedHits = this._mergedResp.hits.hits; - var desiredSize = this._desiredSize; - var sortFn = this._sortFn; - - _.pushAll(hits, mergedHits); - - if (sortFn) { - notify.event('resort rows', function () { - mergedHits.sort(sortFn); + return super.start(); }); } - if (isNumber(desiredSize)) { - mergedHits = this._mergedResp.hits.hits = mergedHits.slice(0, desiredSize); - } - }; - - SegmentedReq.prototype._mergeSegment = notify.timed('merge response segment', function (seg) { - var merged = this._mergedResp; - - this._segments.push(seg); - - merged.took += seg.took; - merged.hits.total += seg.hits.total; - merged.hits.max_score = Math.max(merged.hits.max_score, seg.hits.max_score); - - if (_.size(seg.hits.hits)) { - this._mergeHits(seg.hits.hits); - this._detectHitsWindow(merged.hits.hits); + continue() { + return this._reportStatus(); } - if (!seg.aggregations) return; + getFetchParams() { + return this._getFlattenedSource().then(flatSource => { + const params = _.cloneDeep(flatSource); - Object.keys(seg.aggregations).forEach(function (aggKey) { + // calculate the number of indices to fetch in this request in order to prevent + // more than this._maxSegments requests. We use Math.max(1, n) to ensure that each request + // has at least one index pattern, and Math.floor() to make sure that if the + // number of indices does not round out evenly the extra index is tacked onto the last + // request, making sure the first request returns faster. + const remainingSegments = this._maxSegments - this._segments.length; + const indexCount = Math.max(1, Math.floor(this._queue.length / remainingSegments)); - if (!merged.aggregations) { - // start merging aggregations - merged.aggregations = {}; - merged._bucketIndex = {}; - } + const indices = this._active = this._queue.splice(0, indexCount); + params.index = _.pluck(indices, 'index'); - if (!merged.aggregations[aggKey]) { - merged.aggregations[aggKey] = { - buckets: [] - }; - } - - seg.aggregations[aggKey].buckets.forEach(function (bucket) { - var mbucket = merged._bucketIndex[bucket.key]; - if (mbucket) { - mbucket.doc_count += bucket.doc_count; - return; + if (isNumber(this._desiredSize)) { + params.body.size = this._pickSizeForIndices(indices); } - mbucket = merged._bucketIndex[bucket.key] = bucket; - merged.aggregations[aggKey].buckets.push(mbucket); + return params; }); - }); - }); - - SegmentedReq.prototype._detectHitsWindow = function (hits) { - hits = hits || []; - var indexPattern = this.source.get('index'); - var desiredSize = this._desiredSize; - - var size = _.size(hits); - if (!isNumber(desiredSize) || size < desiredSize) { - this._hitWindow = { - size: size, - min: -Infinity, - max: Infinity - }; - return; } - let min; - let max; + handleResponse(resp) { + return this._consumeSegment(resp); + } - hits.forEach(function (deepHit) { - var hit = indexPattern.flattenHit(deepHit); - var time = hit[indexPattern.timeFieldName]; - if (min == null || time < min) min = time; - if (max == null || time > max) max = time; - }); + filterError(resp) { + if (/ClusterBlockException.*index\sclosed/.test(resp.error)) { + this._consumeSegment(false); + return true; + } + } - this._hitWindow = { size, min, max }; - }; + isIncomplete() { + const queueNotCreated = !this._queueCreated; + const queueNotEmpty = this._queue.length > 0; + return queueNotCreated || queueNotEmpty; + } - SegmentedReq.prototype._pickSizeForIndices = function (indices) { - var hitWindow = this._hitWindow; - var desiredSize = this._desiredSize; + clone() { + return new SegmentedReq(this.source, this.defer, this._initFn); + } - if (!isNumber(desiredSize)) return null; - // we don't have any hits yet, get us more info! - if (!hitWindow) return desiredSize; - // the order of documents isn't important, just get us more - if (!this._sortFn) return Math.max(desiredSize - hitWindow.size, 0); - // if all of the documents in every index fall outside of our current doc set, we can ignore them. - var someOverlap = indices.some(function (index) { - return index.min <= hitWindow.max && hitWindow.min <= index.max; - }); + complete() { + this._reportStatus(); + this._handle.emit('complete'); + return super.complete(); + } - return someOverlap ? desiredSize : 0; - }; + /********* + ** SegmentedReq specific methods + *********/ + + + /** + * Set the sort total number of segments to emit + * + * @param {number} + */ + setMaxSegments(maxSegments) { + this._maxSegments = Math.max(_.parseInt(maxSegments), 1); + } + + /** + * Set the sort direction for the request. + * + * @param {string} dir - one of 'asc' or 'desc' + */ + setDirection(dir) { + switch (dir) { + case 'asc': + case 'desc': + return (this._direction = dir); + default: + throw new TypeError('unknown sort direction "' + dir + '"'); + } + } + + /** + * Set the function that will be used to sort the rows + * + * @param {fn} + */ + setSortFn(sortFn) { + this._sortFn = sortFn; + } + + /** + * Set the sort total number of documents to + * emit + * + * Setting to false will not limit the documents, + * if a number is set the size of the request to es + * will be updated on each new request + * + * @param {number|false} + */ + setSize(totalSize) { + this._desiredSize = _.parseInt(totalSize); + if (isNaN(this._desiredSize)) this._desiredSize = null; + } + + _createQueue() { + const timeBounds = timefilter.getBounds(); + const indexPattern = this.source.get('index'); + this._queueCreated = false; + + return indexPattern.toDetailedIndexList(timeBounds.min, timeBounds.max, this._direction) + .then(queue => { + if (!_.isArray(queue)) queue = [queue]; + + this._queue = queue; + this._queueCreated = true; + + return queue; + }); + } + + _reportStatus() { + return this._handle.emit('status', { + total: this._queueCreated ? this._all.length : NaN, + complete: this._queueCreated ? this._complete.length : NaN, + remaining: this._queueCreated ? this._queue.length : NaN, + hitCount: this._queueCreated ? this._mergedResp.hits.hits.length : NaN + }); + } + + _getFlattenedSource() { + return this.source._flatten(); + } + + _consumeSegment(seg) { + const index = this._active; + this._complete.push(index); + if (!seg) return; // segment was ignored/filtered, don't store it + + const hadHits = _.get(this._mergedResp, 'hits.hits.length') > 0; + const gotHits = _.get(seg, 'hits.hits.length') > 0; + const firstHits = !hadHits && gotHits; + const haveHits = hadHits || gotHits; + + this._mergeSegment(seg); + this.resp = _.omit(this._mergedResp, '_bucketIndex'); + + if (firstHits) this._handle.emit('first', seg); + if (gotHits) this._handle.emit('segment', seg); + if (haveHits) this._handle.emit('mergedSegment', this.resp); + } + + _mergeHits(hits) { + const mergedHits = this._mergedResp.hits.hits; + const desiredSize = this._desiredSize; + const sortFn = this._sortFn; + + _.pushAll(hits, mergedHits); + + if (sortFn) { + notify.event('resort rows', function () { + mergedHits.sort(sortFn); + }); + } + + if (isNumber(desiredSize)) { + this._mergedResp.hits.hits = mergedHits.slice(0, desiredSize); + } + } + + _mergeSegment(seg) { + const merged = this._mergedResp; + + this._segments.push(seg); + + merged.took += seg.took; + merged.hits.total += seg.hits.total; + merged.hits.max_score = Math.max(merged.hits.max_score, seg.hits.max_score); + + if (_.size(seg.hits.hits)) { + this._mergeHits(seg.hits.hits); + this._detectHitsWindow(merged.hits.hits); + } + + if (!seg.aggregations) return; + + Object.keys(seg.aggregations).forEach(function (aggKey) { + + if (!merged.aggregations) { + // start merging aggregations + merged.aggregations = {}; + merged._bucketIndex = {}; + } + + if (!merged.aggregations[aggKey]) { + merged.aggregations[aggKey] = { + buckets: [] + }; + } + + seg.aggregations[aggKey].buckets.forEach(function (bucket) { + let mbucket = merged._bucketIndex[bucket.key]; + if (mbucket) { + mbucket.doc_count += bucket.doc_count; + return; + } + + mbucket = merged._bucketIndex[bucket.key] = bucket; + merged.aggregations[aggKey].buckets.push(mbucket); + }); + }); + } + + _detectHitsWindow(hits) { + hits = hits || []; + const indexPattern = this.source.get('index'); + const desiredSize = this._desiredSize; + + const size = _.size(hits); + if (!isNumber(desiredSize) || size < desiredSize) { + this._hitWindow = { + size: size, + min: -Infinity, + max: Infinity + }; + return; + } + + let min; + let max; + + hits.forEach(function (deepHit) { + const hit = indexPattern.flattenHit(deepHit); + const time = hit[indexPattern.timeFieldName]; + if (min == null || time < min) min = time; + if (max == null || time > max) max = time; + }); + + this._hitWindow = { size, min, max }; + } + + _pickSizeForIndices(indices) { + const hitWindow = this._hitWindow; + const desiredSize = this._desiredSize; + + if (!isNumber(desiredSize)) return null; + // we don't have any hits yet, get us more info! + if (!hitWindow) return desiredSize; + // the order of documents isn't important, just get us more + if (!this._sortFn) return Math.max(desiredSize - hitWindow.size, 0); + // if all of the documents in every index fall outside of our current doc set, we can ignore them. + const someOverlap = indices.some(function (index) { + return index.min <= hitWindow.max && hitWindow.min <= index.max; + }); + + return someOverlap ? desiredSize : 0; + } + } + + SegmentedReq.prototype.mergedSegment = notify.timed('merge response segment', SegmentedReq.prototype.mergedSegment); return SegmentedReq; }; diff --git a/src/ui/public/courier/fetch/request/segmented_handle.js b/src/ui/public/courier/fetch/request/segmented_handle.js new file mode 100644 index 000000000000..702378d8392a --- /dev/null +++ b/src/ui/public/courier/fetch/request/segmented_handle.js @@ -0,0 +1,40 @@ +import EventsProvider from 'ui/events'; + +export default function CourierSegmentedReqHandle(Private) { + const Events = Private(EventsProvider); + + const segmentedRequest = Symbol('Actual Segmented Request'); + + /** + * Simple class for creating an object to send to the + * requester of a SegmentedRequest. Since the SegmentedRequest + * extends AbstractRequest, it wasn't able to be the event + * emitter it was born to be. This provides a channel for + * setting values on the segmented request, and an event + * emitter for the request to speak outwardly + * + * @param {SegmentedRequest} - req - the requst this handle relates to + */ + return class SegmentedHandle extends Events { + constructor(req) { + super(); + this[segmentedRequest] = req; + } + + setDirection(...args) { + this[segmentedRequest].setDirection(...args); + } + + setSize(...args) { + this[segmentedRequest].setSize(...args); + } + + setMaxSegments(...args) { + this[segmentedRequest].setMaxSegments(...args); + } + + setSortFn(...args) { + this[segmentedRequest].setSortFn(...args); + } + }; +}; diff --git a/src/ui/public/courier/fetch/strategy/__tests__/search.js b/src/ui/public/courier/fetch/strategy/__tests__/search.js index e71400791248..21d62a2bbb41 100644 --- a/src/ui/public/courier/fetch/strategy/__tests__/search.js +++ b/src/ui/public/courier/fetch/strategy/__tests__/search.js @@ -2,7 +2,9 @@ import _ from 'lodash'; import sinon from 'auto-release-sinon'; import expect from 'expect.js'; import ngMock from 'ngMock'; -import CourierFetchStrategySearchProvider from 'ui/courier/fetch/strategy/search'; + +import SearchStrategyProvider from '../search'; + describe('ui/courier/fetch/strategy/search', () => { let Promise; @@ -15,7 +17,7 @@ describe('ui/courier/fetch/strategy/search', () => { beforeEach(ngMock.inject((Private, $injector) => { Promise = $injector.get('Promise'); $rootScope = $injector.get('$rootScope'); - search = Private(CourierFetchStrategySearchProvider); + search = Private(SearchStrategyProvider); reqsFetchParams = [ { index: ['logstash-123'], diff --git a/src/ui/public/courier/fetch/strategy/search.js b/src/ui/public/courier/fetch/strategy/search.js index 3c2972e4ec35..2abda799343b 100644 --- a/src/ui/public/courier/fetch/strategy/search.js +++ b/src/ui/public/courier/fetch/strategy/search.js @@ -1,6 +1,8 @@ -import { toJson } from 'ui/utils/aggressive_parse'; import _ from 'lodash'; import angular from 'angular'; + +import { toJson } from 'ui/utils/aggressive_parse'; + export default function FetchStrategyForSearch(Private, Promise, timefilter) { return { @@ -20,7 +22,7 @@ export default function FetchStrategyForSearch(Private, Promise, timefilter) { return indexList; } - var timeBounds = timefilter.getBounds(); + const timeBounds = timefilter.getBounds(); return indexList.toIndexList(timeBounds.min, timeBounds.max); }) .then(function (indexList) { diff --git a/src/ui/public/courier/looper/_looper.js b/src/ui/public/courier/looper/_looper.js index 1f76b872407d..fcb25511e6a1 100644 --- a/src/ui/public/courier/looper/_looper.js +++ b/src/ui/public/courier/looper/_looper.js @@ -1,5 +1,9 @@ import _ from 'lodash'; -export default function LooperFactory($timeout, Notifier, Promise) { + +import 'ui/promises'; +import Notifier from 'ui/notify/notifier'; + +export default function LooperFactory($timeout, Promise) { var notify = new Notifier(); function Looper(ms, fn) { diff --git a/src/ui/public/courier/looper/doc.js b/src/ui/public/courier/looper/doc.js index 0a37f334fca7..a1c6104ce20a 100644 --- a/src/ui/public/courier/looper/doc.js +++ b/src/ui/public/courier/looper/doc.js @@ -1,18 +1,18 @@ -import CourierFetchFetchProvider from 'ui/courier/fetch/fetch'; -import CourierLooperLooperProvider from 'ui/courier/looper/_looper'; -import CourierFetchStrategyDocProvider from 'ui/courier/fetch/strategy/doc'; +import FetchProvider from '../fetch'; +import LooperProvider from './_looper'; +import DocStrategyProvider from '../fetch/strategy/doc'; export default function DocLooperService(Private) { - var fetch = Private(CourierFetchFetchProvider); - var Looper = Private(CourierLooperLooperProvider); - var docStrategy = Private(CourierFetchStrategyDocProvider); + var fetch = Private(FetchProvider); + var Looper = Private(LooperProvider); + var DocStrategy = Private(DocStrategyProvider); /** * The Looper which will manage the doc fetch interval * @type {Looper} */ var docLooper = new Looper(1500, function () { - fetch.fetchQueued(docStrategy); + fetch.fetchQueued(DocStrategy); }); return docLooper; diff --git a/src/ui/public/courier/looper/search.js b/src/ui/public/courier/looper/search.js index a3f5dfd57e3b..cb3914c601c0 100644 --- a/src/ui/public/courier/looper/search.js +++ b/src/ui/public/courier/looper/search.js @@ -1,14 +1,14 @@ -import CourierFetchFetchProvider from 'ui/courier/fetch/fetch'; -import CourierFetchStrategySearchProvider from 'ui/courier/fetch/strategy/search'; -import CourierRequestQueueProvider from 'ui/courier/_request_queue'; -import CourierLooperLooperProvider from 'ui/courier/looper/_looper'; +import FetchProvider from '../fetch'; +import SearchStrategyProvider from '../fetch/strategy/search'; +import RequestQueueProvider from '../_request_queue'; +import LooperProvider from './_looper'; export default function SearchLooperService(Private, Promise, Notifier, $rootScope) { - var fetch = Private(CourierFetchFetchProvider); - var searchStrategy = Private(CourierFetchStrategySearchProvider); - var requestQueue = Private(CourierRequestQueueProvider); + var fetch = Private(FetchProvider); + var searchStrategy = Private(SearchStrategyProvider); + var requestQueue = Private(RequestQueueProvider); - var Looper = Private(CourierLooperLooperProvider); + var Looper = Private(LooperProvider); var notif = new Notifier({ location: 'Search Looper' }); /** diff --git a/src/ui/public/courier/saved_object/saved_object.js b/src/ui/public/courier/saved_object/saved_object.js index ea568383410c..4aae5a210cd1 100644 --- a/src/ui/public/courier/saved_object/saved_object.js +++ b/src/ui/public/courier/saved_object/saved_object.js @@ -1,15 +1,18 @@ import angular from 'angular'; -import errors from 'ui/errors'; import _ from 'lodash'; + +import errors from 'ui/errors'; import slugifyId from 'ui/utils/slugify_id'; -import CourierDataSourceDocSourceProvider from 'ui/courier/data_source/doc_source'; -import CourierDataSourceSearchSourceProvider from 'ui/courier/data_source/search_source'; -import UtilsMappingSetupProvider from 'ui/utils/mapping_setup'; +import MappingSetupProvider from 'ui/utils/mapping_setup'; + +import DocSourceProvider from '../data_source/doc_source'; +import SearchSourceProvider from '../data_source/search_source'; + export default function SavedObjectFactory(es, kbnIndex, Promise, Private, Notifier, safeConfirm, indexPatterns) { - var DocSource = Private(CourierDataSourceDocSourceProvider); - var SearchSource = Private(CourierDataSourceSearchSourceProvider); - var mappingSetup = Private(UtilsMappingSetupProvider); + var DocSource = Private(DocSourceProvider); + var SearchSource = Private(SearchSourceProvider); + var mappingSetup = Private(MappingSetupProvider); function SavedObject(config) { if (!_.isObject(config)) config = {}; diff --git a/src/ui/public/index_patterns/__tests__/_index_pattern.js b/src/ui/public/index_patterns/__tests__/_index_pattern.js index 79585e3728c1..d8785a8c714a 100644 --- a/src/ui/public/index_patterns/__tests__/_index_pattern.js +++ b/src/ui/public/index_patterns/__tests__/_index_pattern.js @@ -7,7 +7,7 @@ import errors from 'ui/errors'; import IndexedArray from 'ui/IndexedArray'; import FixturesLogstashFieldsProvider from 'fixtures/logstash_fields'; import FixturesStubbedDocSourceResponseProvider from 'fixtures/stubbed_doc_source_response'; -import CourierDataSourceDocSourceProvider from 'ui/courier/data_source/doc_source'; +import DocSourceProvider from 'ui/courier/data_source/doc_source'; import IndexPatternsMapperProvider from 'ui/index_patterns/_mapper'; import UtilsMappingSetupProvider from 'ui/utils/mapping_setup'; import IndexPatternsIntervalsProvider from 'ui/index_patterns/_intervals'; @@ -33,7 +33,7 @@ describe('index pattern', function () { mockLogstashFields = Private(FixturesLogstashFieldsProvider); docSourceResponse = Private(FixturesStubbedDocSourceResponseProvider); - DocSource = Private(CourierDataSourceDocSourceProvider); + DocSource = Private(DocSourceProvider); sinon.stub(DocSource.prototype, 'doIndex'); sinon.stub(DocSource.prototype, 'fetch'); diff --git a/src/ui/public/index_patterns/_index_pattern.js b/src/ui/public/index_patterns/_index_pattern.js index e890fb540ba7..f469e5cd5a85 100644 --- a/src/ui/public/index_patterns/_index_pattern.js +++ b/src/ui/public/index_patterns/_index_pattern.js @@ -7,7 +7,7 @@ import RegistryFieldFormatsProvider from 'ui/registry/field_formats'; import IndexPatternsGetIdsProvider from 'ui/index_patterns/_get_ids'; import IndexPatternsMapperProvider from 'ui/index_patterns/_mapper'; import IndexPatternsIntervalsProvider from 'ui/index_patterns/_intervals'; -import CourierDataSourceDocSourceProvider from 'ui/courier/data_source/doc_source'; +import DocSourceProvider from 'ui/courier/data_source/doc_source'; import UtilsMappingSetupProvider from 'ui/utils/mapping_setup'; import IndexPatternsFieldListProvider from 'ui/index_patterns/_field_list'; import IndexPatternsFlattenHitProvider from 'ui/index_patterns/_flatten_hit'; @@ -19,7 +19,7 @@ export default function IndexPatternFactory(Private, timefilter, Notifier, confi var getIds = Private(IndexPatternsGetIdsProvider); var mapper = Private(IndexPatternsMapperProvider); var intervals = Private(IndexPatternsIntervalsProvider); - var DocSource = Private(CourierDataSourceDocSourceProvider); + var DocSource = Private(DocSourceProvider); var mappingSetup = Private(UtilsMappingSetupProvider); var FieldList = Private(IndexPatternsFieldListProvider); diff --git a/src/ui/public/index_patterns/_mapper.js b/src/ui/public/index_patterns/_mapper.js index adfaef46b48b..16bdce7d4958 100644 --- a/src/ui/public/index_patterns/_mapper.js +++ b/src/ui/public/index_patterns/_mapper.js @@ -76,7 +76,7 @@ export default function MapperService(Private, Promise, es, config, kbnIndex) { }; self.getIndicesForIndexPattern = function (indexPattern) { - return es.indices.getAliases({ + return es.indices.getAlias({ index: patternToWildcard(indexPattern.id) }) .then(function (resp) { diff --git a/src/ui/public/parse_query/lib/from_user.js b/src/ui/public/parse_query/lib/from_user.js index 42f76da0b16b..c2eefd85c483 100644 --- a/src/ui/public/parse_query/lib/from_user.js +++ b/src/ui/public/parse_query/lib/from_user.js @@ -1,7 +1,7 @@ import _ from 'lodash'; -import CourierDataSourceDecorateQueryProvider from 'ui/courier/data_source/_decorate_query'; +import DecorateQueryProvider from 'ui/courier/data_source/_decorate_query'; export default function GetQueryFromUser(es, Private) { - var decorateQuery = Private(CourierDataSourceDecorateQueryProvider); + var decorateQuery = Private(DecorateQueryProvider); /** * Take text from the user and make it into a query object diff --git a/src/ui/public/stringify/__tests__/_conformance.js b/src/ui/public/stringify/__tests__/_conformance.js index 6218e5a49c0e..af3792d0da70 100644 --- a/src/ui/public/stringify/__tests__/_conformance.js +++ b/src/ui/public/stringify/__tests__/_conformance.js @@ -11,6 +11,7 @@ var config; var formatIds = [ 'bytes', 'date', + 'duration', 'ip', 'number', 'percent', diff --git a/src/ui/public/stringify/__tests__/_duration.js b/src/ui/public/stringify/__tests__/_duration.js new file mode 100644 index 000000000000..a9095e03ebdb --- /dev/null +++ b/src/ui/public/stringify/__tests__/_duration.js @@ -0,0 +1,50 @@ +import expect from 'expect.js'; +import ngMock from 'ngMock'; +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; + }; + } +}); diff --git a/src/ui/public/stringify/__tests__/_ip.js b/src/ui/public/stringify/__tests__/_ip.js index 9ac9d1172893..034206c8f3b8 100644 --- a/src/ui/public/stringify/__tests__/_ip.js +++ b/src/ui/public/stringify/__tests__/_ip.js @@ -9,7 +9,7 @@ describe('IP Address Format', function () { fieldFormats = Private(RegistryFieldFormatsProvider); })); - it('convers a value from a decimal to a string', function () { + it('converts a value from a decimal to a string', function () { var ip = fieldFormats.getInstance('ip'); expect(ip.convert(1186489492)).to.be('70.184.100.148'); }); diff --git a/src/ui/public/stringify/__tests__/index.js b/src/ui/public/stringify/__tests__/index.js index 33c1e2f30b68..7777561ae38a 100644 --- a/src/ui/public/stringify/__tests__/index.js +++ b/src/ui/public/stringify/__tests__/index.js @@ -5,6 +5,7 @@ import './_string'; import './_url'; import './_color'; import './_date'; +import './_duration'; import './_truncate'; describe('Stringify Component', function () { }); diff --git a/src/ui/public/stringify/editors/duration.html b/src/ui/public/stringify/editors/duration.html new file mode 100644 index 000000000000..12220015fff3 --- /dev/null +++ b/src/ui/public/stringify/editors/duration.html @@ -0,0 +1,28 @@ +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
diff --git a/src/ui/public/stringify/editors/duration.less b/src/ui/public/stringify/editors/duration.less new file mode 100644 index 000000000000..bde21dd4da8a --- /dev/null +++ b/src/ui/public/stringify/editors/duration.less @@ -0,0 +1,10 @@ +.editor-duration { + display: flex; + > .form-group { + flex: 1 1 1%; + padding-right: 5px; + &:last-child { + padding-right: 0; + } + } +} diff --git a/src/ui/public/stringify/register.js b/src/ui/public/stringify/register.js index b03389afc8c6..7b6657c48688 100644 --- a/src/ui/public/stringify/register.js +++ b/src/ui/public/stringify/register.js @@ -2,6 +2,7 @@ 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'; @@ -12,6 +13,7 @@ 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); diff --git a/src/ui/public/stringify/types/Color.js b/src/ui/public/stringify/types/Color.js index 645a94ef84ac..3ce45193f585 100644 --- a/src/ui/public/stringify/types/Color.js +++ b/src/ui/public/stringify/types/Color.js @@ -1,10 +1,10 @@ import 'ui/stringify/editors/color.less'; import _ from 'lodash'; -import IndexPatternsFieldFormatFieldFormatProvider from 'ui/index_patterns/_field_format/FieldFormat'; +import IndexPatternsFieldFormatProvider from 'ui/index_patterns/_field_format/FieldFormat'; import colorTemplate from 'ui/stringify/editors/color.html'; -export default function _StringProvider(Private) { +export default function ColorFormatProvider(Private) { - const FieldFormat = Private(IndexPatternsFieldFormatFieldFormatProvider); + const FieldFormat = Private(IndexPatternsFieldFormatProvider); const DEFAULT_COLOR = { range: `${Number.NEGATIVE_INFINITY}:${Number.POSITIVE_INFINITY}`, text: '#000000', diff --git a/src/ui/public/stringify/types/Date.js b/src/ui/public/stringify/types/Date.js index 70ae1b3873f7..66c955270f97 100644 --- a/src/ui/public/stringify/types/Date.js +++ b/src/ui/public/stringify/types/Date.js @@ -1,11 +1,11 @@ import _ from 'lodash'; import moment from 'moment'; import 'ui/field_format_editor/pattern/pattern'; -import IndexPatternsFieldFormatFieldFormatProvider from 'ui/index_patterns/_field_format/FieldFormat'; +import IndexPatternsFieldFormatProvider from 'ui/index_patterns/_field_format/FieldFormat'; import BoundToConfigObjProvider from 'ui/bound_to_config_obj'; import dateTemplate from 'ui/stringify/editors/date.html'; export default function DateTimeFormatProvider(Private) { - var FieldFormat = Private(IndexPatternsFieldFormatFieldFormatProvider); + var FieldFormat = Private(IndexPatternsFieldFormatProvider); var BoundToConfigObj = Private(BoundToConfigObjProvider); diff --git a/src/ui/public/stringify/types/Ip.js b/src/ui/public/stringify/types/Ip.js index b2e1d2bdf319..a23fd8c36b64 100644 --- a/src/ui/public/stringify/types/Ip.js +++ b/src/ui/public/stringify/types/Ip.js @@ -1,7 +1,7 @@ import _ from 'lodash'; -import IndexPatternsFieldFormatFieldFormatProvider from 'ui/index_patterns/_field_format/FieldFormat'; +import IndexPatternsFieldFormatProvider from 'ui/index_patterns/_field_format/FieldFormat'; export default function IpFormatProvider(Private) { - var FieldFormat = Private(IndexPatternsFieldFormatFieldFormatProvider); + var FieldFormat = Private(IndexPatternsFieldFormatProvider); _.class(Ip).inherits(FieldFormat); function Ip(params) { diff --git a/src/ui/public/stringify/types/Percent.js b/src/ui/public/stringify/types/Percent.js index 3709d0419f7b..0f94b18daa82 100644 --- a/src/ui/public/stringify/types/Percent.js +++ b/src/ui/public/stringify/types/Percent.js @@ -1,7 +1,7 @@ import _ from 'lodash'; import BoundToConfigObjProvider from 'ui/bound_to_config_obj'; import StringifyTypesNumeralProvider from 'ui/stringify/types/_Numeral'; -export default function NumberFormatProvider(Private) { +export default function PercentFormatProvider(Private) { var BoundToConfigObj = Private(BoundToConfigObjProvider); var Numeral = Private(StringifyTypesNumeralProvider); diff --git a/src/ui/public/stringify/types/Source.js b/src/ui/public/stringify/types/Source.js index c874b2b483f8..7e80a0e2304b 100644 --- a/src/ui/public/stringify/types/Source.js +++ b/src/ui/public/stringify/types/Source.js @@ -1,9 +1,9 @@ import _ from 'lodash'; import noWhiteSpace from 'ui/utils/no_white_space'; import angular from 'angular'; -import IndexPatternsFieldFormatFieldFormatProvider from 'ui/index_patterns/_field_format/FieldFormat'; -export default function _SourceProvider(Private, shortDotsFilter) { - var FieldFormat = Private(IndexPatternsFieldFormatFieldFormatProvider); +import IndexPatternsFieldFormatProvider from 'ui/index_patterns/_field_format/FieldFormat'; +export default function _SourceFormatProvider(Private, shortDotsFilter) { + var FieldFormat = Private(IndexPatternsFieldFormatProvider); var template = _.template(noWhiteSpace(require('ui/stringify/types/_source.html'))); _.class(Source).inherits(FieldFormat); diff --git a/src/ui/public/stringify/types/String.js b/src/ui/public/stringify/types/String.js index e5b11c918680..b955aebcd919 100644 --- a/src/ui/public/stringify/types/String.js +++ b/src/ui/public/stringify/types/String.js @@ -1,8 +1,8 @@ import _ from 'lodash'; import 'ui/field_format_editor/samples/samples'; -import IndexPatternsFieldFormatFieldFormatProvider from 'ui/index_patterns/_field_format/FieldFormat'; -export default function _StringProvider(Private) { - var FieldFormat = Private(IndexPatternsFieldFormatFieldFormatProvider); +import IndexPatternsFieldFormatProvider from 'ui/index_patterns/_field_format/FieldFormat'; +export default function StringFormatProvider(Private) { + var FieldFormat = Private(IndexPatternsFieldFormatProvider); _.class(_String).inherits(FieldFormat); diff --git a/src/ui/public/stringify/types/Url.js b/src/ui/public/stringify/types/Url.js index d8d6c01c2779..b2c4a635adb9 100644 --- a/src/ui/public/stringify/types/Url.js +++ b/src/ui/public/stringify/types/Url.js @@ -1,11 +1,11 @@ import _ from 'lodash'; import 'ui/field_format_editor/pattern/pattern'; import 'ui/stringify/icons'; -import IndexPatternsFieldFormatFieldFormatProvider from 'ui/index_patterns/_field_format/FieldFormat'; +import IndexPatternsFieldFormatProvider from 'ui/index_patterns/_field_format/FieldFormat'; import urlTemplate from 'ui/stringify/editors/url.html'; export default function UrlFormatProvider(Private, highlightFilter) { - var FieldFormat = Private(IndexPatternsFieldFormatFieldFormatProvider); + var FieldFormat = Private(IndexPatternsFieldFormatProvider); _.class(Url).inherits(FieldFormat); diff --git a/src/ui/public/stringify/types/_Numeral.js b/src/ui/public/stringify/types/_Numeral.js index 7769319d9d35..f979ed6c8f20 100644 --- a/src/ui/public/stringify/types/_Numeral.js +++ b/src/ui/public/stringify/types/_Numeral.js @@ -1,9 +1,9 @@ import _ from 'lodash'; import 'ui/field_format_editor/numeral/numeral'; -import IndexPatternsFieldFormatFieldFormatProvider from 'ui/index_patterns/_field_format/FieldFormat'; +import IndexPatternsFieldFormatProvider from 'ui/index_patterns/_field_format/FieldFormat'; import BoundToConfigObjProvider from 'ui/bound_to_config_obj'; export default function AbstractNumeralFormatProvider(Private) { - var FieldFormat = Private(IndexPatternsFieldFormatFieldFormatProvider); + var FieldFormat = Private(IndexPatternsFieldFormatProvider); var BoundToConfigObj = Private(BoundToConfigObjProvider); var numeral = require('numeral')(); diff --git a/src/ui/public/stringify/types/duration.js b/src/ui/public/stringify/types/duration.js new file mode 100644 index 000000000000..719f543da3e4 --- /dev/null +++ b/src/ui/public/stringify/types/duration.js @@ -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/FieldFormat'; +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); + } +}; diff --git a/src/ui/public/stringify/types/truncate.js b/src/ui/public/stringify/types/truncate.js index 05d650dbe7a4..4f96235b1f33 100644 --- a/src/ui/public/stringify/types/truncate.js +++ b/src/ui/public/stringify/types/truncate.js @@ -1,7 +1,7 @@ import _ from 'lodash'; -import IndexPatternsFieldFormatFieldFormatProvider from 'ui/index_patterns/_field_format/FieldFormat'; +import IndexPatternsFieldFormatProvider from 'ui/index_patterns/_field_format/FieldFormat'; export default function TruncateFormatProvider(Private) { - var FieldFormat = Private(IndexPatternsFieldFormatFieldFormatProvider); + var FieldFormat = Private(IndexPatternsFieldFormatProvider); var omission = '...'; _.class(Truncate).inherits(FieldFormat); @@ -31,4 +31,4 @@ export default function TruncateFormatProvider(Private) { Truncate.sampleInput = [ require('ui/stringify/samples/large.html') ]; return Truncate; -}; \ No newline at end of file +}; diff --git a/src/ui/public/utils/__tests__/scanner.js b/src/ui/public/utils/__tests__/scanner.js index 9e1c89d8d7c8..9abc4ca618c7 100644 --- a/src/ui/public/utils/__tests__/scanner.js +++ b/src/ui/public/utils/__tests__/scanner.js @@ -4,6 +4,9 @@ import Bluebird from 'bluebird'; import 'elasticsearch-browser'; import ngMock from 'ngMock'; import sinon from 'sinon'; +import url from 'url'; + +import serverConfig from '../../../../../test/serverConfig'; describe('Scanner', function () { let es; @@ -11,7 +14,7 @@ describe('Scanner', function () { 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(); } diff --git a/tasks/config/esvm.js b/tasks/config/esvm.js index 89bf4115333b..38b2468a2549 100644 --- a/tasks/config/esvm.js +++ b/tasks/config/esvm.js @@ -2,7 +2,7 @@ module.exports = function (grunt) { var resolve = require('path').resolve; var directory = resolve(__dirname, '../../esvm'); var dataDir = resolve(directory, 'data_dir'); - var uiConfig = require('../../test/serverConfig'); + var serverConfig = require('../../test/serverConfig'); return { options: { @@ -14,11 +14,6 @@ module.exports = function (grunt) { }, http: { port: 9200 - }, - marvel: { - agent: { - enabled: false - } } } }, @@ -41,7 +36,7 @@ module.exports = function (grunt) { purge: true, config: { http: { - port: 9210 + port: serverConfig.servers.elasticsearch.port }, cluster: { name: 'esvm-test' @@ -55,7 +50,7 @@ module.exports = function (grunt) { purge: true, config: { http: { - port: uiConfig.servers.elasticsearch.port + port: serverConfig.servers.elasticsearch.port }, cluster: { name: 'esvm-ui' diff --git a/test/utils/__tests__/getPage.js b/test/utils/__tests__/getPage.js index 19ce3a1fae24..1c2b0bf2dd87 100644 --- a/test/utils/__tests__/getPage.js +++ b/test/utils/__tests__/getPage.js @@ -13,7 +13,7 @@ describe('getUrl', function () { expect(url).to.be('http://localhost/foo'); }); - it('should convert to a secure url with port', function () { + it('should convert to a url with port', function () { var url = getUrl({ protocol: 'http', hostname: 'localhost', diff --git a/test/utils/kbn_server.js b/test/utils/kbn_server.js index eb77401615dc..cc5649669cb1 100644 --- a/test/utils/kbn_server.js +++ b/test/utils/kbn_server.js @@ -1,8 +1,10 @@ +import url from 'url'; import { defaultsDeep, set } from 'lodash'; import { header as basicAuthHeader } from './base_auth'; import { kibanaUser, kibanaServer } from '../shield'; import KbnServer from '../../src/server/KbnServer'; import fromRoot from '../../src/utils/fromRoot'; +import serverConfig from '../serverConfig'; const SERVER_DEFAULTS = { server: { @@ -23,7 +25,7 @@ const SERVER_DEFAULTS = { enabled: false }, elasticsearch: { - url: 'http://localhost:9210', + url: url.format(serverConfig.servers.elasticsearch), username: kibanaServer.username, password: kibanaServer.password }