Skip to content

Commit

Permalink
[8.x] [Fleet] Reuse package infos for synthetics bulk ops (#191486) (#…
Browse files Browse the repository at this point in the history
…193846)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Fleet] Reuse package infos for synthetics bulk ops
(#191486)](#191486)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"Shahzad","email":"shahzad31comp@gmail.com"},"sourceCommit":{"committedDate":"2024-09-24T10:33:22Z","message":"[Fleet]
Reuse package infos for synthetics bulk ops (#191486)\n\n##
Summary\r\n\r\n Reuse package infos for synthetics bulk ops !!\r\n\r\nWe
are just trying to debug Project monitor push API which
interacts\r\nwith fleet code and trying to see what excessive calls are
being made,\r\nwhich can be
reduced.","sha":"6d584d49a73284077d5331c9c5398593f9edd5ea","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","v9.0.0","backport:prev-minor","ci:project-deploy-observability","Team:obs-ux-management"],"title":"[Fleet]
Reuse package infos for synthetics bulk
ops","number":191486,"url":"#191486
Reuse package infos for synthetics bulk ops (#191486)\n\n##
Summary\r\n\r\n Reuse package infos for synthetics bulk ops !!\r\n\r\nWe
are just trying to debug Project monitor push API which
interacts\r\nwith fleet code and trying to see what excessive calls are
being made,\r\nwhich can be
reduced.","sha":"6d584d49a73284077d5331c9c5398593f9edd5ea"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"#191486
Reuse package infos for synthetics bulk ops (#191486)\n\n##
Summary\r\n\r\n Reuse package infos for synthetics bulk ops !!\r\n\r\nWe
are just trying to debug Project monitor push API which
interacts\r\nwith fleet code and trying to see what excessive calls are
being made,\r\nwhich can be
reduced.","sha":"6d584d49a73284077d5331c9c5398593f9edd5ea"}}]}]
BACKPORT-->

Co-authored-by: Shahzad <shahzad31comp@gmail.com>
  • Loading branch information
kibanamachine and shahzad31 committed Sep 24, 2024
1 parent bfac4dd commit 5770e8a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
27 changes: 24 additions & 3 deletions x-pack/plugins/fleet/server/services/package_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ import { getAuthzFromRequest, doesNotHaveRequiredFleetAuthz } from './security';

import { storedPackagePolicyToAgentInputs } from './agent_policies';
import { agentPolicyService } from './agent_policy';
import { getPackageInfo, getInstallation, ensureInstalledPackage } from './epm/packages';
import {
getPackageInfo,
getInstallation,
ensureInstalledPackage,
getInstallationObject,
} from './epm/packages';
import { getAssetsDataFromAssetsMap } from './epm/packages/assets';
import { compileTemplate } from './epm/agent/agent';
import { escapeSearchQueryPhrase, normalizeKuery as _normalizeKuery } from './saved_object';
Expand Down Expand Up @@ -1874,9 +1879,25 @@ class PackagePolicyClientImpl implements PackagePolicyClient {
public async buildPackagePolicyFromPackage(
soClient: SavedObjectsClientContract,
pkgName: string,
logger?: Logger
options?: { logger?: Logger; installMissingPackage?: boolean }
): Promise<NewPackagePolicy | undefined> {
const pkgInstall = await getInstallation({ savedObjectsClient: soClient, pkgName, logger });
const pkgInstallObj = await getInstallationObject({
savedObjectsClient: soClient,
pkgName,
logger: options?.logger,
});
let pkgInstall = pkgInstallObj?.attributes;
if (!pkgInstall && options?.installMissingPackage) {
const esClient = await appContextService.getInternalUserESClient();
const result = await ensureInstalledPackage({
esClient,
pkgName,
savedObjectsClient: soClient,
});
if (result.package) {
pkgInstall = result.package;
}
}
if (pkgInstall) {
const packageInfo = await getPackageInfo({
savedObjectsClient: soClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export interface PackagePolicyClient {
buildPackagePolicyFromPackage(
soClient: SavedObjectsClientContract,
pkgName: string,
logger?: Logger
options?: { logger?: Logger; installMissingPackage?: boolean }
): Promise<NewPackagePolicy | undefined>;

runExternalCallbacks<A extends ExternalCallback[0]>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class SyntheticsPrivateLocation {
const newPolicy = await this.server.fleet.packagePolicyService.buildPackagePolicyFromPackage(
soClient,
'synthetics',
this.server.logger
{ logger: this.server.logger, installMissingPackage: true }
);

if (!newPolicy) {
Expand Down

0 comments on commit 5770e8a

Please sign in to comment.