Skip to content

Commit

Permalink
Fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Nov 9, 2024
1 parent c47e7a1 commit 0d18c22
Show file tree
Hide file tree
Showing 110 changed files with 454 additions and 508 deletions.
11 changes: 0 additions & 11 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1566,13 +1566,6 @@ module.exports = {
plugins: ['react', '@typescript-eslint'],
rules: {
'import/no-nodejs-modules': 'error',
'no-restricted-imports': [
'error',
{
// prevents UI code from importing server side code and then webpack including it when doing builds
patterns: ['**/server/*'],
},
],
'react/boolean-prop-naming': 'error',
'react/button-has-type': 'error',
'react/display-name': 'error',
Expand Down Expand Up @@ -1636,10 +1629,6 @@ module.exports = {
'no-restricted-imports': [
'error',
{
// prevents code from importing files that contain the name "legacy" within their name. This is a mechanism
// to help deprecation and prevent accidental re-use/continued use of code we plan on removing. If you are
// finding yourself turning this off a lot for "new code" consider renaming the file and functions if it is has valid uses.
patterns: ['*legacy*'],
paths: [
{
name: 'react-router-dom',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1845,4 +1845,4 @@
"zod-to-json-schema": "^3.23.0"
},
"packageManager": "[email protected]"
}
}
8 changes: 6 additions & 2 deletions x-pack/plugins/alerting/server/alerts_client/alerts_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import type {
WithoutReservedActionGroups,
DataStreamAdapter,
} from '../types';

import { LegacyAlertsClient } from './legacy_alerts_client';
import type { IIndexPatternString } from '../alerts_service/resource_installer_utils';
import { getIndexTemplateAndPattern } from '../alerts_service/resource_installer_utils';
import type { CreateAlertsClientParams } from '../alerts_service/alerts_service';
import type { AlertRule, LogAlertsOpts, ProcessAlertsOpts, SearchResult } from './types';
import type {
IAlertsClient,
InitializeExecutionOpts,
Expand All @@ -43,6 +43,10 @@ import type {
GetSummarizedAlertsParams,
GetMaintenanceWindowScopedQueryAlertsParams,
ScopedQueryAggregationResult,
AlertRule,
LogAlertsOpts,
ProcessAlertsOpts,
SearchResult,
} from './types';
import {
buildNewAlert,
Expand Down Expand Up @@ -326,7 +330,7 @@ export class AlertsClient<
// Persist alerts first
await this.persistAlertsHelper();

return await this.updatePersistedAlertsWithMaintenanceWindowIds();
return this.updatePersistedAlertsWithMaintenanceWindowIds();
}

public getAlertsToSerialize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1974,7 +1974,7 @@ describe('Alerts Service', () => {
await new Promise((r) => setTimeout(r, delayMs));
}

return await alertsService.createAlertsClient({
return alertsService.createAlertsClient({
alertingEventLogger,
logger,
request: fakeRequest,
Expand Down Expand Up @@ -2081,7 +2081,7 @@ describe('Alerts Service', () => {
await new Promise((r) => setTimeout(r, delayMs));
}

return await alertsService.createAlertsClient({
return alertsService.createAlertsClient({
alertingEventLogger,
logger,
request: fakeRequest,
Expand Down
23 changes: 11 additions & 12 deletions x-pack/plugins/alerting/server/alerts_service/alerts_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ export class AlertsService implements IAlertsService {
await Promise.all(
initFns.map((fn) =>
installWithTimeout({
installFn: async () => await fn(),
installFn: async () => fn(),
pluginStop$: this.options.pluginStop$,
logger: this.options.logger,
timeoutMs,
Expand Down Expand Up @@ -430,14 +430,13 @@ export class AlertsService implements IAlertsService {
dynamic: mappings.dynamic,
context,
});
initFns.push(
async () =>
await createOrUpdateComponentTemplate({
logger: this.options.logger,
esClient,
template: componentTemplate,
totalFieldsLimit: TOTAL_FIELDS_LIMIT,
})
initFns.push(async () =>
createOrUpdateComponentTemplate({
logger: this.options.logger,
esClient,
template: componentTemplate,
totalFieldsLimit: TOTAL_FIELDS_LIMIT,
})
);
componentTemplateRefs.push(componentTemplate.name);
}
Expand All @@ -453,7 +452,7 @@ export class AlertsService implements IAlertsService {
// Context specific initialization installs index template and write index
initFns = initFns.concat([
async () =>
await createOrUpdateIndexTemplate({
createOrUpdateIndexTemplate({
logger: this.options.logger,
esClient,
template: getIndexTemplate({
Expand All @@ -467,7 +466,7 @@ export class AlertsService implements IAlertsService {
}),
}),
async () =>
await createConcreteWriteIndex({
createConcreteWriteIndex({
logger: this.options.logger,
esClient,
totalFieldsLimit: TOTAL_FIELDS_LIMIT,
Expand All @@ -481,7 +480,7 @@ export class AlertsService implements IAlertsService {
// the component template.
for (const fn of initFns) {
await installWithTimeout({
installFn: async () => await fn(),
installFn: async () => fn(),
pluginStop$: this.options.pluginStop$,
logger: this.options.logger,
timeoutMs,
Expand Down
7 changes: 4 additions & 3 deletions x-pack/plugins/alerting/server/alerts_service/test_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ export const retryUntil = async (
count: number = RETRY_UNTIL_DEFAULT_COUNT,
wait: number = RETRY_UNTIL_DEFAULT_WAIT
): Promise<boolean> => {
let _count = count;
await delay(wait);
while (count > 0) {
count--;
while (_count > 0) {
_count--;

if (await fn()) return true;

Expand All @@ -31,4 +32,4 @@ export const retryUntil = async (
return false;
};

const delay = async (millis: number) => await new Promise((resolve) => setTimeout(resolve, millis));
const delay = async (millis: number) => new Promise((resolve) => setTimeout(resolve, millis));
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ import {
} from '../../../../rules_client/common/audit_events';

export async function deleteBackfill(context: RulesClientContext, id: string): Promise<{}> {
return await retryIfConflicts(
context.logger,
`rulesClient.deleteBackfill('${id}')`,
async () => await deleteWithOCC(context, { id })
return retryIfConflicts(context.logger, `rulesClient.deleteBackfill('${id}')`, async () =>
deleteWithOCC(context, { id })
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export async function scheduleBackfill(
}

const actionsClient = await context.getActionsClient();
return await context.backfillClient.bulkQueue({
return context.backfillClient.bulkQueue({
auditLogger: context.auditLogger,
params,
rules: rulesToSchedule.map(({ id, attributes, references }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ export async function archiveMaintenanceWindow(
context: MaintenanceWindowClientContext,
params: ArchiveMaintenanceWindowParams
): Promise<MaintenanceWindow> {
return await retryIfConflicts(
return retryIfConflicts(
context.logger,
`maintenanceWindowClient.archive('${params.id})`,
async () => {
return await archiveWithOCC(context, params);
return archiveWithOCC(context, params);
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export async function deleteMaintenanceWindow(
context: MaintenanceWindowClientContext,
params: DeleteMaintenanceWindowParams
): Promise<{}> {
return await retryIfConflicts(
return retryIfConflicts(
context.logger,
`maintenanceWindowClient.delete('${params.id}')`,
async () => await deleteWithOCC(context, params)
async () => deleteWithOCC(context, params)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ export async function finishMaintenanceWindow(
context: MaintenanceWindowClientContext,
params: FinishMaintenanceWindowParams
): Promise<MaintenanceWindow> {
return await retryIfConflicts(
return retryIfConflicts(
context.logger,
`maintenanceWindowClient.finish('${params.id})`,
async () => {
return await finishWithOCC(context, params);
return finishWithOCC(context, params);
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export async function updateMaintenanceWindow(
context: MaintenanceWindowClientContext,
params: UpdateMaintenanceWindowParams
): Promise<MaintenanceWindow> {
return await retryIfConflicts(
return retryIfConflicts(
context.logger,
`maintenanceWindowClient.update('${params.id})`,
async () => {
return await updateWithOCC(context, params);
return updateWithOCC(context, params);
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
import { schema } from '@kbn/config-schema';
import { encryptedSavedObjectsMock } from '@kbn/encrypted-saved-objects-plugin/server/mocks';
import { actionsAuthorizationMock } from '@kbn/actions-plugin/server/mocks';
import type { ActionsAuthorization } from '@kbn/actions-plugin/server';
import type { ActionsAuthorization, ActionsClient } from '@kbn/actions-plugin/server';
import { auditLoggerMock } from '@kbn/security-plugin/server/audit/mocks';
import { loggerMock } from '@kbn/logging-mocks';
import type { ActionsClient } from '@kbn/actions-plugin/server';
import { ruleTypeRegistryMock } from '../../../../rule_type_registry.mock';
import { alertingAuthorizationMock } from '../../../../authorization/alerting_authorization.mock';
import { RecoveredActionGroup } from '../../../../../common';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ import { RULE_SAVED_OBJECT_TYPE } from '../../../../saved_objects';
import { convertRuleIdsToKueryNode } from '../../../../lib';
import { bulkMarkApiKeysForInvalidation } from '../../../../invalidate_pending_api_keys/bulk_mark_api_keys_for_invalidation';
import { ruleAuditEvent, RuleAuditAction } from '../../../../rules_client/common/audit_events';
import { tryToRemoveTasks } from '../../../../rules_client/common';
import { API_KEY_GENERATE_CONCURRENCY } from '../../../../rules_client/common/constants';
import {
getAuthorizationFilter,
checkAuthorizationAndGetTotal,
migrateLegacyActions,
untrackRuleAlerts,
} from '../../../../rules_client/lib';
import {
retryIfBulkOperationConflicts,
buildKueryNodeFilter,
tryToRemoveTasks,
} from '../../../../rules_client/common';
import type { RulesClientContext } from '../../../../rules_client/types';
import type {
Expand All @@ -37,7 +38,6 @@ import { transformRuleAttributesToRuleDomain, transformRuleDomainToRule } from '
import { ruleDomainSchema } from '../../schemas';
import type { RuleParams, RuleDomain } from '../../types';
import type { RawRule, SanitizedRule } from '../../../../types';
import { untrackRuleAlerts } from '../../../../rules_client/lib';

export const bulkDeleteRules = async <Params extends RuleParams>(
context: RulesClientContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
*/
import type { KueryNode } from '@kbn/es-query';
import { nodeBuilder } from '@kbn/es-query';
import type { SavedObjectsBulkUpdateObject, SavedObjectsBulkCreateObject } from '@kbn/core/server';
import type {
SavedObjectsBulkUpdateObject,
SavedObjectsBulkCreateObject,
Logger,
} from '@kbn/core/server';
import Boom from '@hapi/boom';
import { withSpan } from '@kbn/apm-utils';
import pMap from 'p-map';
import type { Logger } from '@kbn/core/server';
import type { TaskManagerStartContract } from '@kbn/task-manager-plugin/server';
import { RULE_SAVED_OBJECT_TYPE } from '../../../../saved_objects';
import type { RawRule, SanitizedRule, RawRuleAction } from '../../../../types';
Expand Down Expand Up @@ -306,7 +309,7 @@ const tryToDisableTasks = async ({
logger: Logger;
taskManager: TaskManagerStartContract;
}) => {
return await withSpan({ name: 'taskManager.bulkDisable', type: 'rules' }, async () => {
return withSpan({ name: 'taskManager.bulkDisable', type: 'rules' }, async () => {
if (taskIdsToDisable.length > 0) {
try {
const resultFromDisablingTasks = await taskManager.bulkDisable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
siemRule2,
} from '../../../../rules_client/tests/test_helpers';
import { migrateLegacyActions } from '../../../../rules_client/lib';

import { migrateLegacyActionsMock } from '../../../../rules_client/lib/siem_legacy_actions/retrieve_migrated_legacy_actions.mock';
import { ConnectorAdapterRegistry } from '../../../../connector_adapters/connector_adapter_registry';
import type { ConnectorAdapter } from '../../../../connector_adapters/types';
Expand Down Expand Up @@ -1878,6 +1879,7 @@ describe('bulkEdit()', () => {
expect(unsecuredSavedObjectsClient.bulkCreate).toHaveBeenCalledTimes(0);
expect(bulkMarkApiKeysForInvalidation).toHaveBeenCalledTimes(0);

// eslint-disable-next-line require-atomic-updates
bulkEditOperationsSchema.validate = originalValidate;
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { validateAndAuthorizeSystemActions } from '../../../../lib/validate_auth
import type { Rule, RuleAction, RuleSystemAction } from '../../../../../common';
import { RULE_SAVED_OBJECT_TYPE } from '../../../../saved_objects';
import type { BulkActionSkipResult } from '../../../../../common/bulk_edit';
import type { RuleTypeRegistry } from '../../../../types';
import {
validateRuleTypeParams,
getRuleNotifyWhenType,
Expand Down Expand Up @@ -53,6 +52,7 @@ import {
updateMeta,
addGeneratedActionValues,
createNewAPIKeySet,
migrateLegacyActions,
} from '../../../../rules_client/lib';
import type {
BulkOperationError,
Expand All @@ -61,7 +61,6 @@ import type {
NormalizedAlertActionWithGeneratedValues,
NormalizedAlertAction,
} from '../../../../rules_client/types';
import { migrateLegacyActions } from '../../../../rules_client/lib';
import type {
BulkEditFields,
BulkEditOperation,
Expand All @@ -70,7 +69,7 @@ import type {
ParamsModifier,
ShouldIncrementRevision,
} from './types';
import type { RawRuleAction, RawRule, SanitizedRule } from '../../../../types';
import type { RawRuleAction, RawRule, SanitizedRule, RuleTypeRegistry } from '../../../../types';
import { ruleNotifyWhen } from '../../constants';
import { actionRequestSchema, ruleDomainSchema, systemActionRequestSchema } from '../../schemas';
import type { RuleParams, RuleDomain, RuleSnoozeSchedule } from '../../types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ import { alertingAuthorizationMock } from '../../../../authorization/alerting_au
import { encryptedSavedObjectsMock } from '@kbn/encrypted-saved-objects-plugin/server/mocks';
import { actionsAuthorizationMock } from '@kbn/actions-plugin/server/mocks';
import type { AlertingAuthorization } from '../../../../authorization/alerting_authorization';
import type { ActionsAuthorization } from '@kbn/actions-plugin/server';
import type { ActionsAuthorization, ActionsClient } from '@kbn/actions-plugin/server';
import { auditLoggerMock } from '@kbn/security-plugin/server/audit/mocks';
import { getBeforeSetup, setGlobalDate } from '../../../../rules_client/tests/lib';
import { loggerMock } from '@kbn/logging-mocks';
import type { BulkUpdateTaskResult } from '@kbn/task-manager-plugin/server/task_scheduling';
import type { ActionsClient } from '@kbn/actions-plugin/server';
import {
disabledRule1,
disabledRule2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import type {
SavedObjectsBulkCreateObject,
SavedObjectsBulkUpdateObject,
SavedObjectsFindResult,
Logger,
} from '@kbn/core/server';
import { withSpan } from '@kbn/apm-utils';
import type { Logger } from '@kbn/core/server';
import type { TaskManagerStartContract } from '@kbn/task-manager-plugin/server';
import { TaskStatus } from '@kbn/task-manager-plugin/server';
import type { TaskInstanceWithDeprecatedFields } from '@kbn/task-manager-plugin/server/task';
Expand Down Expand Up @@ -161,14 +161,12 @@ const bulkEnableRulesWithOCC = async (
type: 'rules',
},
async () =>
await context.encryptedSavedObjectsClient.createPointInTimeFinderDecryptedAsInternalUser<RawRule>(
{
filter,
type: RULE_SAVED_OBJECT_TYPE,
perPage: 100,
...(context.namespace ? { namespaces: [context.namespace] } : undefined),
}
)
context.encryptedSavedObjectsClient.createPointInTimeFinderDecryptedAsInternalUser<RawRule>({
filter,
type: RULE_SAVED_OBJECT_TYPE,
perPage: 100,
...(context.namespace ? { namespaces: [context.namespace] } : undefined),
})
);

const rulesFinderRules: Array<SavedObjectsFindResult<RawRule>> = [];
Expand Down
Loading

0 comments on commit 0d18c22

Please sign in to comment.