Skip to content

Commit

Permalink
Adds elasticsearch client to manifest manager context and uses it for…
Browse files Browse the repository at this point in the history
… bulkUpdate
  • Loading branch information
dasansol92 committed Jun 27, 2023
1 parent dce6775 commit 92b521b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
* 2.0.
*/

import { savedObjectsClientMock, loggingSystemMock } from '@kbn/core/server/mocks';
import {
savedObjectsClientMock,
loggingSystemMock,
elasticsearchServiceMock,
} from '@kbn/core/server/mocks';
import type { Logger } from '@kbn/core/server';
import type { PackagePolicyClient } from '@kbn/fleet-plugin/server';
import { createPackagePolicyServiceMock } from '@kbn/fleet-plugin/server/mocks';
Expand Down Expand Up @@ -89,6 +93,7 @@ export const buildManifestManagerContextMock = (
logger: loggingSystemMock.create().get() as jest.Mocked<Logger>,
experimentalFeatures: parseExperimentalConfigValue([]).features,
packagerTaskPackagePolicyUpdateBatchSize: 10,
esClient: elasticsearchServiceMock.createElasticsearchClient(),
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ describe('ManifestManager', () => {
expect(context.packagePolicyService.bulkUpdate).toHaveBeenNthCalledWith(
1,
expect.anything(),
undefined,
context.esClient,
[
createPackagePolicyWithConfigMock({
id: TEST_POLICY_ID_1,
Expand Down Expand Up @@ -990,7 +990,7 @@ describe('ManifestManager', () => {
expect(context.packagePolicyService.bulkUpdate).toHaveBeenNthCalledWith(
1,
expect.anything(),
undefined,
context.esClient,
[
createPackagePolicyWithConfigMock({
id: TEST_POLICY_ID_1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pMap from 'p-map';
import semver from 'semver';
import { isEqual, isEmpty, chunk } from 'lodash';
import type { ElasticsearchClient } from '@kbn/core/server';
import { type Logger, type SavedObjectsClientContract } from '@kbn/core/server';
import {
ENDPOINT_EVENT_FILTERS_LIST_ID,
Expand Down Expand Up @@ -92,6 +93,7 @@ export interface ManifestManagerContext {
logger: Logger;
experimentalFeatures: ExperimentalFeatures;
packagerTaskPackagePolicyUpdateBatchSize: number;
esClient: ElasticsearchClient;
}

const getArtifactIds = (manifest: ManifestSchema) =>
Expand All @@ -112,6 +114,7 @@ export class ManifestManager {
protected experimentalFeatures: ExperimentalFeatures;
protected cachedExceptionsListsByOs: Map<string, ExceptionListItemSchema[]>;
protected packagerTaskPackagePolicyUpdateBatchSize: number;
protected esClient: ElasticsearchClient;

constructor(context: ManifestManagerContext) {
this.artifactClient = context.artifactClient;
Expand All @@ -124,6 +127,7 @@ export class ManifestManager {
this.cachedExceptionsListsByOs = new Map();
this.packagerTaskPackagePolicyUpdateBatchSize =
context.packagerTaskPackagePolicyUpdateBatchSize;
this.esClient = context.esClient;
}

/**
Expand Down Expand Up @@ -606,8 +610,7 @@ export class ManifestManager {
for (const currentBatch of updateBatches) {
const response = await this.packagePolicyService.bulkUpdate(
this.savedObjectsClient,
// @ts-expect-error TS2345
undefined,
this.esClient,
currentBatch
);

Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/security_solution/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ export class Plugin implements ISecuritySolutionPlugin {
logger,
experimentalFeatures: config.experimentalFeatures,
packagerTaskPackagePolicyUpdateBatchSize: config.packagerTaskPackagePolicyUpdateBatchSize,
esClient: core.elasticsearch.client.asInternalUser,
});

// Migrate artifacts to fleet and then start the minifest task after that is done
Expand Down

0 comments on commit 92b521b

Please sign in to comment.