mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
fix logger text and fix bulk error type (#144598)
* fix logger text and fix bulk error type * add logging of failed to delete task ids Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
c2eb7b782c
commit
53037ef848
8 changed files with 40 additions and 37 deletions
|
@ -35,7 +35,7 @@ export type { PluginSetupContract, PluginStartContract } from './plugin';
|
|||
export type {
|
||||
FindResult,
|
||||
BulkEditOperation,
|
||||
BulkEditError,
|
||||
BulkOperationError,
|
||||
BulkEditOptions,
|
||||
BulkEditOptionsFilter,
|
||||
BulkEditOptionsIds,
|
||||
|
|
|
@ -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[];
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
@ -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[];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
@ -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(
|
||||
|
@ -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> = {};
|
||||
|
@ -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;
|
||||
|
@ -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>(
|
||||
|
@ -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();
|
||||
|
|
|
@ -56,7 +56,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry);
|
||||
(auditLogger.log as jest.Mock).mockClear();
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
setGlobalDate();
|
||||
|
@ -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: [],
|
||||
|
|
|
@ -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';
|
||||
|
@ -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>();
|
||||
|
@ -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;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import type { BulkEditError, RulesClient } from '@kbn/alerting-plugin/server';
|
||||
import type { BulkOperationError, RulesClient } from '@kbn/alerting-plugin/server';
|
||||
import pMap from 'p-map';
|
||||
|
||||
import {
|
||||
|
@ -82,7 +82,7 @@ export const bulkEditRules = async ({
|
|||
const rulesAction = ruleActions.pop();
|
||||
|
||||
if (rulesAction) {
|
||||
const unmuteErrors: BulkEditError[] = [];
|
||||
const unmuteErrors: BulkOperationError[] = [];
|
||||
const rulesToUnmute = await pMap(
|
||||
result.rules,
|
||||
async (rule) => {
|
||||
|
|
|
@ -41,7 +41,7 @@ import {
|
|||
ActionVariable,
|
||||
RuleType as CommonRuleType,
|
||||
} from '@kbn/alerting-plugin/common';
|
||||
import type { BulkEditError } from '@kbn/alerting-plugin/server';
|
||||
import type { BulkOperationError } from '@kbn/alerting-plugin/server';
|
||||
import { RuleRegistrySearchRequestPagination } from '@kbn/rule-registry-plugin/common';
|
||||
import { EcsFieldsResponse } from '@kbn/rule-registry-plugin/common/search_strategy';
|
||||
import { SortCombinations } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
|
@ -158,7 +158,7 @@ export enum RuleFlyoutCloseReason {
|
|||
|
||||
export interface BulkEditResponse {
|
||||
rules: Rule[];
|
||||
errors: BulkEditError[];
|
||||
errors: BulkOperationError[];
|
||||
total: number;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue