Skip to content

Commit

Permalink
manually update violations
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Sep 9, 2021
1 parent 9fad060 commit 20495b0
Show file tree
Hide file tree
Showing 17 changed files with 60 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
*/

import Path from 'path';
import Fs from 'fs';
import Util from 'util';
import glob from 'glob';
import del from 'del';
import { kibanaServerTestUser } from '@kbn/test';
import { kibanaPackageJson as pkg } from '@kbn/utils';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
Expand All @@ -18,15 +16,8 @@ import { Root } from '../../../root';

const LOG_FILE_PREFIX = 'migration_test_multiple_es_nodes';

const asyncUnlink = Util.promisify(Fs.unlink);

async function removeLogFile() {
glob(Path.join(__dirname, `${LOG_FILE_PREFIX}_*.log`), (err, files) => {
files.forEach(async (file) => {
// ignore errors if it doesn't exist
await asyncUnlink(file).catch(() => void 0);
});
});
await del([Path.join(__dirname, `${LOG_FILE_PREFIX}_*.log`)], { force: true });
}

function extractSortNumberFromId(id: string): number {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
*/

import Path from 'path';
import Fs from 'fs';
import Util from 'util';
import glob from 'glob';
import del from 'del';
import { esTestConfig, kibanaServerTestUser } from '@kbn/test';
import { kibanaPackageJson as pkg } from '@kbn/utils';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
Expand All @@ -19,15 +17,8 @@ import type { Root } from '../../../root';

const LOG_FILE_PREFIX = 'migration_test_multiple_kibana_nodes';

const asyncUnlink = Util.promisify(Fs.unlink);

async function removeLogFiles() {
glob(Path.join(__dirname, `${LOG_FILE_PREFIX}_*.log`), (err, files) => {
files.forEach(async (file) => {
// ignore errors if it doesn't exist
await asyncUnlink(file).catch(() => void 0);
});
});
await del([Path.join(__dirname, `${LOG_FILE_PREFIX}_*.log`)], { force: true });
}

function extractSortNumberFromId(id: string): number {
Expand Down
22 changes: 7 additions & 15 deletions src/plugins/bfetch/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type {
StartServicesAccessor,
} from 'src/core/server';
import { schema } from '@kbn/config-schema';
import { Subject } from 'rxjs';
import { map$ } from '@kbn/std';
import {
StreamingResponseHandler,
BatchRequestData,
Expand Down Expand Up @@ -208,23 +208,15 @@ export class BfetchServerPlugin
>(path, (request) => {
const handlerInstance = handler(request);
return {
getResponseStream: ({ batch }) => {
const subject = new Subject<BatchResponseItem<BatchItemResult, E>>();
let cnt = batch.length;
batch.forEach(async (batchItem, id) => {
getResponseStream: ({ batch }) =>
map$(batch, async (batchItem, id) => {
try {
const result = await handlerInstance.onBatchItem(batchItem);
subject.next({ id, result });
} catch (err) {
const error = normalizeError<E>(err);
subject.next({ id, error });
} finally {
cnt--;
if (!cnt) subject.complete();
return { id, result };
} catch (error) {
return { id, error: normalizeError<E>(error) };
}
});
return subject;
},
}),
};
});
};
Expand Down
22 changes: 12 additions & 10 deletions src/plugins/vis_type_timelion/server/lib/reduce.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import _ from 'lodash';
import { asyncMap } from '@kbn/std';

function allSeriesContainKey(seriesList, key) {
const containsKeyInitialValue = true;
Expand Down Expand Up @@ -48,16 +49,17 @@ async function pairwiseReduce(left, right, fn) {
});

// pairwise reduce seriesLists
const pairwiseSeriesList = { type: 'seriesList', list: [] };
left.list.forEach(async (leftSeries) => {
const first = { type: 'seriesList', list: [leftSeries] };
const second = { type: 'seriesList', list: [indexedList[leftSeries[pairwiseField]]] };
const reducedSeriesList = await reduce([first, second], fn);
const reducedSeries = reducedSeriesList.list[0];
reducedSeries.label = leftSeries[pairwiseField];
pairwiseSeriesList.list.push(reducedSeries);
});
return pairwiseSeriesList;
return {
type: 'seriesList',
list: await asyncMap(left.list, async (leftSeries) => {
const first = { type: 'seriesList', list: [leftSeries] };
const second = { type: 'seriesList', list: [indexedList[leftSeries[pairwiseField]]] };
const reducedSeriesList = await reduce([first, second], fn);
const reducedSeries = reducedSeriesList.list[0];
reducedSeries.label = leftSeries[pairwiseField];
return reducedSeries;
}),
};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import classNames from 'classnames';
import { compact, uniqBy, map, every, isUndefined } from 'lodash';

import { i18n } from '@kbn/i18n';
import { asyncForEach } from '@kbn/std';
import { EuiPopoverProps, EuiIcon, keys, htmlIdGenerator } from '@elastic/eui';

import { PersistedState } from '../../../../../../visualizations/public';
Expand Down Expand Up @@ -127,13 +128,14 @@ export class VisLegend extends PureComponent<VisLegendProps, VisLegendState> {
new Promise(async (resolve, reject) => {
try {
const filterableLabels = new Set<string>();
items.forEach(async (item) => {
await asyncForEach(items, async (item) => {
const canFilter = await this.canFilter(item);

if (canFilter) {
filterableLabels.add(item.label);
}
});

this.setState(
{
filterableLabels,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import type { ListId, NamespaceType } from '@kbn/securitysolution-io-ts-list-types';
import { getSavedObjectType } from '@kbn/securitysolution-list-utils';
import { asyncForEach } from '@kbn/std';

import { SavedObjectsClientContract } from '../../../../../../src/core/server/';

Expand Down Expand Up @@ -80,7 +81,7 @@ export const deleteFoundExceptionListItems = async ({
namespaceType: NamespaceType;
}): Promise<void> => {
const savedObjectType = getSavedObjectType({ namespaceType });
ids.forEach(async (id) => {
await asyncForEach(ids, async (id) => {
try {
await savedObjectsClient.delete(savedObjectType, id);
} catch (err) {
Expand Down
10 changes: 5 additions & 5 deletions x-pack/plugins/maps/public/index_pattern_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import type { IndexPatternField, IndexPattern } from 'src/plugins/data/public';
import { i18n } from '@kbn/i18n';
import { asyncMap } from '@kbn/std';
import { getIndexPatternService } from './kibana_services';
import { indexPatterns } from '../../../../src/plugins/data/public';
import { ES_GEO_FIELD_TYPE, ES_GEO_FIELD_TYPES } from '../common/constants';
Expand All @@ -32,18 +33,17 @@ export function getGeoTileAggNotSupportedReason(field: IndexPatternField): strin
export async function getIndexPatternsFromIds(
indexPatternIds: string[] = []
): Promise<IndexPattern[]> {
const promises: IndexPattern[] = [];
indexPatternIds.forEach(async (indexPatternId) => {
const results = await asyncMap(indexPatternIds, async (indexPatternId) => {
try {
// @ts-ignore
promises.push(getIndexPatternService().get(indexPatternId));
return (await getIndexPatternService().get(indexPatternId)) as IndexPattern;
} catch (error) {
// Unable to load index pattern, better to not throw error so map can render
// Error will be surfaced by layer since it too will be unable to locate the index pattern
return null;
}
});
return await Promise.all(promises);

return results.filter((r): r is IndexPattern => r !== null);
}

export function getTermsFields(fields: IndexPatternField[]): IndexPatternField[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { ElasticsearchClient } from 'kibana/server';
import { asyncForEach } from '@kbn/std';

import { Transforms } from '../modules/types';
import type { Logger } from '../../../../../src/core/server';
Expand Down Expand Up @@ -35,7 +36,7 @@ export const uninstallTransforms = async ({
suffix,
transforms,
}: UninstallTransformsOptions): Promise<void> => {
transforms.forEach(async (transform) => {
await asyncForEach(transforms, async (transform) => {
const { id } = transform;
const computedId = computeTransformId({ id, prefix, suffix });
const exists = await getTransformExists(esClient, computedId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { uniqueId } from 'lodash';
import React, { createContext, useEffect, useState } from 'react';
import { useRouteMatch } from 'react-router-dom';
import { asyncForEach } from '@kbn/std';
import { Alert } from '../../../alerting/common';
import { getDataHandler } from '../data_handler';
import { FETCH_STATUS } from '../hooks/use_fetcher';
Expand Down Expand Up @@ -53,7 +54,7 @@ export function HasDataContextProvider({ children }: { children: React.ReactNode
useEffect(
() => {
if (!isExploratoryView)
apps.forEach(async (app) => {
asyncForEach(apps, async (app) => {
try {
const updateState = ({
hasData,
Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/rollup/server/collectors/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
import { get } from 'lodash';
import { ElasticsearchClient } from 'kibana/server';
import { asyncForEach } from '@kbn/std';

// elasticsearch index.max_result_window default value
const ES_MAX_RESULT_WINDOW_DEFAULT_VALUE = 1000;
Expand Down Expand Up @@ -168,7 +169,7 @@ export async function fetchRollupVisualizations(
const visualizations = get(savedVisualizationsList, 'hits.hits', []);
const sort =
savedVisualizationsList.hits.hits[savedVisualizationsList.hits.hits.length - 1].sort;
visualizations.forEach(async (visualization: any) => {
await asyncForEach(visualizations, async (visualization: any) => {
const references: Array<{ name: string; id: string; type: string }> | undefined = get(
visualization,
'_source.references'
Expand All @@ -193,7 +194,7 @@ export async function fetchRollupVisualizations(
}
}
}
}, [] as string[]);
});

if (savedVisualizationsList.hits.hits.length < ES_MAX_RESULT_WINDOW_DEFAULT_VALUE) {
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import React, { Component, Fragment } from 'react';

import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { asyncForEach } from '@kbn/std';
import type { PublicMethodsOf } from '@kbn/utility-types';
import type { NotificationsStart } from 'src/core/public';

Expand Down Expand Up @@ -81,7 +82,7 @@ export class ConfirmDeleteUsers extends Component<Props, unknown> {
private deleteUsers = () => {
const { usersToDelete, callback, userAPIClient, notifications } = this.props;
const errors: string[] = [];
usersToDelete.forEach(async (username) => {
asyncForEach(usersToDelete, async (username) => {
try {
await userAPIClient.deleteUser(username);
notifications.toasts.addSuccess(
Expand All @@ -99,6 +100,7 @@ export class ConfirmDeleteUsers extends Component<Props, unknown> {
)
);
}

if (callback) {
callback(usersToDelete, errors);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { asyncForEach } from '@kbn/std';
import { DeleteRuleOptions } from './types';

export const deleteRules = async ({
Expand All @@ -14,5 +15,7 @@ export const deleteRules = async ({
id,
}: DeleteRuleOptions) => {
await rulesClient.delete({ id });
ruleStatuses.forEach(async (obj) => ruleStatusClient.delete(obj.id));
await asyncForEach(ruleStatuses, async (obj) => {
await ruleStatusClient.delete(obj.id);
});
};
4 changes: 3 additions & 1 deletion x-pack/test/accessibility/apps/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
* 2.0.
*/

import { asyncForEach } from '@kbn/std';

// This function clears all pipelines to ensure that there in an empty state before starting each test.
export async function deleteAllPipelines(client: any, logger: any) {
const pipelines = await client.ingest.getPipeline();
const pipeLineIds = Object.keys(pipelines.body);
await logger.debug(pipelines);
if (pipeLineIds.length > 0) {
pipeLineIds.forEach(async (newId: any) => {
await asyncForEach(pipeLineIds, async (newId: any) => {
await client.ingest.deletePipeline({ id: newId });
});
}
Expand Down
4 changes: 2 additions & 2 deletions x-pack/test/api_integration/apis/uptime/rest/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export default function ({ getService }: FtrProviderContext) {
const scheduleEvery = 10000; // fake monitor checks every 10s
let dateRange: { start: string; end: string };

[true, false].forEach(async (includeTimespan: boolean) => {
[true, false].forEach(async (includeObserver: boolean) => {
[true, false].forEach((includeTimespan: boolean) => {
[true, false].forEach((includeObserver: boolean) => {
describe(`with timespans=${includeTimespan} and observer=${includeObserver}`, async () => {
before(async () => {
const promises: Array<Promise<any>> = [];
Expand Down
7 changes: 4 additions & 3 deletions x-pack/test/fleet_api_integration/apis/epm/data_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import expect from '@kbn/expect';
import { asyncForEach } from '@kbn/std';
import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { skipIfNoDockerRegistry } from '../../helpers';

Expand Down Expand Up @@ -90,7 +91,7 @@ export default function (providerContext: FtrProviderContext) {
});

it('should list the logs and metrics datastream', async function () {
namespaces.forEach(async (namespace) => {
await asyncForEach(namespaces, async (namespace) => {
const resLogsDatastream = await es.transport.request({
method: 'GET',
path: `/_data_stream/${logsTemplateName}-${namespace}`,
Expand All @@ -108,7 +109,7 @@ export default function (providerContext: FtrProviderContext) {

it('after update, it should have rolled over logs datastream because mappings are not compatible and not metrics', async function () {
await installPackage(pkgUpdateKey);
namespaces.forEach(async (namespace) => {
await asyncForEach(namespaces, async (namespace) => {
const resLogsDatastream = await es.transport.request({
method: 'GET',
path: `/_data_stream/${logsTemplateName}-${namespace}`,
Expand All @@ -123,7 +124,7 @@ export default function (providerContext: FtrProviderContext) {
});

it('should be able to upgrade a package after a rollover', async function () {
namespaces.forEach(async (namespace) => {
await asyncForEach(namespaces, async (namespace) => {
await es.transport.request({
method: 'POST',
path: `/${logsTemplateName}-${namespace}/_rollover`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default function ({ getService, getPageObjects }) {

const GEO_POINT = 'geo_point';
const pointGeojsonFiles = ['point.json', 'multi_point.json'];
pointGeojsonFiles.forEach(async (pointFile) => {
pointGeojsonFiles.forEach((pointFile) => {
it(`should index with type geo_point for file: ${pointFile}`, async () => {
if (!(await browser.checkBrowserPermission('clipboard-read'))) {
return;
Expand All @@ -127,7 +127,7 @@ export default function ({ getService, getPageObjects }) {
'multi_polygon.json',
'polygon.json',
];
nonPointGeojsonFiles.forEach(async (shapeFile) => {
nonPointGeojsonFiles.forEach((shapeFile) => {
it(`should index with type geo_shape for file: ${shapeFile}`, async () => {
if (!(await browser.checkBrowserPermission('clipboard-read'))) {
return;
Expand Down
Loading

0 comments on commit 20495b0

Please sign in to comment.