From c4ecfa26758dea15f8cec70ab6eab60ad0462567 Mon Sep 17 00:00:00 2001 From: Ahmad Bamieh Date: Tue, 23 Mar 2021 18:27:30 +0200 Subject: [PATCH 1/6] remove bluebird from deps --- package.json | 2 - .../public/saved_object/saved_object.test.ts | 93 ++++---- .../server/handlers/chain_runner.js | 11 +- .../vis_type_timelion/server/lib/alter.js | 3 +- .../vis_type_timelion/server/routes/run.ts | 3 +- .../server/series_functions/static.js | 3 +- .../series_functions/worldbank_indicators.js | 3 +- .../server/series_functions/yaxis.test.js | 11 +- .../apis/kql_telemetry/kql_telemetry.ts | 3 +- .../server/lib/details/get_metrics.js | 53 +++-- .../lib/kibana/get_kibanas_for_clusters.js | 215 ++++++++--------- .../lib/logstash/get_logstash_for_clusters.js | 221 +++++++++--------- yarn.lock | 7 +- 13 files changed, 309 insertions(+), 319 deletions(-) diff --git a/package.json b/package.json index 32cf8dc1aee0f..e8d21636759be 100644 --- a/package.json +++ b/package.json @@ -166,7 +166,6 @@ "apollo-server-hapi": "^1.3.6", "archiver": "^5.2.0", "axios": "^0.21.1", - "bluebird": "3.5.5", "brace": "0.11.1", "chalk": "^4.1.0", "check-disk-space": "^2.1.0", @@ -408,7 +407,6 @@ "@types/archiver": "^5.1.0", "@types/babel__core": "^7.1.12", "@types/base64-js": "^1.2.5", - "@types/bluebird": "^3.1.1", "@types/chance": "^1.0.0", "@types/cheerio": "^0.22.10", "@types/chroma-js": "^1.4.2", diff --git a/src/plugins/saved_objects/public/saved_object/saved_object.test.ts b/src/plugins/saved_objects/public/saved_object/saved_object.test.ts index 169160b247cb7..afd898b716627 100644 --- a/src/plugins/saved_objects/public/saved_object/saved_object.test.ts +++ b/src/plugins/saved_objects/public/saved_object/saved_object.test.ts @@ -6,7 +6,6 @@ * Side Public License, v 1. */ -import Bluebird from 'bluebird'; import { createSavedObjectClass } from './saved_object'; import { SavedObject, @@ -57,25 +56,26 @@ describe('Saved Object', () => { */ function stubESResponse(mockDocResponse: SimpleSavedObject) { // Stub out search for duplicate title: - savedObjectsClientStub.get = jest.fn().mockReturnValue(Bluebird.resolve(mockDocResponse)); - savedObjectsClientStub.update = jest.fn().mockReturnValue(Bluebird.resolve(mockDocResponse)); + savedObjectsClientStub.get = jest.fn().mockResolvedValue(mockDocResponse); + savedObjectsClientStub.update = jest.fn().mockResolvedValue(mockDocResponse); - savedObjectsClientStub.find = jest - .fn() - .mockReturnValue(Bluebird.resolve({ savedObjects: [], total: 0 })); + savedObjectsClientStub.find = jest.fn().mockResolvedValue({ savedObjects: [], total: 0 }); savedObjectsClientStub.bulkGet = jest .fn() - .mockReturnValue(Bluebird.resolve({ savedObjects: [mockDocResponse] })); + .mockResolvedValue({ savedObjects: [mockDocResponse] }); } function stubSavedObjectsClientCreate( resp: SimpleSavedObject | string, resolve = true ) { - savedObjectsClientStub.create = jest - .fn() - .mockReturnValue(resolve ? Bluebird.resolve(resp) : Bluebird.reject(resp)); + savedObjectsClientStub.create = jest.fn().mockImplementation(async () => { + if (resolve) { + return resp; + } + throw resp; + }); } /** @@ -257,21 +257,20 @@ describe('Saved Object', () => { ); }); - it('as false does not create a copy', () => { + it('as false does not create a copy', async () => { const myId = 'myId'; stubESResponse(getMockedDocResponse(myId)); + const savedObject = await createInitializedSavedObject({ type: 'dashboard', id: myId }); - return createInitializedSavedObject({ type: 'dashboard', id: myId }).then((savedObject) => { - savedObjectsClientStub.create = jest.fn().mockImplementation(() => { - expect(savedObject.id).toBe(myId); - return Bluebird.resolve({ id: myId }); - }); - savedObject.copyOnSave = false; - - return savedObject.save(saveOptionsMock).then((id) => { - expect(id).toBe(myId); - }); + savedObjectsClientStub.create = jest.fn().mockImplementation(async () => { + expect(savedObject.id).toBe(myId); + return { id: myId }; }); + + savedObject.copyOnSave = false; + const id = await savedObject.save(saveOptionsMock); + expect(id).toBe(myId); + expect(savedObjectsClientStub.create).toBeCalled(); }); }); @@ -291,40 +290,40 @@ describe('Saved Object', () => { }); describe('updates isSaving variable', () => { - it('on success', () => { + it('on success', async () => { const id = 'id'; stubESResponse(getMockedDocResponse(id)); - return createInitializedSavedObject({ type: 'dashboard', id }).then((savedObject) => { - savedObjectsClientStub.create = jest.fn().mockImplementation(() => { - expect(savedObject.isSaving).toBe(true); - return Bluebird.resolve({ - type: 'dashboard', - id, - _version: 'foo', - }); - }); + const savedObject = await createInitializedSavedObject({ type: 'dashboard', id }); - expect(savedObject.isSaving).toBe(false); - return savedObject.save(saveOptionsMock).then(() => { - expect(savedObject.isSaving).toBe(false); - }); + savedObjectsClientStub.create = jest.fn().mockImplementation(async () => { + expect(savedObject.isSaving).toBe(true); + return { + type: 'dashboard', + id, + _version: 'foo', + }; }); + + expect(savedObject.isSaving).toBe(false); + await savedObject.save(saveOptionsMock); + expect(savedObjectsClientStub.create).toBeCalled(); + expect(savedObject.isSaving).toBe(false); }); - it('on failure', () => { + it('on failure', async () => { stubESResponse(getMockedDocResponse('id')); - return createInitializedSavedObject({ type: 'dashboard' }).then((savedObject) => { - savedObjectsClientStub.create = jest.fn().mockImplementation(() => { - expect(savedObject.isSaving).toBe(true); - return Bluebird.reject(''); - }); + const savedObject = await createInitializedSavedObject({ type: 'dashboard' }); - expect(savedObject.isSaving).toBe(false); - return savedObject.save(saveOptionsMock).catch(() => { - expect(savedObject.isSaving).toBe(false); - }); + savedObjectsClientStub.create = jest.fn().mockImplementation(() => { + expect(savedObject.isSaving).toBe(true); + throw new Error('some error'); }); + + expect(savedObject.isSaving).toBe(false); + await expect(() => savedObject.save(saveOptionsMock)).rejects.toThrowError('some error'); + expect(savedObjectsClientStub.create).toBeCalled(); + expect(savedObject.isSaving).toBe(false); }); }); @@ -745,7 +744,7 @@ describe('Saved Object', () => { ); const savedObject = new SavedObjectClass(config); - savedObject.hydrateIndexPattern = jest.fn().mockImplementation(() => { + savedObject.hydrateIndexPattern = jest.fn().mockImplementation(async () => { const indexPattern = getStubIndexPattern( indexPatternId, getConfig, @@ -755,7 +754,7 @@ describe('Saved Object', () => { ); indexPattern.title = indexPattern.id!; savedObject.searchSource!.setField('index', indexPattern); - return Bluebird.resolve(indexPattern); + return indexPattern; }); expect(!!savedObject.searchSource!.getField('index')).toBe(false); diff --git a/src/plugins/vis_type_timelion/server/handlers/chain_runner.js b/src/plugins/vis_type_timelion/server/handlers/chain_runner.js index b7bdbcdcb57a6..5ef9aa5e5ca89 100644 --- a/src/plugins/vis_type_timelion/server/handlers/chain_runner.js +++ b/src/plugins/vis_type_timelion/server/handlers/chain_runner.js @@ -7,7 +7,6 @@ */ import _ from 'lodash'; -import Bluebird from 'bluebird'; import { i18n } from '@kbn/i18n'; import moment from 'moment'; @@ -34,7 +33,7 @@ export default function chainRunner(tlConfig) { function resolveArgument(item) { if (Array.isArray(item)) { - return Bluebird.all(_.map(item, resolveArgument)); + return Promise.all(_.map(item, resolveArgument)); } if (_.isObject(item)) { @@ -43,7 +42,7 @@ export default function chainRunner(tlConfig) { const itemFunctionDef = tlConfig.getFunction(item.function); if (itemFunctionDef.cacheKey && queryCache[itemFunctionDef.cacheKey(item)]) { stats.queryCount++; - return Bluebird.resolve(_.cloneDeep(queryCache[itemFunctionDef.cacheKey(item)])); + return Promise.resolve(_.cloneDeep(queryCache[itemFunctionDef.cacheKey(item)])); } return invoke(item.function, item.arguments); } @@ -86,7 +85,7 @@ export default function chainRunner(tlConfig) { args = _.map(args, resolveArgument); - return Bluebird.all(args).then(function (args) { + return Promise.all(args).then(function (args) { args.byName = indexArguments(functionDef, args); return functionDef.fn(args, tlConfig); }); @@ -120,7 +119,7 @@ export default function chainRunner(tlConfig) { return args; }); }); - return Bluebird.all(seriesList).then(function (args) { + return Promise.all(seriesList).then(function (args) { const list = _.chain(args).map('list').flatten().value(); const seriesList = _.merge.apply(this, _.flatten([{}, args])); seriesList.list = list; @@ -150,7 +149,7 @@ export default function chainRunner(tlConfig) { }) .value(); - return Bluebird.settle(promises).then(function (resolvedDatasources) { + return Promise.allSettled(promises).then(function (resolvedDatasources) { stats.queryTime = new Date().getTime(); _.each(queries, function (query, i) { diff --git a/src/plugins/vis_type_timelion/server/lib/alter.js b/src/plugins/vis_type_timelion/server/lib/alter.js index 2e234f3405c21..47a57f213cdbb 100644 --- a/src/plugins/vis_type_timelion/server/lib/alter.js +++ b/src/plugins/vis_type_timelion/server/lib/alter.js @@ -6,7 +6,6 @@ * Side Public License, v 1. */ -import Bluebird from 'bluebird'; import _ from 'lodash'; /* @param {Array} args @@ -18,7 +17,7 @@ import _ from 'lodash'; export default function alter(args, fn) { // In theory none of the args should ever be promises. This is probably a waste. - return Bluebird.all(args) + return Promise.all(args) .then(function (args) { const seriesList = args.shift(); diff --git a/src/plugins/vis_type_timelion/server/routes/run.ts b/src/plugins/vis_type_timelion/server/routes/run.ts index b3ab3c61c15d8..58068cc8a3d59 100644 --- a/src/plugins/vis_type_timelion/server/routes/run.ts +++ b/src/plugins/vis_type_timelion/server/routes/run.ts @@ -8,7 +8,6 @@ import { IRouter, Logger, CoreSetup } from 'kibana/server'; import { schema } from '@kbn/config-schema'; -import Bluebird from 'bluebird'; import _ from 'lodash'; // @ts-ignore import chainRunnerFn from '../handlers/chain_runner.js'; @@ -95,7 +94,7 @@ export function runRoute( esShardTimeout: configManager.getEsShardTimeout(), }); const chainRunner = chainRunnerFn(tlConfig); - const sheet = await Bluebird.all(chainRunner.processRequest(request.body)); + const sheet = await Promise.all(chainRunner.processRequest(request.body)); return response.ok({ body: { diff --git a/src/plugins/vis_type_timelion/server/series_functions/static.js b/src/plugins/vis_type_timelion/server/series_functions/static.js index b5e8dd6df6682..afc1bd5afbbb8 100644 --- a/src/plugins/vis_type_timelion/server/series_functions/static.js +++ b/src/plugins/vis_type_timelion/server/series_functions/static.js @@ -9,7 +9,6 @@ import { i18n } from '@kbn/i18n'; import _ from 'lodash'; import Datasource from '../lib/classes/datasource'; -import Bluebird from 'bluebird'; export default new Datasource('static', { aliases: ['value'], @@ -51,7 +50,7 @@ export default new Datasource('static', { }); } - return Bluebird.resolve({ + return Promise.resolve({ type: 'seriesList', list: [ { diff --git a/src/plugins/vis_type_timelion/server/series_functions/worldbank_indicators.js b/src/plugins/vis_type_timelion/server/series_functions/worldbank_indicators.js index ba28a82345522..1f65376385731 100644 --- a/src/plugins/vis_type_timelion/server/series_functions/worldbank_indicators.js +++ b/src/plugins/vis_type_timelion/server/series_functions/worldbank_indicators.js @@ -9,7 +9,6 @@ import { i18n } from '@kbn/i18n'; import _ from 'lodash'; import worldbank from './worldbank.js'; -import Bluebird from 'bluebird'; import Datasource from '../lib/classes/datasource'; export default new Datasource('worldbank_indicators', { @@ -61,7 +60,7 @@ export default new Datasource('worldbank_indicators', { return worldbank.timelionFn(wbArgs, tlConfig); }); - return Bluebird.map(seriesLists, function (seriesList) { + return Promise.all(seriesLists, function (seriesList) { return seriesList.list[0]; }).then(function (list) { return { diff --git a/src/plugins/vis_type_timelion/server/series_functions/yaxis.test.js b/src/plugins/vis_type_timelion/server/series_functions/yaxis.test.js index 6d627832544de..d68aa7ac70117 100644 --- a/src/plugins/vis_type_timelion/server/series_functions/yaxis.test.js +++ b/src/plugins/vis_type_timelion/server/series_functions/yaxis.test.js @@ -7,7 +7,6 @@ */ import fn from './yaxis'; -import Bluebird from 'bluebird'; const expect = require('chai').expect; import invoke from './helpers/invoke_series_fn.js'; @@ -25,7 +24,7 @@ describe('yaxis.js', () => { }); it('puts odd numbers of the left, even on the right, by default', () => { - return Bluebird.all([ + return Promise.all([ invoke(fn, [seriesList, 1]).then((r) => { expect(r.output.list[0]._global.yaxes[0].position).to.equal('left'); }), @@ -39,7 +38,7 @@ describe('yaxis.js', () => { }); it('it lets you override default positions', () => { - return Bluebird.all([ + return Promise.all([ invoke(fn, [seriesList, 1, null, null, 'right']).then((r) => { expect(r.output.list[0]._global.yaxes[0].position).to.equal('right'); }), @@ -50,7 +49,7 @@ describe('yaxis.js', () => { }); it('sets the minimum (default: no min)', () => { - return Bluebird.all([ + return Promise.all([ invoke(fn, [seriesList, 1, null]).then((r) => { expect(r.output.list[0]._global.yaxes[0].min).to.equal(null); }), @@ -61,7 +60,7 @@ describe('yaxis.js', () => { }); it('sets the max (default: no max)', () => { - return Bluebird.all([ + return Promise.all([ invoke(fn, [seriesList, 1, null]).then((r) => { expect(r.output.list[0]._global.yaxes[0].max).to.equal(undefined); }), @@ -72,7 +71,7 @@ describe('yaxis.js', () => { }); it('sets the units (default: no unit', () => { - return Bluebird.all([ + return Promise.all([ invoke(fn, [seriesList, 1, null, null, null, null, null, null]).then((r) => { expect(r.output.list[0]._global.yaxes[0].units).to.equal(undefined); }), diff --git a/test/api_integration/apis/kql_telemetry/kql_telemetry.ts b/test/api_integration/apis/kql_telemetry/kql_telemetry.ts index 5c4a8b25e4c05..4d535f65c5621 100644 --- a/test/api_integration/apis/kql_telemetry/kql_telemetry.ts +++ b/test/api_integration/apis/kql_telemetry/kql_telemetry.ts @@ -7,7 +7,6 @@ */ import expect from '@kbn/expect'; -import Bluebird from 'bluebird'; import { get } from 'lodash'; import { FtrProviderContext } from '../../ftr_provider_context'; @@ -81,7 +80,7 @@ export default function ({ getService }: FtrProviderContext) { }); it('should only accept literal boolean values for the opt_in POST body param', function () { - return Bluebird.all([ + return Promise.all([ supertest .post('/api/kibana/kql_opt_in_stats') .set('content-type', 'application/json') diff --git a/x-pack/plugins/monitoring/server/lib/details/get_metrics.js b/x-pack/plugins/monitoring/server/lib/details/get_metrics.js index da0c2e0b3fcdb..7bd438e878e39 100644 --- a/x-pack/plugins/monitoring/server/lib/details/get_metrics.js +++ b/x-pack/plugins/monitoring/server/lib/details/get_metrics.js @@ -7,7 +7,6 @@ import moment from 'moment'; import { isPlainObject } from 'lodash'; -import Bluebird from 'bluebird'; import { checkParam } from '../error_missing_required'; import { getSeries } from './get_series'; import { calculateTimeseriesInterval } from '../calculate_timeseries_interval'; @@ -38,32 +37,36 @@ export async function getMetrics( min = max - numOfBuckets * bucketSize * 1000; } - return Bluebird.map(metricSet, (metric) => { - // metric names match the literal metric name, but they can be supplied in groups or individually - let metricNames; + const rows = await Promise.all( + metricSet.map(async (metric) => { + // metric names match the literal metric name, but they can be supplied in groups or individually + let metricNames; - if (isPlainObject(metric)) { - metricNames = metric.keys; - } else { - metricNames = [metric]; - } + if (isPlainObject(metric)) { + metricNames = metric.keys; + } else { + metricNames = [metric]; + } - return Bluebird.map(metricNames, (metricName) => { - return getSeries(req, indexPattern, metricName, metricOptions, filters, groupBy, { - min, - max, - bucketSize, - timezone, - }); - }); - }).then((rows) => { - const data = {}; - metricSet.forEach((key, index) => { - // keyName must match the value stored in the html template - const keyName = isPlainObject(key) ? key.name : key; - data[keyName] = rows[index]; - }); + return await Promise.all( + metricNames.map(async (metricName) => { + return await getSeries(req, indexPattern, metricName, metricOptions, filters, groupBy, { + min, + max, + bucketSize, + timezone, + }); + }) + ); + }) + ); - return data; + const data = {}; + metricSet.forEach((key, index) => { + // keyName must match the value stored in the html template + const keyName = isPlainObject(key) ? key.name : key; + data[keyName] = rows[index]; }); + + return data; } diff --git a/x-pack/plugins/monitoring/server/lib/kibana/get_kibanas_for_clusters.js b/x-pack/plugins/monitoring/server/lib/kibana/get_kibanas_for_clusters.js index 002ca93323a8a..27953096b0aac 100644 --- a/x-pack/plugins/monitoring/server/lib/kibana/get_kibanas_for_clusters.js +++ b/x-pack/plugins/monitoring/server/lib/kibana/get_kibanas_for_clusters.js @@ -5,7 +5,6 @@ * 2.0. */ -import Bluebird from 'bluebird'; import { chain, find, get } from 'lodash'; import { checkParam } from '../error_missing_required'; import { createQuery } from '../create_query.js'; @@ -31,137 +30,139 @@ export function getKibanasForClusters(req, kbnIndexPattern, clusters) { const start = req.payload.timeRange.min; const end = req.payload.timeRange.max; - return Bluebird.map(clusters, (cluster) => { - const clusterUuid = cluster.cluster_uuid; - const metric = KibanaClusterMetric.getMetricFields(); - const params = { - index: kbnIndexPattern, - size: 0, - ignoreUnavailable: true, - body: { - query: createQuery({ - type: 'kibana_stats', - start, - end, - clusterUuid, - metric, - }), - aggs: { - kibana_uuids: { - terms: { - field: 'kibana_stats.kibana.uuid', - size: config.get('monitoring.ui.max_bucket_size'), - }, - aggs: { - latest_report: { - terms: { - field: 'kibana_stats.timestamp', - size: 1, - order: { - _key: 'desc', - }, - }, - aggs: { - response_time_max: { - max: { - field: 'kibana_stats.response_times.max', + return Promise.all( + clusters.map(async (cluster) => { + const clusterUuid = cluster.cluster_uuid; + const metric = KibanaClusterMetric.getMetricFields(); + const params = { + index: kbnIndexPattern, + size: 0, + ignoreUnavailable: true, + body: { + query: createQuery({ + type: 'kibana_stats', + start, + end, + clusterUuid, + metric, + }), + aggs: { + kibana_uuids: { + terms: { + field: 'kibana_stats.kibana.uuid', + size: config.get('monitoring.ui.max_bucket_size'), + }, + aggs: { + latest_report: { + terms: { + field: 'kibana_stats.timestamp', + size: 1, + order: { + _key: 'desc', }, }, - memory_rss: { - max: { - field: 'kibana_stats.process.memory.resident_set_size_in_bytes', + aggs: { + response_time_max: { + max: { + field: 'kibana_stats.response_times.max', + }, }, - }, - memory_heap_size_limit: { - max: { - field: 'kibana_stats.process.memory.heap.size_limit', + memory_rss: { + max: { + field: 'kibana_stats.process.memory.resident_set_size_in_bytes', + }, }, - }, - concurrent_connections: { - max: { - field: 'kibana_stats.concurrent_connections', + memory_heap_size_limit: { + max: { + field: 'kibana_stats.process.memory.heap.size_limit', + }, }, - }, - requests_total: { - max: { - field: 'kibana_stats.requests.total', + concurrent_connections: { + max: { + field: 'kibana_stats.concurrent_connections', + }, + }, + requests_total: { + max: { + field: 'kibana_stats.requests.total', + }, }, }, }, - }, - response_time_max_per: { - max_bucket: { - buckets_path: 'latest_report>response_time_max', + response_time_max_per: { + max_bucket: { + buckets_path: 'latest_report>response_time_max', + }, }, - }, - memory_rss_per: { - max_bucket: { - buckets_path: 'latest_report>memory_rss', + memory_rss_per: { + max_bucket: { + buckets_path: 'latest_report>memory_rss', + }, }, - }, - memory_heap_size_limit_per: { - max_bucket: { - buckets_path: 'latest_report>memory_heap_size_limit', + memory_heap_size_limit_per: { + max_bucket: { + buckets_path: 'latest_report>memory_heap_size_limit', + }, }, - }, - concurrent_connections_per: { - max_bucket: { - buckets_path: 'latest_report>concurrent_connections', + concurrent_connections_per: { + max_bucket: { + buckets_path: 'latest_report>concurrent_connections', + }, }, - }, - requests_total_per: { - max_bucket: { - buckets_path: 'latest_report>requests_total', + requests_total_per: { + max_bucket: { + buckets_path: 'latest_report>requests_total', + }, }, }, }, - }, - response_time_max: { - max_bucket: { - buckets_path: 'kibana_uuids>response_time_max_per', - }, - }, - memory_rss: { - sum_bucket: { - buckets_path: 'kibana_uuids>memory_rss_per', + response_time_max: { + max_bucket: { + buckets_path: 'kibana_uuids>response_time_max_per', + }, }, - }, - memory_heap_size_limit: { - sum_bucket: { - buckets_path: 'kibana_uuids>memory_heap_size_limit_per', + memory_rss: { + sum_bucket: { + buckets_path: 'kibana_uuids>memory_rss_per', + }, }, - }, - concurrent_connections: { - sum_bucket: { - buckets_path: 'kibana_uuids>concurrent_connections_per', + memory_heap_size_limit: { + sum_bucket: { + buckets_path: 'kibana_uuids>memory_heap_size_limit_per', + }, }, - }, - requests_total: { - sum_bucket: { - buckets_path: 'kibana_uuids>requests_total_per', + concurrent_connections: { + sum_bucket: { + buckets_path: 'kibana_uuids>concurrent_connections_per', + }, }, - }, - status: { - terms: { - field: 'kibana_stats.kibana.status', - order: { - max_timestamp: 'desc', + requests_total: { + sum_bucket: { + buckets_path: 'kibana_uuids>requests_total_per', }, }, - aggs: { - max_timestamp: { - max: { - field: 'timestamp', + status: { + terms: { + field: 'kibana_stats.kibana.status', + order: { + max_timestamp: 'desc', + }, + }, + aggs: { + max_timestamp: { + max: { + field: 'timestamp', + }, }, }, }, }, }, - }, - }; + }; + + const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('monitoring'); + const result = await callWithRequest(req, 'search', params); - const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('monitoring'); - return callWithRequest(req, 'search', params).then((result) => { const aggregations = get(result, 'aggregations', {}); const kibanaUuids = get(aggregations, 'kibana_uuids.buckets', []); const statusBuckets = get(aggregations, 'status.buckets', []); @@ -207,6 +208,6 @@ export function getKibanasForClusters(req, kbnIndexPattern, clusters) { count: kibanaUuids.length, }, }; - }); - }); + }) + ); } diff --git a/x-pack/plugins/monitoring/server/lib/logstash/get_logstash_for_clusters.js b/x-pack/plugins/monitoring/server/lib/logstash/get_logstash_for_clusters.js index 18f4cb07ba021..6eea75282a868 100644 --- a/x-pack/plugins/monitoring/server/lib/logstash/get_logstash_for_clusters.js +++ b/x-pack/plugins/monitoring/server/lib/logstash/get_logstash_for_clusters.js @@ -5,7 +5,6 @@ * 2.0. */ -import Bluebird from 'bluebird'; import { get } from 'lodash'; import { checkParam } from '../error_missing_required'; import { createQuery } from '../create_query.js'; @@ -43,142 +42,144 @@ export function getLogstashForClusters(req, lsIndexPattern, clusters) { const end = req.payload.timeRange.max; const config = req.server.config(); - return Bluebird.map(clusters, (cluster) => { - const clusterUuid = cluster.cluster_uuid; - const params = { - index: lsIndexPattern, - size: 0, - ignoreUnavailable: true, - body: { - query: createQuery({ - type: 'logstash_stats', - start, - end, - clusterUuid, - metric: LogstashClusterMetric.getMetricFields(), - }), - aggs: { - logstash_uuids: { - terms: { - field: 'logstash_stats.logstash.uuid', - size: config.get('monitoring.ui.max_bucket_size'), - }, - aggs: { - latest_report: { - terms: { - field: 'logstash_stats.timestamp', - size: 1, - order: { - _key: 'desc', - }, - }, - aggs: { - memory_used: { - max: { - field: 'logstash_stats.jvm.mem.heap_used_in_bytes', + return Promise.all( + clusters.map(async (cluster) => { + const clusterUuid = cluster.cluster_uuid; + const params = { + index: lsIndexPattern, + size: 0, + ignoreUnavailable: true, + body: { + query: createQuery({ + type: 'logstash_stats', + start, + end, + clusterUuid, + metric: LogstashClusterMetric.getMetricFields(), + }), + aggs: { + logstash_uuids: { + terms: { + field: 'logstash_stats.logstash.uuid', + size: config.get('monitoring.ui.max_bucket_size'), + }, + aggs: { + latest_report: { + terms: { + field: 'logstash_stats.timestamp', + size: 1, + order: { + _key: 'desc', }, }, - memory: { - max: { - field: 'logstash_stats.jvm.mem.heap_max_in_bytes', + aggs: { + memory_used: { + max: { + field: 'logstash_stats.jvm.mem.heap_used_in_bytes', + }, }, - }, - events_in_total: { - max: { - field: 'logstash_stats.events.in', + memory: { + max: { + field: 'logstash_stats.jvm.mem.heap_max_in_bytes', + }, }, - }, - events_out_total: { - max: { - field: 'logstash_stats.events.out', + events_in_total: { + max: { + field: 'logstash_stats.events.in', + }, + }, + events_out_total: { + max: { + field: 'logstash_stats.events.out', + }, }, }, }, - }, - memory_used_per_node: { - max_bucket: { - buckets_path: 'latest_report>memory_used', + memory_used_per_node: { + max_bucket: { + buckets_path: 'latest_report>memory_used', + }, }, - }, - memory_per_node: { - max_bucket: { - buckets_path: 'latest_report>memory', + memory_per_node: { + max_bucket: { + buckets_path: 'latest_report>memory', + }, }, - }, - events_in_total_per_node: { - max_bucket: { - buckets_path: 'latest_report>events_in_total', + events_in_total_per_node: { + max_bucket: { + buckets_path: 'latest_report>events_in_total', + }, }, - }, - events_out_total_per_node: { - max_bucket: { - buckets_path: 'latest_report>events_out_total', + events_out_total_per_node: { + max_bucket: { + buckets_path: 'latest_report>events_out_total', + }, }, }, }, - }, - logstash_versions: { - terms: { - field: 'logstash_stats.logstash.version', - size: config.get('monitoring.ui.max_bucket_size'), - }, - }, - pipelines_nested: { - nested: { - path: 'logstash_stats.pipelines', + logstash_versions: { + terms: { + field: 'logstash_stats.logstash.version', + size: config.get('monitoring.ui.max_bucket_size'), + }, }, - aggs: { - pipelines: { - sum_bucket: { - buckets_path: 'queue_types>num_pipelines', - }, + pipelines_nested: { + nested: { + path: 'logstash_stats.pipelines', }, - queue_types: { - terms: { - field: 'logstash_stats.pipelines.queue.type', - size: config.get('monitoring.ui.max_bucket_size'), + aggs: { + pipelines: { + sum_bucket: { + buckets_path: 'queue_types>num_pipelines', + }, }, - aggs: { - num_pipelines: { - cardinality: { - field: 'logstash_stats.pipelines.id', + queue_types: { + terms: { + field: 'logstash_stats.pipelines.queue.type', + size: config.get('monitoring.ui.max_bucket_size'), + }, + aggs: { + num_pipelines: { + cardinality: { + field: 'logstash_stats.pipelines.id', + }, }, }, }, }, }, - }, - events_in_total: { - sum_bucket: { - buckets_path: 'logstash_uuids>events_in_total_per_node', + events_in_total: { + sum_bucket: { + buckets_path: 'logstash_uuids>events_in_total_per_node', + }, }, - }, - events_out_total: { - sum_bucket: { - buckets_path: 'logstash_uuids>events_out_total_per_node', + events_out_total: { + sum_bucket: { + buckets_path: 'logstash_uuids>events_out_total_per_node', + }, }, - }, - memory_used: { - sum_bucket: { - buckets_path: 'logstash_uuids>memory_used_per_node', + memory_used: { + sum_bucket: { + buckets_path: 'logstash_uuids>memory_used_per_node', + }, }, - }, - memory: { - sum_bucket: { - buckets_path: 'logstash_uuids>memory_per_node', + memory: { + sum_bucket: { + buckets_path: 'logstash_uuids>memory_per_node', + }, }, - }, - max_uptime: { - max: { - field: 'logstash_stats.jvm.uptime_in_millis', + max_uptime: { + max: { + field: 'logstash_stats.jvm.uptime_in_millis', + }, }, }, }, - }, - }; + }; + + const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('monitoring'); + const result = await callWithRequest(req, 'search', params); - const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('monitoring'); - return callWithRequest(req, 'search', params).then((result) => { const aggregations = get(result, 'aggregations', {}); const logstashUuids = get(aggregations, 'logstash_uuids.buckets', []); const logstashVersions = get(aggregations, 'logstash_versions.buckets', []); @@ -213,6 +214,6 @@ export function getLogstashForClusters(req, lsIndexPattern, clusters) { versions: logstashVersions.map((versionBucket) => versionBucket.key), }, }; - }); - }); + }) + ); } diff --git a/yarn.lock b/yarn.lock index 74bca3901dfe1..464c94eeff8e0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4518,7 +4518,7 @@ resolved "https://registry.yarnpkg.com/@types/base64-js/-/base64-js-1.2.5.tgz#582b2476169a6cba460a214d476c744441d873d5" integrity sha1-WCskdhaabLpGCiFNR2x0REHYc9U= -"@types/bluebird@*", "@types/bluebird@^3.1.1": +"@types/bluebird@*": version "3.5.30" resolved "https://registry.yarnpkg.com/@types/bluebird/-/bluebird-3.5.30.tgz#ee034a0eeea8b84ed868b1aa60d690b08a6cfbc5" integrity sha512-8LhzvcjIoqoi1TghEkRMkbbmM+jhHnBokPGkJWjclMK+Ks0MxEBow3/p2/iFTZ+OIbJHQDSfpgdZEb+af3gfVw== @@ -8296,11 +8296,6 @@ bluebird@3.5.3: resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.3.tgz#7d01c6f9616c9a51ab0f8c549a79dfe6ec33efa7" integrity sha512-/qKPUQlaW1OyR51WeCPBvRnAlnZFUJkCSG5HzGnuIqhgyJtF+T94lFnn33eiazjRm2LAHVy2guNnaq48X9SJuw== -bluebird@3.5.5: - version "3.5.5" - resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.5.tgz#a8d0afd73251effbbd5fe384a77d73003c17a71f" - integrity sha512-5am6HnnfN+urzt4yfg7IgTbotDjIT/u8AJpEt0sIU9FtXfVeezXAPKswrG+xKUCOYAINpSdgZVDU6QFh+cuH3w== - bluebird@3.7.2, bluebird@^3.3.1, bluebird@^3.3.5, bluebird@^3.4.1, bluebird@^3.5.0, bluebird@^3.5.1, bluebird@^3.5.5, bluebird@^3.7.1, bluebird@^3.7.2: version "3.7.2" resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f" From c37d35f98a6a3cd6b6721ad1309812cc329d96b0 Mon Sep 17 00:00:00 2001 From: Ahmad Bamieh Date: Tue, 23 Mar 2021 18:47:20 +0200 Subject: [PATCH 2/6] update sets --- .../series_functions/worldbank_indicators.js | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/plugins/vis_type_timelion/server/series_functions/worldbank_indicators.js b/src/plugins/vis_type_timelion/server/series_functions/worldbank_indicators.js index 1f65376385731..ee0dc193600fc 100644 --- a/src/plugins/vis_type_timelion/server/series_functions/worldbank_indicators.js +++ b/src/plugins/vis_type_timelion/server/series_functions/worldbank_indicators.js @@ -53,20 +53,25 @@ export default new Datasource('worldbank_indicators', { }); const countries = config.country.split(':'); - const seriesLists = _.map(countries, function (country) { + const seriesListSets = _.map(countries, function (country) { const code = 'country/' + country + '/indicator/' + config.indicator; const wbArgs = [code]; wbArgs.byName = { code: code }; return worldbank.timelionFn(wbArgs, tlConfig); }); - return Promise.all(seriesLists, function (seriesList) { - return seriesList.list[0]; - }).then(function (list) { - return { - type: 'seriesList', - list: list, - }; - }); + return Promise.all(seriesListSets) + .then((seriesLists) => { + return seriesLists.reduce((acc, seriesList) => { + acc.push(seriesList.list[0]); + return acc; + }, []); + }) + .then(function (list) { + return { + type: 'seriesList', + list: list, + }; + }); }, }); From 6323b413d8976078694731ab562999685119cb7d Mon Sep 17 00:00:00 2001 From: Ahmad Bamieh Date: Tue, 23 Mar 2021 20:49:19 +0200 Subject: [PATCH 3/6] remove remaining bluebird imports --- .../src/actions/rebuild_all.ts | 10 +- packages/kbn-es-archiver/src/lib/directory.ts | 5 +- .../kbn-test/src/functional_tests/lib/auth.js | 6 +- packages/kbn-test/src/jest/setup/polyfills.js | 7 - .../src/mocha/junit_report_generation.test.js | 5 +- .../kbn-utils/src/streams/map_stream.test.ts | 4 +- src/dev/notice/bundled_notices.js | 10 +- .../precommit_hook/get_files_for_commit.js | 8 +- .../public/components/tag_cloud.test.js | 27 ++-- .../server/series_functions/quandl.js | 2 - test/functional/page_objects/common_page.ts | 4 +- test/functional/page_objects/login_page.ts | 4 +- .../management/saved_objects_page.ts | 151 +++++++++--------- test/functional/page_objects/settings_page.ts | 35 ++-- test/functional/services/common/browser.ts | 4 +- .../services/common/test_subjects.ts | 3 +- .../web_element_wrapper.ts | 8 +- utilities/visual_regression.js | 104 ++++++------ .../server/routes/agent_policy/handlers.ts | 22 +-- .../scripts/endpoint/trusted_apps/index.ts | 39 +++-- .../index_lifecycle_management_page.ts | 43 ++--- .../functional/page_objects/rollup_page.ts | 53 +++--- .../functional/page_objects/watcher_page.ts | 23 +-- x-pack/test/functional/services/ace_editor.js | 5 +- .../services/monitoring/cluster_alerts.js | 5 +- .../functional/services/pipeline_editor.js | 48 ++++-- .../tests/kerberos/kerberos_login.ts | 6 +- .../oidc/authorization_code_flow/oidc_auth.ts | 4 +- .../tests/pki/pki_auth.ts | 6 +- .../tests/saml/saml_login.ts | 6 +- .../tests/session_idle/cleanup.ts | 8 +- .../tests/session_lifespan/cleanup.ts | 6 +- 32 files changed, 348 insertions(+), 323 deletions(-) diff --git a/packages/kbn-es-archiver/src/actions/rebuild_all.ts b/packages/kbn-es-archiver/src/actions/rebuild_all.ts index 1581ff41b95fc..e921e9a23c25e 100644 --- a/packages/kbn-es-archiver/src/actions/rebuild_all.ts +++ b/packages/kbn-es-archiver/src/actions/rebuild_all.ts @@ -7,9 +7,9 @@ */ import { resolve, dirname, relative } from 'path'; -import { stat, Stats, rename, createReadStream, createWriteStream } from 'fs'; +import { createReadStream, createWriteStream } from 'fs'; +import { stat, rename } from 'fs/promises'; import { Readable, Writable } from 'stream'; -import { fromNode } from 'bluebird'; import { ToolingLog } from '@kbn/dev-utils'; import { createPromiseFromStreams } from '@kbn/utils'; import { @@ -21,8 +21,8 @@ import { } from '../lib'; async function isDirectory(path: string): Promise { - const stats: Stats = await fromNode((cb) => stat(path, cb)); - return stats.isDirectory(); + const pathStats = await stat(path); + return pathStats.isDirectory(); } export async function rebuildAllAction({ @@ -59,7 +59,7 @@ export async function rebuildAllAction({ createWriteStream(tempFile), ] as [Readable, ...Writable[]]); - await fromNode((cb) => rename(tempFile, childPath, cb)); + await rename(tempFile, childPath); log.info(`${archiveName} Rebuilt ${childName}`); } } diff --git a/packages/kbn-es-archiver/src/lib/directory.ts b/packages/kbn-es-archiver/src/lib/directory.ts index f82e59a0ed252..dc39a646fc3bf 100644 --- a/packages/kbn-es-archiver/src/lib/directory.ts +++ b/packages/kbn-es-archiver/src/lib/directory.ts @@ -6,10 +6,9 @@ * Side Public License, v 1. */ -import { readdir } from 'fs'; -import { fromNode } from 'bluebird'; +import { readdir } from 'fs/promises'; export async function readDirectory(path: string) { - const allNames = await fromNode((cb) => readdir(path, cb)); + const allNames: string[] = await readdir(path); return allNames.filter((name) => !name.startsWith('.')); } diff --git a/packages/kbn-test/src/functional_tests/lib/auth.js b/packages/kbn-test/src/functional_tests/lib/auth.js index 22c84cd7d13d9..abc2bdd7ae10b 100644 --- a/packages/kbn-test/src/functional_tests/lib/auth.js +++ b/packages/kbn-test/src/functional_tests/lib/auth.js @@ -11,7 +11,7 @@ import util from 'util'; import { format as formatUrl } from 'url'; import request from 'request'; -import { delay } from 'bluebird'; +import { timer } from 'rxjs'; export const DEFAULT_SUPERUSER_PASS = 'changeme'; @@ -56,7 +56,7 @@ async function updateCredentials({ } if (retries > 0) { - await delay(2500); + await timer(2500).toPromise(); return await updateCredentials({ port, auth, @@ -134,7 +134,7 @@ async function insertUser({ } if (retries > 0) { - await delay(2500); + await timer(2500).toPromise(); return await insertUser({ port, auth, diff --git a/packages/kbn-test/src/jest/setup/polyfills.js b/packages/kbn-test/src/jest/setup/polyfills.js index 48b597d280b4a..ebe6178dbdd91 100644 --- a/packages/kbn-test/src/jest/setup/polyfills.js +++ b/packages/kbn-test/src/jest/setup/polyfills.js @@ -6,13 +6,6 @@ * Side Public License, v 1. */ -// bluebird < v3.3.5 does not work with MutationObserver polyfill -// when MutationObserver exists, bluebird avoids using node's builtin async schedulers -const bluebird = require('bluebird'); -bluebird.Promise.setScheduler(function (fn) { - global.setImmediate.call(global, fn); -}); - const MutationObserver = require('mutation-observer'); Object.defineProperty(window, 'MutationObserver', { value: MutationObserver }); diff --git a/packages/kbn-test/src/mocha/junit_report_generation.test.js b/packages/kbn-test/src/mocha/junit_report_generation.test.js index e4e4499f556fd..2ceb95d68f598 100644 --- a/packages/kbn-test/src/mocha/junit_report_generation.test.js +++ b/packages/kbn-test/src/mocha/junit_report_generation.test.js @@ -8,8 +8,8 @@ import { resolve } from 'path'; import { readFileSync } from 'fs'; +import { promisify } from 'util'; -import { fromNode as fcb } from 'bluebird'; import { parseString } from 'xml2js'; import del from 'del'; import Mocha from 'mocha'; @@ -17,6 +17,7 @@ import { getUniqueJunitReportPath } from '../report_path'; import { setupJUnitReportGeneration } from './junit_report_generation'; +const parseStringAsync = promisify(parseString); const PROJECT_DIR = resolve(__dirname, '__fixtures__/project'); const DURATION_REGEX = /^\d+\.\d{3}$/; const ISO_DATE_SEC_REGEX = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/; @@ -39,7 +40,7 @@ describe('dev/mocha/junit report generation', () => { mocha.addFile(resolve(PROJECT_DIR, 'test.js')); await new Promise((resolve) => mocha.run(resolve)); - const report = await fcb((cb) => parseString(readFileSync(XML_PATH), cb)); + const report = await parseStringAsync(readFileSync(XML_PATH)); // test case results are wrapped in expect(report).toEqual({ diff --git a/packages/kbn-utils/src/streams/map_stream.test.ts b/packages/kbn-utils/src/streams/map_stream.test.ts index 2c3df67fdf35c..39ab619b320f7 100644 --- a/packages/kbn-utils/src/streams/map_stream.test.ts +++ b/packages/kbn-utils/src/streams/map_stream.test.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { delay } from 'bluebird'; +import { timer } from 'rxjs'; import { createPromiseFromStreams } from './promise_from_streams'; import { createListStream } from './list_stream'; @@ -39,7 +39,7 @@ describe('createMapStream()', () => { const result = await createPromiseFromStreams([ createListStream([1, 2, 3]), createMapStream(async (n: number, i: number) => { - await delay(n); + await timer(n).toPromise(); return n * i; }), createConcatStream([]), diff --git a/src/dev/notice/bundled_notices.js b/src/dev/notice/bundled_notices.js index 7ab2a5b3f03fe..15a0f6ec1e2f1 100644 --- a/src/dev/notice/bundled_notices.js +++ b/src/dev/notice/bundled_notices.js @@ -7,18 +7,18 @@ */ import { resolve } from 'path'; -import { readFile } from 'fs'; - -import { fromNode as fcb } from 'bluebird'; +import { readFile } from 'fs/promises'; +import { promisify } from 'util'; import glob from 'glob'; +const globAsync = promisify(glob); export async function getBundledNotices(packageDirectory) { const pattern = resolve(packageDirectory, '*{LICENSE,NOTICE}*'); - const paths = await fcb((cb) => glob(pattern, cb)); + const paths = await globAsync(pattern); return Promise.all( paths.map(async (path) => ({ path, - text: await fcb((cb) => readFile(path, 'utf8', cb)), + text: await readFile(path, 'utf8'), })) ); } diff --git a/src/dev/precommit_hook/get_files_for_commit.js b/src/dev/precommit_hook/get_files_for_commit.js index 44c8c9d5e6bc0..4f913ce99cdc0 100644 --- a/src/dev/precommit_hook/get_files_for_commit.js +++ b/src/dev/precommit_hook/get_files_for_commit.js @@ -7,11 +7,9 @@ */ import SimpleGit from 'simple-git'; -import { fromNode as fcb } from 'bluebird'; - import { REPO_ROOT } from '@kbn/utils'; import { File } from '../file'; - +import { promisify } from 'util'; /** * Get the files that are staged for commit (excluding deleted files) * as `File` objects that are aware of their commit status. @@ -21,8 +19,10 @@ import { File } from '../file'; */ export async function getFilesForCommit(gitRef) { const simpleGit = new SimpleGit(REPO_ROOT); + const diffAsync = promisify(simpleGit.diff).bind(simpleGit); + const gitRefForDiff = gitRef ? gitRef : '--cached'; - const output = await fcb((cb) => simpleGit.diff(['--name-status', gitRefForDiff], cb)); + const output = await diffAsync(['--name-status', gitRefForDiff]); return ( output diff --git a/src/plugins/vis_type_tagcloud/public/components/tag_cloud.test.js b/src/plugins/vis_type_tagcloud/public/components/tag_cloud.test.js index 2fb2be0ace7cd..5a220e5ff1420 100644 --- a/src/plugins/vis_type_tagcloud/public/components/tag_cloud.test.js +++ b/src/plugins/vis_type_tagcloud/public/components/tag_cloud.test.js @@ -6,11 +6,11 @@ * Side Public License, v 1. */ +import { once } from 'events'; import _ from 'lodash'; import d3 from 'd3'; import 'jest-canvas-mock'; -import { fromNode, delay } from 'bluebird'; import { TagCloud } from './tag_cloud'; import { setHTMLElementOffset, setSVGElementGetBBox } from '@kbn/test/jest'; @@ -127,7 +127,7 @@ describe('tag cloud tests', () => { tagCloud = new TagCloud(domNode, colorScale); tagCloud.setData(currentTest.data); tagCloud.setOptions(currentTest.options); - await fromNode((cb) => tagCloud.once('renderComplete', cb)); + await once(tagCloud, 'renderComplete'); }); afterEach(teardownDOM); @@ -161,7 +161,7 @@ describe('tag cloud tests', () => { //this timeout modifies the settings before the cloud is rendered. //the cloud needs to use the correct options setTimeout(() => tagCloud.setOptions(logScaleTest.options), timeout); - await fromNode((cb) => tagCloud.once('renderComplete', cb)); + await once(tagCloud, 'renderComplete'); }); afterEach(teardownDOM); @@ -189,7 +189,7 @@ describe('tag cloud tests', () => { tagCloud.setData(baseTest.data); tagCloud.setOptions(baseTest.options); tagCloud.setOptions(logScaleTest.options); - await fromNode((cb) => tagCloud.once('renderComplete', cb)); + await once(tagCloud, 'renderComplete'); }); afterEach(teardownDOM); @@ -216,7 +216,7 @@ describe('tag cloud tests', () => { tagCloud.setOptions(baseTest.options); tagCloud.setData(trimDataTest.data); - await fromNode((cb) => tagCloud.once('renderComplete', cb)); + await once(tagCloud, 'renderComplete'); }); afterEach(teardownDOM); @@ -290,8 +290,7 @@ describe('tag cloud tests', () => { tagCloud = new TagCloud(domNode, colorScale); tagCloud.setData(logScaleTest.data); tagCloud.setOptions(logScaleTest.options); - - await delay(1000); //let layout run + await once(tagCloud, 'renderComplete'); //let layout run SVGElementGetBBoxSpyInstance.mockRestore(); SVGElementGetBBoxSpyInstance = setSVGElementGetBBox(600, 600); @@ -302,7 +301,7 @@ describe('tag cloud tests', () => { tagCloud.setData(baseTest.data); tagCloud.setOptions(baseTest.options); }, 200); - await fromNode((cb) => tagCloud.once('renderComplete', cb)); + await once(tagCloud, 'renderComplete'); }); afterEach(teardownDOM); @@ -327,7 +326,7 @@ describe('tag cloud tests', () => { tagCloud = new TagCloud(domNode, colorScale); tagCloud.setData(baseTest.data); tagCloud.setOptions(baseTest.options); - await fromNode((cb) => tagCloud.once('renderComplete', cb)); + await once(tagCloud, 'renderComplete'); }); afterEach(teardownDOM); @@ -349,12 +348,12 @@ describe('tag cloud tests', () => { tagCloud = new TagCloud(domNode, colorScale); tagCloud.setData(baseTest.data); tagCloud.setOptions(baseTest.options); - await fromNode((cb) => tagCloud.once('renderComplete', cb)); + await once(tagCloud, 'renderComplete'); //make bigger tagCloud._size = [600, 600]; tagCloud.resize(); - await fromNode((cb) => tagCloud.once('renderComplete', cb)); + await once(tagCloud, 'renderComplete'); }); afterEach(teardownDOM); @@ -372,12 +371,12 @@ describe('tag cloud tests', () => { tagCloud = new TagCloud(domNode, colorScale); tagCloud.setData(baseTest.data); tagCloud.setOptions(baseTest.options); - await fromNode((cb) => tagCloud.once('renderComplete', cb)); + await once(tagCloud, 'renderComplete'); //make smaller tagCloud._size = []; tagCloud.resize(); - await fromNode((cb) => tagCloud.once('renderComplete', cb)); + await once(tagCloud, 'renderComplete'); }); afterEach(teardownDOM); @@ -395,7 +394,7 @@ describe('tag cloud tests', () => { tagCloud.setData(baseTest.data); tagCloud.setOptions(baseTest.options); - await fromNode((cb) => tagCloud.once('renderComplete', cb)); + await once(tagCloud, 'renderComplete'); expect(domNode.innerHTML).toMatchSnapshot(); }); diff --git a/src/plugins/vis_type_timelion/server/series_functions/quandl.js b/src/plugins/vis_type_timelion/server/series_functions/quandl.js index 7e3a0f6de9aba..0176919671933 100644 --- a/src/plugins/vis_type_timelion/server/series_functions/quandl.js +++ b/src/plugins/vis_type_timelion/server/series_functions/quandl.js @@ -10,8 +10,6 @@ import { i18n } from '@kbn/i18n'; import _ from 'lodash'; import fetch from 'node-fetch'; import moment from 'moment'; -fetch.Promise = require('bluebird'); - import Datasource from '../lib/classes/datasource'; export default new Datasource('quandl', { diff --git a/test/functional/page_objects/common_page.ts b/test/functional/page_objects/common_page.ts index c6412f55dffbf..92cbd7e6d6fbe 100644 --- a/test/functional/page_objects/common_page.ts +++ b/test/functional/page_objects/common_page.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { delay } from 'bluebird'; +import { timer } from 'rxjs'; import expect from '@kbn/expect'; // @ts-ignore import fetch from 'node-fetch'; @@ -198,7 +198,7 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo async sleep(sleepMilliseconds: number) { log.debug(`... sleep(${sleepMilliseconds}) start`); - await delay(sleepMilliseconds); + await timer(sleepMilliseconds).toPromise(); log.debug(`... sleep(${sleepMilliseconds}) end`); } diff --git a/test/functional/page_objects/login_page.ts b/test/functional/page_objects/login_page.ts index 606ddf4643c40..6b842b5cf4ad3 100644 --- a/test/functional/page_objects/login_page.ts +++ b/test/functional/page_objects/login_page.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { delay } from 'bluebird'; +import { timer } from 'rxjs'; import { FtrProviderContext } from '../ftr_provider_context'; export function LoginPageProvider({ getService }: FtrProviderContext) { @@ -62,7 +62,7 @@ export function LoginPageProvider({ getService }: FtrProviderContext) { async sleep(sleepMilliseconds: number) { log.debug(`... sleep(${sleepMilliseconds}) start`); - await delay(sleepMilliseconds); + await timer(sleepMilliseconds).toPromise(); log.debug(`... sleep(${sleepMilliseconds}) end`); } } diff --git a/test/functional/page_objects/management/saved_objects_page.ts b/test/functional/page_objects/management/saved_objects_page.ts index c28d351aa77fb..0b38ecb8a61fa 100644 --- a/test/functional/page_objects/management/saved_objects_page.ts +++ b/test/functional/page_objects/management/saved_objects_page.ts @@ -7,7 +7,6 @@ */ import { keyBy } from 'lodash'; -import { map as mapAsync } from 'bluebird'; import { FtrProviderContext } from '../../ftr_provider_context'; export function SavedObjectsPageProvider({ getService, getPageObjects }: FtrProviderContext) { @@ -182,53 +181,55 @@ export function SavedObjectsPageProvider({ getService, getPageObjects }: FtrProv async getElementsInTable() { const rows = await testSubjects.findAll('~savedObjectsTableRow'); - return mapAsync(rows, async (row) => { - const checkbox = await row.findByCssSelector('[data-test-subj*="checkboxSelectRow"]'); - // return the object type aria-label="index patterns" - const objectType = await row.findByTestSubject('objectType'); - const titleElement = await row.findByTestSubject('savedObjectsTableRowTitle'); - // not all rows have inspect button - Advanced Settings objects don't - // Advanced Settings has 2 actions, - // data-test-subj="savedObjectsTableAction-relationships" - // data-test-subj="savedObjectsTableAction-copy_saved_objects_to_space" - // Some other objects have the ... - // data-test-subj="euiCollapsedItemActionsButton" - // Maybe some objects still have the inspect element visible? - // !!! Also note that since we don't have spaces on OSS, the actions for the same object can be different depending on OSS or not - let menuElement = null; - let inspectElement = null; - let relationshipsElement = null; - let copySaveObjectsElement = null; - const actions = await row.findByClassName('euiTableRowCell--hasActions'); - // getting the innerHTML and checking if it 'includes' a string is faster than a timeout looking for each element - const actionsHTML = await actions.getAttribute('innerHTML'); - if (actionsHTML.includes('euiCollapsedItemActionsButton')) { - menuElement = await row.findByTestSubject('euiCollapsedItemActionsButton'); - } - if (actionsHTML.includes('savedObjectsTableAction-inspect')) { - inspectElement = await row.findByTestSubject('savedObjectsTableAction-inspect'); - } - if (actionsHTML.includes('savedObjectsTableAction-relationships')) { - relationshipsElement = await row.findByTestSubject( - 'savedObjectsTableAction-relationships' - ); - } - if (actionsHTML.includes('savedObjectsTableAction-copy_saved_objects_to_space')) { - copySaveObjectsElement = await row.findByTestSubject( - 'savedObjectsTableAction-copy_saved_objects_to_space' - ); - } - return { - checkbox, - objectType: await objectType.getAttribute('aria-label'), - titleElement, - title: await titleElement.getVisibleText(), - menuElement, - inspectElement, - relationshipsElement, - copySaveObjectsElement, - }; - }); + return await Promise.all( + rows.map(async (row) => { + const checkbox = await row.findByCssSelector('[data-test-subj*="checkboxSelectRow"]'); + // return the object type aria-label="index patterns" + const objectType = await row.findByTestSubject('objectType'); + const titleElement = await row.findByTestSubject('savedObjectsTableRowTitle'); + // not all rows have inspect button - Advanced Settings objects don't + // Advanced Settings has 2 actions, + // data-test-subj="savedObjectsTableAction-relationships" + // data-test-subj="savedObjectsTableAction-copy_saved_objects_to_space" + // Some other objects have the ... + // data-test-subj="euiCollapsedItemActionsButton" + // Maybe some objects still have the inspect element visible? + // !!! Also note that since we don't have spaces on OSS, the actions for the same object can be different depending on OSS or not + let menuElement = null; + let inspectElement = null; + let relationshipsElement = null; + let copySaveObjectsElement = null; + const actions = await row.findByClassName('euiTableRowCell--hasActions'); + // getting the innerHTML and checking if it 'includes' a string is faster than a timeout looking for each element + const actionsHTML = await actions.getAttribute('innerHTML'); + const [ + menuElement = null, + inspectElement = null, + relationshipsElement = null, + copySaveObjectsElement = null, + ] = Promise.all([ + actionsHTML.includes('euiCollapsedItemActionsButton') && + row.findByTestSubject('euiCollapsedItemActionsButton'), + actionsHTML.includes('savedObjectsTableAction-inspect') && + row.findByTestSubject('savedObjectsTableAction-inspect'), + actionsHTML.includes('savedObjectsTableAction-relationships') && + row.findByTestSubject('savedObjectsTableAction-relationships'), + actionsHTML.includes('savedObjectsTableAction-copy_saved_objects_to_space') && + row.findByTestSubject('savedObjectsTableAction-copy_saved_objects_to_space'), + ]); + + return { + checkbox, + objectType: await objectType.getAttribute('aria-label'), + titleElement, + title: await titleElement.getVisibleText(), + menuElement, + inspectElement, + relationshipsElement, + copySaveObjectsElement, + }; + }) + ); } async getRowTitles() { @@ -242,35 +243,39 @@ export function SavedObjectsPageProvider({ getService, getPageObjects }: FtrProv async getRelationshipFlyout() { const rows = await testSubjects.findAll('relationshipsTableRow'); - return mapAsync(rows, async (row) => { - const objectType = await row.findByTestSubject('relationshipsObjectType'); - const relationship = await row.findByTestSubject('directRelationship'); - const titleElement = await row.findByTestSubject('relationshipsTitle'); - const inspectElement = await row.findByTestSubject('relationshipsTableAction-inspect'); - return { - objectType: await objectType.getAttribute('aria-label'), - relationship: await relationship.getVisibleText(), - titleElement, - title: await titleElement.getVisibleText(), - inspectElement, - }; - }); + return Promise.all( + rows.map(async (row) => { + const objectType = await row.findByTestSubject('relationshipsObjectType'); + const relationship = await row.findByTestSubject('directRelationship'); + const titleElement = await row.findByTestSubject('relationshipsTitle'); + const inspectElement = await row.findByTestSubject('relationshipsTableAction-inspect'); + return { + objectType: await objectType.getAttribute('aria-label'), + relationship: await relationship.getVisibleText(), + titleElement, + title: await titleElement.getVisibleText(), + inspectElement, + }; + }) + ); } async getInvalidRelations() { const rows = await testSubjects.findAll('invalidRelationshipsTableRow'); - return mapAsync(rows, async (row) => { - const objectType = await row.findByTestSubject('relationshipsObjectType'); - const objectId = await row.findByTestSubject('relationshipsObjectId'); - const relationship = await row.findByTestSubject('directRelationship'); - const error = await row.findByTestSubject('relationshipsError'); - return { - type: await objectType.getVisibleText(), - id: await objectId.getVisibleText(), - relationship: await relationship.getVisibleText(), - error: await error.getVisibleText(), - }; - }); + return Promise.all( + rows.map(async (row) => { + const objectType = await row.findByTestSubject('relationshipsObjectType'); + const objectId = await row.findByTestSubject('relationshipsObjectId'); + const relationship = await row.findByTestSubject('directRelationship'); + const error = await row.findByTestSubject('relationshipsError'); + return { + type: await objectType.getVisibleText(), + id: await objectId.getVisibleText(), + relationship: await relationship.getVisibleText(), + error: await error.getVisibleText(), + }; + }) + ); } async getTableSummary() { diff --git a/test/functional/page_objects/settings_page.ts b/test/functional/page_objects/settings_page.ts index 4151a8c1a1893..0278fc8c40837 100644 --- a/test/functional/page_objects/settings_page.ts +++ b/test/functional/page_objects/settings_page.ts @@ -6,9 +6,8 @@ * Side Public License, v 1. */ -import { map as mapAsync } from 'bluebird'; import expect from '@kbn/expect'; -import { FtrProviderContext } from '../ftr_provider_context'; +import { FtrProviderContext } from '../)ftr_provider_context'; export function SettingsPageProvider({ getService, getPageObjects }: FtrProviderContext) { const log = getService('log'); @@ -200,23 +199,29 @@ export function SettingsPageProvider({ getService, getPageObjects }: FtrProvider async getFieldNames() { const fieldNameCells = await testSubjects.findAll('editIndexPattern > indexedFieldName'); - return await mapAsync(fieldNameCells, async (cell) => { - return (await cell.getVisibleText()).trim(); - }); + return await Promise.all( + fieldNameCells.map(async (cell) => { + return (await cell.getVisibleText()).trim(); + }) + ); } async getFieldTypes() { const fieldNameCells = await testSubjects.findAll('editIndexPattern > indexedFieldType'); - return await mapAsync(fieldNameCells, async (cell) => { - return (await cell.getVisibleText()).trim(); - }); + return await await Promise.all( + fieldNameCells.map(async (cell) => { + return (await cell.getVisibleText()).trim(); + }) + ); } async getScriptedFieldLangs() { const fieldNameCells = await testSubjects.findAll('editIndexPattern > scriptedFieldLang'); - return await mapAsync(fieldNameCells, async (cell) => { - return (await cell.getVisibleText()).trim(); - }); + return await await Promise.all( + fieldNameCells.map(async (cell) => { + return (await cell.getVisibleText()).trim(); + }) + ); } async setFieldTypeFilter(type: string) { @@ -293,9 +298,11 @@ export function SettingsPageProvider({ getService, getPageObjects }: FtrProvider async getAllIndexPatternNames() { const indexPatterns = await this.getIndexPatternList(); - return await mapAsync(indexPatterns, async (index) => { - return await index.getVisibleText(); - }); + return await await Promise.all( + indexPatterns.map(async (index) => { + return await index.getVisibleText(); + }) + ); } async isIndexPatternListEmpty() { diff --git a/test/functional/services/common/browser.ts b/test/functional/services/common/browser.ts index d9212e48f73fc..1c5694cd94574 100644 --- a/test/functional/services/common/browser.ts +++ b/test/functional/services/common/browser.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { delay } from 'bluebird'; +import { timer } from 'rxjs'; import { cloneDeepWith } from 'lodash'; import { Key, Origin } from 'selenium-webdriver'; // @ts-ignore internal modules are not typed @@ -305,7 +305,7 @@ export async function BrowserProvider({ getService }: FtrProviderContext) { to ); // wait for 150ms to make sure the script has run - await delay(150); + await timer(150).toPromise(); } /** diff --git a/test/functional/services/common/test_subjects.ts b/test/functional/services/common/test_subjects.ts index 28b37d9576e8c..c2dfe5443e3be 100644 --- a/test/functional/services/common/test_subjects.ts +++ b/test/functional/services/common/test_subjects.ts @@ -7,7 +7,6 @@ */ import testSubjSelector from '@kbn/test-subj-selector'; -import { map as mapAsync } from 'bluebird'; import { ProvidedType } from '@kbn/test/types/ftr'; import { WebElementWrapper } from '../lib/web_element_wrapper'; import { FtrProviderContext } from '../../ftr_provider_context'; @@ -265,7 +264,7 @@ export function TestSubjectsProvider({ getService }: FtrProviderContext) { ): Promise { return await retry.try(async () => { const elements = await this.findAll(selectorAll); - return await mapAsync(elements, mapFn); + return await Promise.all(elements.map(mapFn)); }); } diff --git a/test/functional/services/lib/web_element_wrapper/web_element_wrapper.ts b/test/functional/services/lib/web_element_wrapper/web_element_wrapper.ts index 1a45aee877e1f..851938decab49 100644 --- a/test/functional/services/lib/web_element_wrapper/web_element_wrapper.ts +++ b/test/functional/services/lib/web_element_wrapper/web_element_wrapper.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { delay } from 'bluebird'; +import { timer } from 'rxjs'; import { WebElement, WebDriver, By, Key } from 'selenium-webdriver'; import { PNG } from 'pngjs'; // @ts-ignore not supported yet @@ -122,7 +122,7 @@ export class WebElementWrapper { `finding element '${this.locator.toString()}' again, ${attemptsRemaining - 1} attempts left` ); - await delay(200); + await timer(200).toPromise(); this._webElement = await this.driver.findElement(this.locator); return await this.retryCall(fn, attemptsRemaining - 1); } @@ -241,7 +241,7 @@ export class WebElementWrapper { const value = await this.getAttribute('value'); for (let i = 0; i <= value.length; i++) { await this.pressKeys(this.Keys.BACK_SPACE); - await delay(100); + await timer(100).toPromise(); } } else { if (this.isChromium) { @@ -280,7 +280,7 @@ export class WebElementWrapper { for (const char of value) { await this.retryCall(async function type(wrapper) { await wrapper._webElement.sendKeys(char); - await delay(100); + await timer(100).toPromise(); }); } } else { diff --git a/utilities/visual_regression.js b/utilities/visual_regression.js index fa4d48a2280d5..50a794002c52f 100644 --- a/utilities/visual_regression.js +++ b/utilities/visual_regression.js @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import bluebird, { promisify } from 'bluebird'; +import { promisify } from 'util'; import Handlebars from 'handlebars'; import fs from 'fs'; import path from 'path'; @@ -73,56 +73,58 @@ async function compareScreenshots() { const screenshots = files.filter((file) => file.indexOf('.png') !== -1); // We'll use this data to build a screenshot gallery in HTML. - return await bluebird.map(screenshots, async (screenshot) => { - // We're going to load image data and cache it in this object. - const comparison = { - name: screenshot, - change: undefined, - percentage: undefined, - imageData: { - session: undefined, - baseline: undefined, - diff: undefined, - }, - }; - - const sessionImagePath = path.resolve(SESSION_SCREENSHOTS_DIR, screenshot); - - const baselineImagePath = path.resolve(BASELINE_SCREENSHOTS_DIR, screenshot); - - const diffImagePath = path.resolve(DIFF_SCREENSHOTS_DIR, screenshot); - - const sessionImage = PNG.sync.read(await readFileAsync(sessionImagePath)); - const baselineImage = PNG.sync.read(await readFileAsync(baselineImagePath)); - const { width, height } = sessionImage; - const diff = new PNG({ width, height }); - - const numDiffPixels = pixelmatch( - sessionImage.data, - baselineImage.data, - diff.data, - width, - height, - { threshold: 0 } - ); - - await writeFileAsync(diffImagePath, PNG.sync.write(diff)); - - const change = numDiffPixels / (width * height); - const changePercentage = (change * 100).toFixed(2); - console.log(`(${changePercentage}%) ${screenshot}`); - comparison.percentage = changePercentage; - comparison.change = change; - - // Once the images have been diffed, we can load and store the image data. - comparison.imageData.session = await readFileAsync(sessionImagePath, 'base64'); - - comparison.imageData.baseline = await readFileAsync(baselineImagePath, 'base64'); - - comparison.imageData.diff = await readFileAsync(diffImagePath, 'base64'); - - return comparison; - }); + return await Promise.all( + screenshots.map(async (screenshot) => { + // We're going to load image data and cache it in this object. + const comparison = { + name: screenshot, + change: undefined, + percentage: undefined, + imageData: { + session: undefined, + baseline: undefined, + diff: undefined, + }, + }; + + const sessionImagePath = path.resolve(SESSION_SCREENSHOTS_DIR, screenshot); + + const baselineImagePath = path.resolve(BASELINE_SCREENSHOTS_DIR, screenshot); + + const diffImagePath = path.resolve(DIFF_SCREENSHOTS_DIR, screenshot); + + const sessionImage = PNG.sync.read(await readFileAsync(sessionImagePath)); + const baselineImage = PNG.sync.read(await readFileAsync(baselineImagePath)); + const { width, height } = sessionImage; + const diff = new PNG({ width, height }); + + const numDiffPixels = pixelmatch( + sessionImage.data, + baselineImage.data, + diff.data, + width, + height, + { threshold: 0 } + ); + + await writeFileAsync(diffImagePath, PNG.sync.write(diff)); + + const change = numDiffPixels / (width * height); + const changePercentage = (change * 100).toFixed(2); + console.log(`(${changePercentage}%) ${screenshot}`); + comparison.percentage = changePercentage; + comparison.change = change; + + // Once the images have been diffed, we can load and store the image data. + comparison.imageData.session = await readFileAsync(sessionImagePath, 'base64'); + + comparison.imageData.baseline = await readFileAsync(baselineImagePath, 'base64'); + + comparison.imageData.diff = await readFileAsync(diffImagePath, 'base64'); + + return comparison; + }) + ); } export function run(done) { diff --git a/x-pack/plugins/fleet/server/routes/agent_policy/handlers.ts b/x-pack/plugins/fleet/server/routes/agent_policy/handlers.ts index 0d37979ef9acb..b1178007148d7 100644 --- a/x-pack/plugins/fleet/server/routes/agent_policy/handlers.ts +++ b/x-pack/plugins/fleet/server/routes/agent_policy/handlers.ts @@ -7,7 +7,6 @@ import type { TypeOf } from '@kbn/config-schema'; import type { RequestHandler, ResponseHeaders } from 'src/core/server'; -import bluebird from 'bluebird'; import { fullAgentPolicyToYaml } from '../../../common/services'; import { appContextService, agentPolicyService, packagePolicyService } from '../../services'; @@ -55,16 +54,17 @@ export const getAgentPoliciesHandler: RequestHandler< perPage, }; - await bluebird.map( - items, - (agentPolicy: GetAgentPoliciesResponseItem) => - getAgentsByKuery(esClient, { - showInactive: false, - perPage: 0, - page: 1, - kuery: `${AGENT_SAVED_OBJECT_TYPE}.policy_id:${agentPolicy.id}`, - }).then(({ total: agentTotal }) => (agentPolicy.agents = agentTotal)), - { concurrency: 10 } + await Promise.all( + items.map( + async (agentPolicy: GetAgentPoliciesResponseItem) => + getAgentsByKuery(esClient, { + showInactive: false, + perPage: 0, + page: 1, + kuery: `${AGENT_SAVED_OBJECT_TYPE}.policy_id:${agentPolicy.id}`, + }).then(({ total: agentTotal }) => (agentPolicy.agents = agentTotal)), + { concurrency: 10 } + ) ); return response.ok({ body }); diff --git a/x-pack/plugins/security_solution/scripts/endpoint/trusted_apps/index.ts b/x-pack/plugins/security_solution/scripts/endpoint/trusted_apps/index.ts index 582969f1dcd45..a0c3bf792797d 100644 --- a/x-pack/plugins/security_solution/scripts/endpoint/trusted_apps/index.ts +++ b/x-pack/plugins/security_solution/scripts/endpoint/trusted_apps/index.ts @@ -9,7 +9,7 @@ import minimist from 'minimist'; import { ToolingLog } from '@kbn/dev-utils'; import { KbnClient } from '@kbn/test'; -import bluebird from 'bluebird'; +import { chain } from 'lodash'; import { basename } from 'path'; import { TRUSTED_APPS_CREATE_API, TRUSTED_APPS_LIST_API } from '../../../common/endpoint/constants'; import { NewTrustedApp, OperatingSystem, TrustedApp } from '../../../common/endpoint/types'; @@ -73,21 +73,28 @@ export const run: (options?: RunOptions) => Promise = async ({ path: TRUSTED_APPS_LIST_API, }); - return bluebird.map( - Array.from({ length: count }), - () => - kbnClient - .request({ - method: 'POST', - path: TRUSTED_APPS_CREATE_API, - body: generateTrustedAppEntry(), - }) - .then(({ data }) => { - logger.write(data.id); - return data; - }), - { concurrency: 10 } - ); + const results = []; + + // 10 concurrent requests at a time. + const invokeRequestChunks = chain(Array(count)) + .fill(async () => { + const { data } = await kbnClient.request({ + method: 'POST', + path: TRUSTED_APPS_CREATE_API, + body: generateTrustedAppEntry(), + }); + logger.write(data.id); + return data; + }) + .chunk(10) + .value(); + + for await (const invokeRequestChunk of invokeRequestChunks) { + const result = await Promise.all(invokeRequestChunk.map(invokeRequest)); + results.concat(result); + } + + return results; }; interface GenerateTrustedAppEntryOptions { diff --git a/x-pack/test/functional/page_objects/index_lifecycle_management_page.ts b/x-pack/test/functional/page_objects/index_lifecycle_management_page.ts index f47e79260e61c..034ce1dd75fa6 100644 --- a/x-pack/test/functional/page_objects/index_lifecycle_management_page.ts +++ b/x-pack/test/functional/page_objects/index_lifecycle_management_page.ts @@ -4,7 +4,6 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { map as mapAsync } from 'bluebird'; import { FtrProviderContext } from '../ftr_provider_context'; export function IndexLifecycleManagementPageProvider({ getService }: FtrProviderContext) { @@ -57,27 +56,29 @@ export function IndexLifecycleManagementPageProvider({ getService }: FtrProvider async getPolicyList() { const policies = await testSubjects.findAll('policyTableRow'); - return mapAsync(policies, async (policy) => { - const policyNameElement = await policy.findByTestSubject('policyTableCell-name'); - const policyLinkedIndicesElement = await policy.findByTestSubject( - 'policyTableCell-linkedIndices' - ); - const policyVersionElement = await policy.findByTestSubject('policyTableCell-version'); - const policyModifiedDateElement = await policy.findByTestSubject( - 'policyTableCell-modified_date' - ); - const policyActionsButtonElement = await policy.findByTestSubject( - 'policyActionsContextMenuButton' - ); + return await Promise.all( + policies.map(async (policy) => { + const policyNameElement = await policy.findByTestSubject('policyTableCell-name'); + const policyLinkedIndicesElement = await policy.findByTestSubject( + 'policyTableCell-linkedIndices' + ); + const policyVersionElement = await policy.findByTestSubject('policyTableCell-version'); + const policyModifiedDateElement = await policy.findByTestSubject( + 'policyTableCell-modified_date' + ); + const policyActionsButtonElement = await policy.findByTestSubject( + 'policyActionsContextMenuButton' + ); - return { - name: await policyNameElement.getVisibleText(), - linkedIndices: await policyLinkedIndicesElement.getVisibleText(), - version: await policyVersionElement.getVisibleText(), - modifiedDate: await policyModifiedDateElement.getVisibleText(), - actionsButton: policyActionsButtonElement, - }; - }); + return { + name: await policyNameElement.getVisibleText(), + linkedIndices: await policyLinkedIndicesElement.getVisibleText(), + version: await policyVersionElement.getVisibleText(), + modifiedDate: await policyModifiedDateElement.getVisibleText(), + actionsButton: policyActionsButtonElement, + }; + }) + ); }, }; } diff --git a/x-pack/test/functional/page_objects/rollup_page.ts b/x-pack/test/functional/page_objects/rollup_page.ts index dbdfa4e19c555..47f964d8847cd 100644 --- a/x-pack/test/functional/page_objects/rollup_page.ts +++ b/x-pack/test/functional/page_objects/rollup_page.ts @@ -6,7 +6,6 @@ */ import expect from '@kbn/expect'; -import { map as mapAsync } from 'bluebird'; import { FtrProviderContext } from '../ftr_provider_context'; export function RollupPageProvider({ getService, getPageObjects }: FtrProviderContext) { @@ -112,31 +111,33 @@ export function RollupPageProvider({ getService, getPageObjects }: FtrProviderCo async getJobList() { const jobs = await testSubjects.findAll('jobTableRow'); - return mapAsync(jobs, async (job) => { - const jobNameElement = await job.findByTestSubject('jobTableCell-id'); - const jobStatusElement = await job.findByTestSubject('jobTableCell-status'); - const jobIndexPatternElement = await job.findByTestSubject('jobTableCell-indexPattern'); - const jobRollUpIndexPatternElement = await job.findByTestSubject( - 'jobTableCell-rollupIndex' - ); - const jobDelayElement = await job.findByTestSubject('jobTableCell-rollupDelay'); - const jobIntervalElement = await job.findByTestSubject( - 'jobTableCell-dateHistogramInterval' - ); - const jobGroupElement = await job.findByTestSubject('jobTableCell-groups'); - const jobMetricsElement = await job.findByTestSubject('jobTableCell-metrics'); - - return { - jobName: await jobNameElement.getVisibleText(), - jobStatus: await jobStatusElement.getVisibleText(), - jobIndexPattern: await jobIndexPatternElement.getVisibleText(), - jobRollUpIndexPattern: await jobRollUpIndexPatternElement.getVisibleText(), - jobDelayElement: await jobDelayElement.getVisibleText(), - jobInterval: await jobIntervalElement.getVisibleText(), - jobGroup: await jobGroupElement.getVisibleText(), - jobMetrics: await jobMetricsElement.getVisibleText(), - }; - }); + return Promise.all( + jobs.map(async (job) => { + const jobNameElement = await job.findByTestSubject('jobTableCell-id'); + const jobStatusElement = await job.findByTestSubject('jobTableCell-status'); + const jobIndexPatternElement = await job.findByTestSubject('jobTableCell-indexPattern'); + const jobRollUpIndexPatternElement = await job.findByTestSubject( + 'jobTableCell-rollupIndex' + ); + const jobDelayElement = await job.findByTestSubject('jobTableCell-rollupDelay'); + const jobIntervalElement = await job.findByTestSubject( + 'jobTableCell-dateHistogramInterval' + ); + const jobGroupElement = await job.findByTestSubject('jobTableCell-groups'); + const jobMetricsElement = await job.findByTestSubject('jobTableCell-metrics'); + + return { + jobName: await jobNameElement.getVisibleText(), + jobStatus: await jobStatusElement.getVisibleText(), + jobIndexPattern: await jobIndexPatternElement.getVisibleText(), + jobRollUpIndexPattern: await jobRollUpIndexPatternElement.getVisibleText(), + jobDelayElement: await jobDelayElement.getVisibleText(), + jobInterval: await jobIntervalElement.getVisibleText(), + jobGroup: await jobGroupElement.getVisibleText(), + jobMetrics: await jobMetricsElement.getVisibleText(), + }; + }) + ); } } return new RollupJobPage(); diff --git a/x-pack/test/functional/page_objects/watcher_page.ts b/x-pack/test/functional/page_objects/watcher_page.ts index d0db5c8c3b267..2627ff0fa8105 100644 --- a/x-pack/test/functional/page_objects/watcher_page.ts +++ b/x-pack/test/functional/page_objects/watcher_page.ts @@ -5,7 +5,6 @@ * 2.0. */ -import { map as mapAsync } from 'bluebird'; import { FtrProviderContext } from '../ftr_provider_context'; export function WatcherPageProvider({ getPageObjects, getService }: FtrProviderContext) { @@ -52,17 +51,19 @@ export function WatcherPageProvider({ getPageObjects, getService }: FtrProviderC // get all the watches in the list async getWatches() { const watches = await find.allByCssSelector('.euiTableRow'); - return mapAsync(watches, async (watch) => { - const checkBox = await watch.findByCssSelector('td:nth-child(1)'); - const id = await watch.findByCssSelector('td:nth-child(2)'); - const name = await watch.findByCssSelector('td:nth-child(3)'); + return Promise.all( + watches.map(async (watch) => { + const checkBox = await watch.findByCssSelector('td:nth-child(1)'); + const id = await watch.findByCssSelector('td:nth-child(2)'); + const name = await watch.findByCssSelector('td:nth-child(3)'); - return { - checkBox: (await checkBox.getAttribute('innerHTML')).includes('input'), - id: await id.getVisibleText(), - name: (await name.getVisibleText()).split(',').map((role) => role.trim()), - }; - }); + return { + checkBox: (await checkBox.getAttribute('innerHTML')).includes('input'), + id: await id.getVisibleText(), + name: (await name.getVisibleText()).split(',').map((role) => role.trim()), + }; + }) + ); } } return new WatcherPage(); diff --git a/x-pack/test/functional/services/ace_editor.js b/x-pack/test/functional/services/ace_editor.js index 589f05695e065..be74708749f84 100644 --- a/x-pack/test/functional/services/ace_editor.js +++ b/x-pack/test/functional/services/ace_editor.js @@ -5,8 +5,6 @@ * 2.0. */ -import { map as mapAsync } from 'bluebird'; - export function AceEditorProvider({ getService }) { const testSubjects = getService('testSubjects'); const find = getService('find'); @@ -35,7 +33,8 @@ export function AceEditorProvider({ getService }) { return await retry.try(async () => { const editor = await testSubjects.find(testSubjectSelector); const lines = await editor.findAllByClassName('ace_line'); - const linesText = await mapAsync(lines, (line) => line.getVisibleText()); + + const linesText = await Promise.all(lines.map((line) => line.getVisibleText())); return linesText.join('\n'); }); } diff --git a/x-pack/test/functional/services/monitoring/cluster_alerts.js b/x-pack/test/functional/services/monitoring/cluster_alerts.js index cbeb537b08016..34c0907c3c0e2 100644 --- a/x-pack/test/functional/services/monitoring/cluster_alerts.js +++ b/x-pack/test/functional/services/monitoring/cluster_alerts.js @@ -6,7 +6,6 @@ */ import { range } from 'lodash'; -import { map as mapAsync } from 'bluebird'; export function MonitoringClusterAlertsProvider({ getService, getPageObjects }) { const testSubjects = getService('testSubjects'); @@ -61,9 +60,7 @@ export function MonitoringClusterAlertsProvider({ getService, getPageObjects }) const listingRows = await this.getOverviewAlerts(); const alertIcons = await retry.try(async () => { const elements = await find.allByCssSelector(SUBJ_OVERVIEW_ICONS); - return await mapAsync(elements, async (element) => { - return await element.getVisibleText(); - }); + return await Promise.all(elements.map(async (element) => await element.getVisibleText())); }); return await this._getAlertSetAll({ diff --git a/x-pack/test/functional/services/pipeline_editor.js b/x-pack/test/functional/services/pipeline_editor.js index ece7ec5b3ecbc..77d6d05778335 100644 --- a/x-pack/test/functional/services/pipeline_editor.js +++ b/x-pack/test/functional/services/pipeline_editor.js @@ -6,7 +6,6 @@ */ import expect from '@kbn/expect'; -import { props as propsAsync } from 'bluebird'; export function PipelineEditorProvider({ getService }) { const retry = getService('retry'); @@ -125,22 +124,39 @@ export function PipelineEditorProvider({ getService }) { * @return {Promise} */ async assertInputs(expectedValues) { - const values = await propsAsync({ - id: testSubjects.getAttribute(SUBJ_INPUT_ID, 'value'), - description: testSubjects.getAttribute(SUBJ_INPUT_DESCRIPTION, 'value'), - pipeline: aceEditor.getValue(SUBJ_UI_ACE_PIPELINE), - workers: testSubjects.getAttribute(SUBJ_INPUT_WORKERS, 'value'), - batchSize: testSubjects.getAttribute(SUBJ_INPUT_BATCH_SIZE, 'value'), - queueType: testSubjects.getAttribute(SUBJ_SELECT_QUEUE_TYPE, 'value'), - queueMaxBytesNumber: testSubjects.getAttribute(SUBJ_INPUT_QUEUE_MAX_BYTES_NUMBER, 'value'), - queueMaxBytesUnits: testSubjects.getAttribute(SUBJ_SELECT_QUEUE_MAX_BYTES_UNITS, 'value'), - queueCheckpointWrites: testSubjects.getAttribute( - SUBJ_INPUT_QUEUE_CHECKPOINT_WRITES, - 'value' - ), - }); + const [ + id, + description, + pipeline, + workers, + batchSize, + queueType, + queueMaxBytesNumber, + queueMaxBytesUnits, + queueCheckpointWrites, + ] = Promise.all([ + testSubjects.getAttribute(SUBJ_INPUT_ID, 'value'), + testSubjects.getAttribute(SUBJ_INPUT_DESCRIPTION, 'value'), + aceEditor.getValue(SUBJ_UI_ACE_PIPELINE), + testSubjects.getAttribute(SUBJ_INPUT_WORKERS, 'value'), + testSubjects.getAttribute(SUBJ_INPUT_BATCH_SIZE, 'value'), + testSubjects.getAttribute(SUBJ_SELECT_QUEUE_TYPE, 'value'), + testSubjects.getAttribute(SUBJ_INPUT_QUEUE_MAX_BYTES_NUMBER, 'value'), + testSubjects.getAttribute(SUBJ_SELECT_QUEUE_MAX_BYTES_UNITS, 'value'), + testSubjects.getAttribute(SUBJ_INPUT_QUEUE_CHECKPOINT_WRITES, 'value'), + ]); - expect(values).to.eql(expectedValues); + expect({ + id, + description, + pipeline, + workers, + batchSize, + queueType, + queueMaxBytesNumber, + queueMaxBytesUnits, + queueCheckpointWrites, + }).to.eql(expectedValues); } async assertNoDeleteButton() { diff --git a/x-pack/test/security_api_integration/tests/kerberos/kerberos_login.ts b/x-pack/test/security_api_integration/tests/kerberos/kerberos_login.ts index 2fe88dc21e5e0..82f065ef00fe5 100644 --- a/x-pack/test/security_api_integration/tests/kerberos/kerberos_login.ts +++ b/x-pack/test/security_api_integration/tests/kerberos/kerberos_login.ts @@ -7,7 +7,7 @@ import expect from '@kbn/expect'; import request, { Cookie } from 'request'; -import { delay } from 'bluebird'; +import { timer } from 'rxjs'; import { adminTestUser } from '@kbn/test'; import { FtrProviderContext } from '../../ftr_provider_context'; import { @@ -309,7 +309,7 @@ export default function ({ getService }: FtrProviderContext) { // Access token expiration is set to 15s for API integration tests. // Let's wait for 20s to make sure token expires. - await delay(20000); + await timer(20000).toPromise(); // This api call should succeed and automatically refresh token. Returned cookie will contain // the new access and refresh token pair. @@ -340,7 +340,7 @@ export default function ({ getService }: FtrProviderContext) { // Access token expiration is set to 15s for API integration tests. // Let's wait for 20s to make sure token expires. - await delay(20000); + await timer(20000).toPromise(); // This request should succeed and automatically refresh token. Returned cookie will contain // the new access and refresh token pair. diff --git a/x-pack/test/security_api_integration/tests/oidc/authorization_code_flow/oidc_auth.ts b/x-pack/test/security_api_integration/tests/oidc/authorization_code_flow/oidc_auth.ts index b2dd65b4f2009..94c807b7b06df 100644 --- a/x-pack/test/security_api_integration/tests/oidc/authorization_code_flow/oidc_auth.ts +++ b/x-pack/test/security_api_integration/tests/oidc/authorization_code_flow/oidc_auth.ts @@ -8,7 +8,7 @@ import expect from '@kbn/expect'; import request, { Cookie } from 'request'; import url from 'url'; -import { delay } from 'bluebird'; +import { timer } from 'rxjs'; import { adminTestUser } from '@kbn/test'; import { getStateAndNonce } from '../../../fixtures/oidc/oidc_tools'; import { FtrProviderContext } from '../../../ftr_provider_context'; @@ -515,7 +515,7 @@ export default function ({ getService }: FtrProviderContext) { // Access token expiration is set to 15s for API integration tests. // Let's wait for 20s to make sure token expires. - await delay(20000); + await timer(20000).toPromise(); // This api call should succeed and automatically refresh token. Returned cookie will contain // the new access and refresh token pair. diff --git a/x-pack/test/security_api_integration/tests/pki/pki_auth.ts b/x-pack/test/security_api_integration/tests/pki/pki_auth.ts index e3f63aad9e255..97c1f55646f0d 100644 --- a/x-pack/test/security_api_integration/tests/pki/pki_auth.ts +++ b/x-pack/test/security_api_integration/tests/pki/pki_auth.ts @@ -7,7 +7,7 @@ import expect from '@kbn/expect'; import request, { Cookie } from 'request'; -import { delay } from 'bluebird'; +import { timer } from 'rxjs'; import { readFileSync } from 'fs'; import { resolve } from 'path'; import { CA_CERT_PATH } from '@kbn/dev-utils'; @@ -344,7 +344,7 @@ export default function ({ getService }: FtrProviderContext) { // Access token expiration is set to 15s for API integration tests. // Let's wait for 20s to make sure token expires. - await delay(20000); + await timer(20000).toPromise(); // This api call should succeed and automatically refresh token. Returned cookie will contain // the new access token. @@ -368,7 +368,7 @@ export default function ({ getService }: FtrProviderContext) { // Access token expiration is set to 15s for API integration tests. // Let's wait for 20s to make sure token expires. - await delay(20000); + await timer(20000).toPromise(); // This request should succeed and automatically refresh token. Returned cookie will contain // the new access and refresh token pair. diff --git a/x-pack/test/security_api_integration/tests/saml/saml_login.ts b/x-pack/test/security_api_integration/tests/saml/saml_login.ts index e199ba99bfc58..d8a9f42d777ef 100644 --- a/x-pack/test/security_api_integration/tests/saml/saml_login.ts +++ b/x-pack/test/security_api_integration/tests/saml/saml_login.ts @@ -7,7 +7,7 @@ import { stringify } from 'query-string'; import url from 'url'; -import { delay } from 'bluebird'; +import { timer } from 'rxjs'; import expect from '@kbn/expect'; import request, { Cookie } from 'request'; import { adminTestUser } from '@kbn/test'; @@ -482,7 +482,7 @@ export default function ({ getService }: FtrProviderContext) { // Access token expiration is set to 15s for API integration tests. // Let's wait for 20s to make sure token expires. - await delay(20000); + await timer(20000).toPromise(); }); const expectNewSessionCookie = (cookie: Cookie) => { @@ -661,7 +661,7 @@ export default function ({ getService }: FtrProviderContext) { ['when access token is valid', async () => {}], // Scenario when active cookie has an expired access token. Access token expiration is set // to 15s for API integration tests so we need to wait for 20s to make sure token expires. - ['when access token is expired', async () => await delay(20000)], + ['when access token is expired', async () => await timer(20000).toPromise()], // Scenario when active cookie references to access/refresh token pair that were already // removed from Elasticsearch (to simulate 24h when expired tokens are removed). [ diff --git a/x-pack/test/security_api_integration/tests/session_idle/cleanup.ts b/x-pack/test/security_api_integration/tests/session_idle/cleanup.ts index 84f84e8752122..249eabe094e4f 100644 --- a/x-pack/test/security_api_integration/tests/session_idle/cleanup.ts +++ b/x-pack/test/security_api_integration/tests/session_idle/cleanup.ts @@ -6,7 +6,7 @@ */ import request, { Cookie } from 'request'; -import { delay } from 'bluebird'; +import { timer } from 'rxjs'; import expect from '@kbn/expect'; import { adminTestUser } from '@kbn/test'; import type { AuthenticationProvider } from '../../../../plugins/security/common/model'; @@ -99,7 +99,7 @@ export default function ({ getService }: FtrProviderContext) { // Cleanup routine runs every 10s, and idle timeout threshold is three times larger than 5s // idle timeout, let's wait for 40s to make sure cleanup routine runs when idle timeout // threshold is exceeded. - await delay(40000); + await timer(40000).toPromise(); // Session info is removed from the index and cookie isn't valid anymore expect(await getNumberOfSessionDocuments()).to.be(0); @@ -144,7 +144,7 @@ export default function ({ getService }: FtrProviderContext) { // Cleanup routine runs every 10s, and idle timeout threshold is three times larger than 5s // idle timeout, let's wait for 40s to make sure cleanup routine runs when idle timeout // threshold is exceeded. - await delay(40000); + await timer(40000).toPromise(); // Session for basic and SAML that used global session settings should not be valid anymore. expect(await getNumberOfSessionDocuments()).to.be(2); @@ -192,7 +192,7 @@ export default function ({ getService }: FtrProviderContext) { // least twice. for (const counter of [...Array(20).keys()]) { // Session idle timeout is 15s, let's wait 10s and make a new request that would extend the session. - await delay(1500); + await timer(1500).toPromise(); sessionCookie = (await checkSessionCookie(sessionCookie, basicUsername, { type: 'basic', diff --git a/x-pack/test/security_api_integration/tests/session_lifespan/cleanup.ts b/x-pack/test/security_api_integration/tests/session_lifespan/cleanup.ts index 3d24efc9b8e74..80c48aed571b2 100644 --- a/x-pack/test/security_api_integration/tests/session_lifespan/cleanup.ts +++ b/x-pack/test/security_api_integration/tests/session_lifespan/cleanup.ts @@ -6,7 +6,7 @@ */ import request, { Cookie } from 'request'; -import { delay } from 'bluebird'; +import { timer } from 'rxjs'; import expect from '@kbn/expect'; import { adminTestUser } from '@kbn/test'; import type { AuthenticationProvider } from '../../../../plugins/security/common/model'; @@ -96,7 +96,7 @@ export default function ({ getService }: FtrProviderContext) { // Cleanup routine runs every 10s, let's wait for 40s to make sure it runs multiple times and // when lifespan is exceeded. - await delay(40000); + await timer(40000).toPromise(); // Session info is removed from the index and cookie isn't valid anymore expect(await getNumberOfSessionDocuments()).to.be(0); @@ -139,7 +139,7 @@ export default function ({ getService }: FtrProviderContext) { // Cleanup routine runs every 10s, let's wait for 40s to make sure it runs multiple times and // when lifespan is exceeded. - await delay(40000); + await timer(40000).toPromise(); // Session for basic and SAML that used global session settings should not be valid anymore. expect(await getNumberOfSessionDocuments()).to.be(2); From da58e0d8b3f01056292a9b586e6419573debc4e5 Mon Sep 17 00:00:00 2001 From: Ahmad Bamieh Date: Tue, 23 Mar 2021 21:25:01 +0200 Subject: [PATCH 4/6] use p-map for concurrency --- .../__fixtures__/failure_hooks/config.js | 6 +-- .../server/routes/agent_policy/handlers.ts | 43 +++++++++++-------- .../scripts/endpoint/trusted_apps/index.ts | 22 +++------- 3 files changed, 35 insertions(+), 36 deletions(-) diff --git a/packages/kbn-test/src/functional_test_runner/integration_tests/__fixtures__/failure_hooks/config.js b/packages/kbn-test/src/functional_test_runner/integration_tests/__fixtures__/failure_hooks/config.js index 0b9cfd88b4cbb..dd234b8645baf 100644 --- a/packages/kbn-test/src/functional_test_runner/integration_tests/__fixtures__/failure_hooks/config.js +++ b/packages/kbn-test/src/functional_test_runner/integration_tests/__fixtures__/failure_hooks/config.js @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { delay } from 'bluebird'; +import { timer } from 'rxjs'; export default function () { return { @@ -22,13 +22,13 @@ export default function () { lifecycle.testFailure.add(async (err, test) => { log.info('testFailure %s %s', err.message, test.fullTitle()); - await delay(10); + await timer(10).toPromise(); log.info('testFailureAfterDelay %s %s', err.message, test.fullTitle()); }); lifecycle.testHookFailure.add(async (err, test) => { log.info('testHookFailure %s %s', err.message, test.fullTitle()); - await delay(10); + await timer(10).toPromise(); log.info('testHookFailureAfterDelay %s %s', err.message, test.fullTitle()); }); }, diff --git a/x-pack/plugins/fleet/server/routes/agent_policy/handlers.ts b/x-pack/plugins/fleet/server/routes/agent_policy/handlers.ts index b1178007148d7..9f20a032cf2e4 100644 --- a/x-pack/plugins/fleet/server/routes/agent_policy/handlers.ts +++ b/x-pack/plugins/fleet/server/routes/agent_policy/handlers.ts @@ -8,6 +8,8 @@ import type { TypeOf } from '@kbn/config-schema'; import type { RequestHandler, ResponseHeaders } from 'src/core/server'; +import pMap from 'p-map'; + import { fullAgentPolicyToYaml } from '../../../common/services'; import { appContextService, agentPolicyService, packagePolicyService } from '../../services'; import { getAgentsByKuery } from '../../services/agents'; @@ -37,7 +39,8 @@ import { defaultIngestErrorHandler } from '../../errors'; export const getAgentPoliciesHandler: RequestHandler< undefined, - TypeOf + TypeOf, + GetOneAgentPolicyResponse > = async (context, request, response) => { const soClient = context.core.savedObjects.client; const esClient = context.core.elasticsearch.client.asCurrentUser; @@ -47,27 +50,31 @@ export const getAgentPoliciesHandler: RequestHandler< withPackagePolicies, ...restOfQuery, }); - const body: GetAgentPoliciesResponse = { + + const agentPolicies = await pMap( items, - total, - page, - perPage, - }; + async (agentPolicy: GetAgentPoliciesResponseItem) => { + const { total: agentTotal } = getAgentsByKuery(esClient, { + showInactive: false, + perPage: 0, + page: 1, + kuery: `${AGENT_SAVED_OBJECT_TYPE}.policy_id:${agentPolicy.id}`, + }); - await Promise.all( - items.map( - async (agentPolicy: GetAgentPoliciesResponseItem) => - getAgentsByKuery(esClient, { - showInactive: false, - perPage: 0, - page: 1, - kuery: `${AGENT_SAVED_OBJECT_TYPE}.policy_id:${agentPolicy.id}`, - }).then(({ total: agentTotal }) => (agentPolicy.agents = agentTotal)), - { concurrency: 10 } - ) + agentPolicy.agents = agentTotal; + return agentPolicy; + }, + { concurrency: 10 } ); - return response.ok({ body }); + return response.ok({ + body: { + items: agentPolicies, + total, + page, + perPage, + }, + }); } catch (error) { return defaultIngestErrorHandler({ error, response }); } diff --git a/x-pack/plugins/security_solution/scripts/endpoint/trusted_apps/index.ts b/x-pack/plugins/security_solution/scripts/endpoint/trusted_apps/index.ts index a0c3bf792797d..aa66774f6581e 100644 --- a/x-pack/plugins/security_solution/scripts/endpoint/trusted_apps/index.ts +++ b/x-pack/plugins/security_solution/scripts/endpoint/trusted_apps/index.ts @@ -11,6 +11,7 @@ import { ToolingLog } from '@kbn/dev-utils'; import { KbnClient } from '@kbn/test'; import { chain } from 'lodash'; import { basename } from 'path'; +import pMap from 'p-map'; import { TRUSTED_APPS_CREATE_API, TRUSTED_APPS_LIST_API } from '../../../common/endpoint/constants'; import { NewTrustedApp, OperatingSystem, TrustedApp } from '../../../common/endpoint/types'; @@ -73,11 +74,9 @@ export const run: (options?: RunOptions) => Promise = async ({ path: TRUSTED_APPS_LIST_API, }); - const results = []; - - // 10 concurrent requests at a time. - const invokeRequestChunks = chain(Array(count)) - .fill(async () => { + return pMap( + Array.from({ length: count }), + async () => { const { data } = await kbnClient.request({ method: 'POST', path: TRUSTED_APPS_CREATE_API, @@ -85,16 +84,9 @@ export const run: (options?: RunOptions) => Promise = async ({ }); logger.write(data.id); return data; - }) - .chunk(10) - .value(); - - for await (const invokeRequestChunk of invokeRequestChunks) { - const result = await Promise.all(invokeRequestChunk.map(invokeRequest)); - results.concat(result); - } - - return results; + }, + { concurrency: 10 } + ); }; interface GenerateTrustedAppEntryOptions { From aea36cd4faec9896bbff770b8a23d3f86bb69ddc Mon Sep 17 00:00:00 2001 From: Ahmad Bamieh Date: Tue, 23 Mar 2021 21:35:48 +0200 Subject: [PATCH 5/6] fix type checks --- .../page_objects/management/saved_objects_page.ts | 6 +----- test/functional/page_objects/settings_page.ts | 2 +- test/functional/services/common/test_subjects.ts | 4 +++- .../test/security_api_integration/tests/saml/saml_login.ts | 7 ++++++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/test/functional/page_objects/management/saved_objects_page.ts b/test/functional/page_objects/management/saved_objects_page.ts index 0b38ecb8a61fa..f4fa1a3528379 100644 --- a/test/functional/page_objects/management/saved_objects_page.ts +++ b/test/functional/page_objects/management/saved_objects_page.ts @@ -195,10 +195,6 @@ export function SavedObjectsPageProvider({ getService, getPageObjects }: FtrProv // data-test-subj="euiCollapsedItemActionsButton" // Maybe some objects still have the inspect element visible? // !!! Also note that since we don't have spaces on OSS, the actions for the same object can be different depending on OSS or not - let menuElement = null; - let inspectElement = null; - let relationshipsElement = null; - let copySaveObjectsElement = null; const actions = await row.findByClassName('euiTableRowCell--hasActions'); // getting the innerHTML and checking if it 'includes' a string is faster than a timeout looking for each element const actionsHTML = await actions.getAttribute('innerHTML'); @@ -207,7 +203,7 @@ export function SavedObjectsPageProvider({ getService, getPageObjects }: FtrProv inspectElement = null, relationshipsElement = null, copySaveObjectsElement = null, - ] = Promise.all([ + ] = await Promise.all([ actionsHTML.includes('euiCollapsedItemActionsButton') && row.findByTestSubject('euiCollapsedItemActionsButton'), actionsHTML.includes('savedObjectsTableAction-inspect') && diff --git a/test/functional/page_objects/settings_page.ts b/test/functional/page_objects/settings_page.ts index 0278fc8c40837..43c1608b9792f 100644 --- a/test/functional/page_objects/settings_page.ts +++ b/test/functional/page_objects/settings_page.ts @@ -7,7 +7,7 @@ */ import expect from '@kbn/expect'; -import { FtrProviderContext } from '../)ftr_provider_context'; +import { FtrProviderContext } from '../ftr_provider_context'; export function SettingsPageProvider({ getService, getPageObjects }: FtrProviderContext) { const log = getService('log'); diff --git a/test/functional/services/common/test_subjects.ts b/test/functional/services/common/test_subjects.ts index c2dfe5443e3be..80f2f2bee01eb 100644 --- a/test/functional/services/common/test_subjects.ts +++ b/test/functional/services/common/test_subjects.ts @@ -264,7 +264,9 @@ export function TestSubjectsProvider({ getService }: FtrProviderContext) { ): Promise { return await retry.try(async () => { const elements = await this.findAll(selectorAll); - return await Promise.all(elements.map(mapFn)); + return await Promise.all( + elements.map((element, index, array) => mapFn(element, index, array.length)) + ); }); } diff --git a/x-pack/test/security_api_integration/tests/saml/saml_login.ts b/x-pack/test/security_api_integration/tests/saml/saml_login.ts index d8a9f42d777ef..f29fc1e9c33eb 100644 --- a/x-pack/test/security_api_integration/tests/saml/saml_login.ts +++ b/x-pack/test/security_api_integration/tests/saml/saml_login.ts @@ -661,7 +661,12 @@ export default function ({ getService }: FtrProviderContext) { ['when access token is valid', async () => {}], // Scenario when active cookie has an expired access token. Access token expiration is set // to 15s for API integration tests so we need to wait for 20s to make sure token expires. - ['when access token is expired', async () => await timer(20000).toPromise()], + [ + 'when access token is expired', + async () => { + await timer(20000).toPromise(); + }, + ], // Scenario when active cookie references to access/refresh token pair that were already // removed from Elasticsearch (to simulate 24h when expired tokens are removed). [ From e624a58d7d627e5b107a9688b985a15bd39a8951 Mon Sep 17 00:00:00 2001 From: Ahmad Bamieh Date: Wed, 24 Mar 2021 00:51:41 +0200 Subject: [PATCH 6/6] fix checks --- .../management/saved_objects_page.ts | 40 ++++++++++--------- .../server/routes/agent_policy/handlers.ts | 4 +- .../scripts/endpoint/trusted_apps/index.ts | 2 +- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/test/functional/page_objects/management/saved_objects_page.ts b/test/functional/page_objects/management/saved_objects_page.ts index f4fa1a3528379..1c44e8ba61715 100644 --- a/test/functional/page_objects/management/saved_objects_page.ts +++ b/test/functional/page_objects/management/saved_objects_page.ts @@ -195,25 +195,29 @@ export function SavedObjectsPageProvider({ getService, getPageObjects }: FtrProv // data-test-subj="euiCollapsedItemActionsButton" // Maybe some objects still have the inspect element visible? // !!! Also note that since we don't have spaces on OSS, the actions for the same object can be different depending on OSS or not + let menuElement = null; + let inspectElement = null; + let relationshipsElement = null; + let copySaveObjectsElement = null; const actions = await row.findByClassName('euiTableRowCell--hasActions'); // getting the innerHTML and checking if it 'includes' a string is faster than a timeout looking for each element const actionsHTML = await actions.getAttribute('innerHTML'); - const [ - menuElement = null, - inspectElement = null, - relationshipsElement = null, - copySaveObjectsElement = null, - ] = await Promise.all([ - actionsHTML.includes('euiCollapsedItemActionsButton') && - row.findByTestSubject('euiCollapsedItemActionsButton'), - actionsHTML.includes('savedObjectsTableAction-inspect') && - row.findByTestSubject('savedObjectsTableAction-inspect'), - actionsHTML.includes('savedObjectsTableAction-relationships') && - row.findByTestSubject('savedObjectsTableAction-relationships'), - actionsHTML.includes('savedObjectsTableAction-copy_saved_objects_to_space') && - row.findByTestSubject('savedObjectsTableAction-copy_saved_objects_to_space'), - ]); - + if (actionsHTML.includes('euiCollapsedItemActionsButton')) { + menuElement = await row.findByTestSubject('euiCollapsedItemActionsButton'); + } + if (actionsHTML.includes('savedObjectsTableAction-inspect')) { + inspectElement = await row.findByTestSubject('savedObjectsTableAction-inspect'); + } + if (actionsHTML.includes('savedObjectsTableAction-relationships')) { + relationshipsElement = await row.findByTestSubject( + 'savedObjectsTableAction-relationships' + ); + } + if (actionsHTML.includes('savedObjectsTableAction-copy_saved_objects_to_space')) { + copySaveObjectsElement = await row.findByTestSubject( + 'savedObjectsTableAction-copy_saved_objects_to_space' + ); + } return { checkbox, objectType: await objectType.getAttribute('aria-label'), @@ -239,7 +243,7 @@ export function SavedObjectsPageProvider({ getService, getPageObjects }: FtrProv async getRelationshipFlyout() { const rows = await testSubjects.findAll('relationshipsTableRow'); - return Promise.all( + return await Promise.all( rows.map(async (row) => { const objectType = await row.findByTestSubject('relationshipsObjectType'); const relationship = await row.findByTestSubject('directRelationship'); @@ -258,7 +262,7 @@ export function SavedObjectsPageProvider({ getService, getPageObjects }: FtrProv async getInvalidRelations() { const rows = await testSubjects.findAll('invalidRelationshipsTableRow'); - return Promise.all( + return await Promise.all( rows.map(async (row) => { const objectType = await row.findByTestSubject('relationshipsObjectType'); const objectId = await row.findByTestSubject('relationshipsObjectId'); diff --git a/x-pack/plugins/fleet/server/routes/agent_policy/handlers.ts b/x-pack/plugins/fleet/server/routes/agent_policy/handlers.ts index 9f20a032cf2e4..abb631ada03a4 100644 --- a/x-pack/plugins/fleet/server/routes/agent_policy/handlers.ts +++ b/x-pack/plugins/fleet/server/routes/agent_policy/handlers.ts @@ -40,7 +40,7 @@ import { defaultIngestErrorHandler } from '../../errors'; export const getAgentPoliciesHandler: RequestHandler< undefined, TypeOf, - GetOneAgentPolicyResponse + GetAgentPoliciesResponse > = async (context, request, response) => { const soClient = context.core.savedObjects.client; const esClient = context.core.elasticsearch.client.asCurrentUser; @@ -54,7 +54,7 @@ export const getAgentPoliciesHandler: RequestHandler< const agentPolicies = await pMap( items, async (agentPolicy: GetAgentPoliciesResponseItem) => { - const { total: agentTotal } = getAgentsByKuery(esClient, { + const { total: agentTotal } = await getAgentsByKuery(esClient, { showInactive: false, perPage: 0, page: 1, diff --git a/x-pack/plugins/security_solution/scripts/endpoint/trusted_apps/index.ts b/x-pack/plugins/security_solution/scripts/endpoint/trusted_apps/index.ts index aa66774f6581e..b837636990b23 100644 --- a/x-pack/plugins/security_solution/scripts/endpoint/trusted_apps/index.ts +++ b/x-pack/plugins/security_solution/scripts/endpoint/trusted_apps/index.ts @@ -9,9 +9,9 @@ import minimist from 'minimist'; import { ToolingLog } from '@kbn/dev-utils'; import { KbnClient } from '@kbn/test'; -import { chain } from 'lodash'; import { basename } from 'path'; import pMap from 'p-map'; + import { TRUSTED_APPS_CREATE_API, TRUSTED_APPS_LIST_API } from '../../../common/endpoint/constants'; import { NewTrustedApp, OperatingSystem, TrustedApp } from '../../../common/endpoint/types';