Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into eui-upgrade-67.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen committed Nov 7, 2022
2 parents 1aff81a + adfa8f7 commit 71cf268
Show file tree
Hide file tree
Showing 36 changed files with 1,289 additions and 338 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
},
"dependencies": {
"@appland/sql-parser": "^1.5.1",
"@babel/runtime": "^7.19.4",
"@babel/runtime": "^7.20.0",
"@dnd-kit/core": "^3.1.1",
"@dnd-kit/sortable": "^4.0.0",
"@dnd-kit/utilities": "^2.0.0",
Expand Down Expand Up @@ -686,9 +686,9 @@
"@babel/core": "^7.19.6",
"@babel/eslint-parser": "^7.19.1",
"@babel/eslint-plugin": "^7.19.1",
"@babel/generator": "^7.19.6",
"@babel/generator": "^7.20.0",
"@babel/helper-plugin-utils": "^7.19.0",
"@babel/parser": "^7.19.6",
"@babel/parser": "^7.20.0",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
Expand All @@ -700,8 +700,8 @@
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@babel/register": "^7.18.9",
"@babel/traverse": "^7.19.6",
"@babel/types": "^7.19.4",
"@babel/traverse": "^7.20.0",
"@babel/types": "^7.20.0",
"@bazel/ibazel": "^0.16.2",
"@bazel/typescript": "4.6.2",
"@cypress/code-coverage": "^3.10.0",
Expand Down Expand Up @@ -1115,7 +1115,7 @@
"svgo": "^2.8.0",
"tape": "^5.0.1",
"tempy": "^0.3.0",
"terser": "^5.14.1",
"terser": "^5.15.1",
"terser-webpack-plugin": "^4.2.3",
"tough-cookie": "^4.1.2",
"tree-kill": "^1.2.2",
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export type { PluginSetupContract, PluginStartContract } from './plugin';
export type {
FindResult,
BulkEditOperation,
BulkEditError,
BulkOperationError,
BulkEditOptions,
BulkEditOptionsFilter,
BulkEditOptionsIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import { chunk } from 'lodash';
import { KueryNode } from '@kbn/es-query';
import { Logger } from '@kbn/core/server';
import { convertRuleIdsToKueryNode } from '../../lib';
import { BulkDeleteError } from '../rules_client';
import { BulkOperationError } from '../rules_client';
import { waitBeforeNextRetry, RETRY_IF_CONFLICTS_ATTEMPTS } from './wait_before_next_retry';

const MAX_RULES_IDS_IN_RETRY = 1000;

export type BulkDeleteOperation = (filter: KueryNode | null) => Promise<{
apiKeysToInvalidate: string[];
errors: BulkDeleteError[];
errors: BulkOperationError[];
taskIdsToDelete: string[];
}>;

interface ReturnRetry {
apiKeysToInvalidate: string[];
errors: BulkDeleteError[];
errors: BulkOperationError[];
taskIdsToDelete: string[];
}

Expand All @@ -46,7 +46,7 @@ export const retryIfBulkDeleteConflicts = async (
filter: KueryNode | null,
retries: number = RETRY_IF_CONFLICTS_ATTEMPTS,
accApiKeysToInvalidate: string[] = [],
accErrors: BulkDeleteError[] = [],
accErrors: BulkOperationError[] = [],
accTaskIdsToDelete: string[] = []
): Promise<ReturnRetry> => {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { chunk } from 'lodash';
import { KueryNode } from '@kbn/es-query';
import { Logger, SavedObjectsBulkUpdateObject, SavedObjectsUpdateResponse } from '@kbn/core/server';
import { convertRuleIdsToKueryNode } from '../../lib';
import { BulkEditError } from '../rules_client';
import { BulkOperationError } from '../rules_client';
import { RawRule } from '../../types';
import { waitBeforeNextRetry, RETRY_IF_CONFLICTS_ATTEMPTS } from './wait_before_next_retry';

Expand All @@ -21,13 +21,13 @@ type BulkEditOperation = (filter: KueryNode | null) => Promise<{
apiKeysToInvalidate: string[];
rules: Array<SavedObjectsBulkUpdateObject<RawRule>>;
resultSavedObjects: Array<SavedObjectsUpdateResponse<RawRule>>;
errors: BulkEditError[];
errors: BulkOperationError[];
}>;

interface ReturnRetry {
apiKeysToInvalidate: string[];
results: Array<SavedObjectsUpdateResponse<RawRule>>;
errors: BulkEditError[];
errors: BulkOperationError[];
}

/**
Expand All @@ -52,7 +52,7 @@ export const retryIfBulkEditConflicts = async (
retries: number = RETRY_IF_CONFLICTS_ATTEMPTS,
accApiKeysToInvalidate: string[] = [],
accResults: Array<SavedObjectsUpdateResponse<RawRule>> = [],
accErrors: BulkEditError[] = []
accErrors: BulkOperationError[] = []
): Promise<ReturnRetry> => {
// run the operation, return if no errors or throw if not a conflict error
try {
Expand Down
34 changes: 16 additions & 18 deletions x-pack/plugins/alerting/server/rules_client/rules_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,17 +309,9 @@ export interface BulkDeleteOptionsIds {

export type BulkDeleteOptions = BulkDeleteOptionsFilter | BulkDeleteOptionsIds;

export interface BulkEditError {
export interface BulkOperationError {
message: string;
rule: {
id: string;
name: string;
};
}

export interface BulkDeleteError {
message: string;
status: number;
status?: number;
rule: {
id: string;
name: string;
Expand Down Expand Up @@ -1908,18 +1900,24 @@ export class RulesClient {
);

const taskIdsFailedToBeDeleted: string[] = [];
const taskIdsSuccessfullyDeleted: string[] = [];
if (taskIdsToDelete.length > 0) {
try {
const resultFromDeletingTasks = await this.taskManager.bulkRemoveIfExist(taskIdsToDelete);
resultFromDeletingTasks?.statuses.forEach((status) => {
if (!status.success) {
if (status.success) {
taskIdsSuccessfullyDeleted.push(status.id);
} else {
taskIdsFailedToBeDeleted.push(status.id);
}
});
this.logger.debug(
`Successfully deleted schedules for underlying tasks: ${taskIdsToDelete
.filter((id) => taskIdsFailedToBeDeleted.includes(id))
.join(', ')}`
`Successfully deleted schedules for underlying tasks: ${taskIdsSuccessfullyDeleted.join(
', '
)}`
);
this.logger.error(
`Failure to delete schedules for underlying tasks: ${taskIdsFailedToBeDeleted.join(', ')}`
);
} catch (error) {
this.logger.error(
Expand Down Expand Up @@ -1953,7 +1951,7 @@ export class RulesClient {
const rules: SavedObjectsBulkDeleteObject[] = [];
const apiKeysToInvalidate: string[] = [];
const taskIdsToDelete: string[] = [];
const errors: BulkDeleteError[] = [];
const errors: BulkOperationError[] = [];
const apiKeyToRuleIdMapping: Record<string, string> = {};
const taskIdToRuleIdMapping: Record<string, string> = {};
const ruleNameToRuleIdMapping: Record<string, string> = {};
Expand Down Expand Up @@ -2009,7 +2007,7 @@ export class RulesClient {
options: BulkEditOptions<Params>
): Promise<{
rules: Array<SanitizedRule<Params>>;
errors: BulkEditError[];
errors: BulkOperationError[];
total: number;
}> {
const queryFilter = (options as BulkEditOptionsFilter<Params>).filter;
Expand Down Expand Up @@ -2176,7 +2174,7 @@ export class RulesClient {
apiKeysToInvalidate: string[];
rules: Array<SavedObjectsBulkUpdateObject<RawRule>>;
resultSavedObjects: Array<SavedObjectsUpdateResponse<RawRule>>;
errors: BulkEditError[];
errors: BulkOperationError[];
}> {
const rulesFinder =
await this.encryptedSavedObjectsClient.createPointInTimeFinderDecryptedAsInternalUser<RawRule>(
Expand All @@ -2189,7 +2187,7 @@ export class RulesClient {
);

const rules: Array<SavedObjectsBulkUpdateObject<RawRule>> = [];
const errors: BulkEditError[] = [];
const errors: BulkOperationError[] = [];
const apiKeysToInvalidate: string[] = [];
const apiKeysMap = new Map<string, { oldApiKey?: string; newApiKey?: string }>();
const username = await this.getUserName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {

beforeEach(() => {
getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry);
(auditLogger.log as jest.Mock).mockClear();
jest.clearAllMocks();
});

setGlobalDate();
Expand Down Expand Up @@ -392,9 +392,11 @@ describe('bulkDelete', () => {

const result = await rulesClient.bulkDeleteRules({ filter: 'fake_filter' });

expect(logger.debug).toBeCalledTimes(1);
expect(logger.debug).toBeCalledWith(
'Successfully deleted schedules for underlying tasks: taskId2'
'Successfully deleted schedules for underlying tasks: taskId1'
);
expect(logger.error).toBeCalledWith(
'Failure to delete schedules for underlying tasks: taskId2'
);
expect(result).toStrictEqual({
errors: [],
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/maps/public/actions/layer_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ export function createLayerGroup(draggedLayerId: string, combineLayerId: string)
};
}

function ungroupLayer(layerId: string) {
export function ungroupLayer(layerId: string) {
return (
dispatch: ThunkDispatch<MapStoreState, void, AnyAction>,
getState: () => MapStoreState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
setDrawMode,
showThisLayerOnly,
toggleLayerVisible,
ungroupLayer,
updateEditLayer,
} from '../../../../../../actions';
import { getLayerListRaw } from '../../../../../../selectors/map_selectors';
Expand Down Expand Up @@ -55,6 +56,9 @@ function mapDispatchToProps(dispatch: ThunkDispatch<MapStoreState, void, AnyActi
showThisLayerOnly: (layerId: string) => {
dispatch(showThisLayerOnly(layerId));
},
ungroupLayer: (layerId: string) => {
dispatch(ungroupLayer(layerId));
},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const defaultProps = {
openLayerSettings: () => {},
numLayers: 2,
showThisLayerOnly: () => {},
ungroupLayer: () => {},
};

describe('TOCEntryActionsPopover', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { ESSearchSource } from '../../../../../../classes/sources/es_search_sour
import { isVectorLayer, IVectorLayer } from '../../../../../../classes/layers/vector_layer';
import { SCALING_TYPES, VECTOR_SHAPE_TYPE } from '../../../../../../../common/constants';
import { RemoveLayerConfirmModal } from '../../../../../../components/remove_layer_confirm_modal';
import { isLayerGroup, LayerGroup } from '../../../../../../classes/layers/layer_group';

export interface Props {
cloneLayer: (layerId: string) => void;
Expand All @@ -38,6 +39,7 @@ export interface Props {
supportsFitToBounds: boolean;
toggleVisible: (layerId: string) => void;
numLayers: number;
ungroupLayer: (layerId: string) => void;
}

interface State {
Expand Down Expand Up @@ -114,18 +116,6 @@ export class TOCEntryActionsPopover extends Component<Props, State> {
}));
};

_cloneLayer() {
this.props.cloneLayer(this.props.layer.getId());
}

_fitToBounds() {
this.props.fitToBounds(this.props.layer.getId());
}

_toggleVisible() {
this.props.toggleVisible(this.props.layer.getId());
}

_getActionsPanel() {
const actionItems = [
{
Expand All @@ -140,7 +130,7 @@ export class TOCEntryActionsPopover extends Component<Props, State> {
disabled: !this.props.supportsFitToBounds,
onClick: () => {
this._closePopover();
this._fitToBounds();
this.props.fitToBounds(this.props.layer.getId());
},
},
{
Expand All @@ -150,7 +140,7 @@ export class TOCEntryActionsPopover extends Component<Props, State> {
toolTipContent: null,
onClick: () => {
this._closePopover();
this._toggleVisible();
this.props.toggleVisible(this.props.layer.getId());
},
},
];
Expand Down Expand Up @@ -218,9 +208,27 @@ export class TOCEntryActionsPopover extends Component<Props, State> {
'data-test-subj': 'cloneLayerButton',
onClick: () => {
this._closePopover();
this._cloneLayer();
this.props.cloneLayer(this.props.layer.getId());
},
});
if (
isLayerGroup(this.props.layer) &&
(this.props.layer as LayerGroup).getChildren().length > 0
) {
actionItems.push({
name: i18n.translate('xpack.maps.layerTocActions.ungroupLayerTitle', {
defaultMessage: 'Ungroup layers',
}),
icon: <EuiIcon type="layers" size="m" />,
toolTipContent: null,
'data-test-subj': 'removeLayerButton',
onClick: () => {
this._closePopover();
this.props.ungroupLayer(this.props.layer.getId());
this.props.removeLayer(this.props.layer.getId());
},
});
}
actionItems.push({
name: i18n.translate('xpack.maps.layerTocActions.removeLayerTitle', {
defaultMessage: 'Remove layer',
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/security_solution/cypress/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { defineConfig } from 'cypress';

// eslint-disable-next-line import/no-default-export
export default defineConfig({
defaultCommandTimeout: 20000,
execTimeout: 20000,
pageLoadTimeout: 20000,
defaultCommandTimeout: 60000,
execTimeout: 60000,
pageLoadTimeout: 60000,
screenshotsFolder: '../../../target/kibana-security-solution/cypress/screenshots',
trashAssetsBeforeRuns: false,
video: false,
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/security_solution/cypress/cypress_ci.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { defineConfig } from 'cypress';

// eslint-disable-next-line import/no-default-export
export default defineConfig({
defaultCommandTimeout: 120000,
execTimeout: 120000,
pageLoadTimeout: 120000,
defaultCommandTimeout: 150000,
execTimeout: 150000,
pageLoadTimeout: 150000,
numTestsKeptInMemory: 0,
retries: {
runMode: 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import moment from 'moment';
import { BadRequestError, transformError } from '@kbn/securitysolution-es-utils';
import type { KibanaResponseFactory, Logger, SavedObjectsClientContract } from '@kbn/core/server';

import type { RulesClient, BulkEditError } from '@kbn/alerting-plugin/server';
import type { RulesClient, BulkOperationError } from '@kbn/alerting-plugin/server';
import type { SanitizedRule } from '@kbn/alerting-plugin/common';
import { AbortError } from '@kbn/kibana-utils-plugin/common';
import type { RuleAlertType, RuleParams } from '../../../../rule_schema';
Expand Down Expand Up @@ -66,7 +66,10 @@ interface NormalizedRuleError {
rules: RuleDetailsInError[];
}

type BulkActionError = PromisePoolError<string> | PromisePoolError<RuleAlertType> | BulkEditError;
type BulkActionError =
| PromisePoolError<string>
| PromisePoolError<RuleAlertType>
| BulkOperationError;

const normalizeErrorResponse = (errors: BulkActionError[]): NormalizedRuleError[] => {
const errorsMap = new Map<string, NormalizedRuleError>();
Expand All @@ -76,7 +79,7 @@ const normalizeErrorResponse = (errors: BulkActionError[]): NormalizedRuleError[
let statusCode: number = 500;
let errorCode: BulkActionsDryRunErrCode | undefined;
let rule: RuleDetailsInError;
// transform different error types (PromisePoolError<string> | PromisePoolError<RuleAlertType> | BulkEditError)
// transform different error types (PromisePoolError<string> | PromisePoolError<RuleAlertType> | BulkOperationError)
// to one common used in NormalizedRuleError
if ('rule' in errorObj) {
rule = errorObj.rule;
Expand Down
Loading

0 comments on commit 71cf268

Please sign in to comment.