mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[Fleet] Fix APM to support space aware Fleet (#206964)
This commit is contained in:
parent
671731ce3f
commit
26f4900bf0
11 changed files with 67 additions and 10 deletions
|
@ -15170,6 +15170,7 @@
|
|||
"monitoring": {
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"apm": {},
|
||||
"enabled": {
|
||||
"type": "boolean"
|
||||
},
|
||||
|
@ -15193,7 +15194,8 @@
|
|||
"enabled",
|
||||
"metrics",
|
||||
"logs",
|
||||
"traces"
|
||||
"traces",
|
||||
"apm"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
|
|
|
@ -15170,6 +15170,7 @@
|
|||
"monitoring": {
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"apm": {},
|
||||
"enabled": {
|
||||
"type": "boolean"
|
||||
},
|
||||
|
@ -15193,7 +15194,8 @@
|
|||
"enabled",
|
||||
"metrics",
|
||||
"logs",
|
||||
"traces"
|
||||
"traces",
|
||||
"apm"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
|
|
|
@ -16780,6 +16780,7 @@ paths:
|
|||
additionalProperties: false
|
||||
type: object
|
||||
properties:
|
||||
apm: {}
|
||||
enabled:
|
||||
type: boolean
|
||||
logs:
|
||||
|
@ -16797,6 +16798,7 @@ paths:
|
|||
- metrics
|
||||
- logs
|
||||
- traces
|
||||
- apm
|
||||
protection:
|
||||
additionalProperties: false
|
||||
type: object
|
||||
|
|
|
@ -18914,6 +18914,7 @@ paths:
|
|||
additionalProperties: false
|
||||
type: object
|
||||
properties:
|
||||
apm: {}
|
||||
enabled:
|
||||
type: boolean
|
||||
logs:
|
||||
|
@ -18931,6 +18932,7 @@ paths:
|
|||
- metrics
|
||||
- logs
|
||||
- traces
|
||||
- apm
|
||||
protection:
|
||||
additionalProperties: false
|
||||
type: object
|
||||
|
|
|
@ -409,6 +409,7 @@ export const FullAgentPolicyResponseSchema = schema.object({
|
|||
metrics: schema.boolean(),
|
||||
logs: schema.boolean(),
|
||||
traces: schema.boolean(),
|
||||
apm: schema.maybe(schema.any()),
|
||||
}),
|
||||
download: schema.object({
|
||||
sourceURI: schema.string(),
|
||||
|
|
|
@ -5,8 +5,29 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import type { CoreStart } from '@kbn/core/server';
|
||||
import { kibanaRequestFactory } from '@kbn/core-http-server-utils';
|
||||
import { SECURITY_EXTENSION_ID, type CoreStart, SavedObjectsClient } from '@kbn/core/server';
|
||||
import { DEFAULT_SPACE_ID } from '@kbn/spaces-plugin/common';
|
||||
|
||||
export async function getInternalSavedObjectsClient(coreStart: CoreStart) {
|
||||
return coreStart.savedObjects.createInternalRepository();
|
||||
return new SavedObjectsClient(coreStart.savedObjects.createInternalRepository());
|
||||
}
|
||||
|
||||
export function getInternalSavedObjectsClientForSpaceId(coreStart: CoreStart, spaceId?: string) {
|
||||
const request = kibanaRequestFactory({
|
||||
headers: {},
|
||||
path: '/',
|
||||
route: { settings: {} },
|
||||
url: { href: '', hash: '' } as URL,
|
||||
raw: { req: { url: '/' } } as any,
|
||||
});
|
||||
|
||||
if (spaceId && spaceId !== DEFAULT_SPACE_ID) {
|
||||
coreStart.http.basePath.set(request, `/s/${spaceId}`);
|
||||
}
|
||||
|
||||
// soClient as kibana internal users, be careful on how you use it, security is not enabled
|
||||
return coreStart.savedObjects.getScopedClient(request, {
|
||||
excludedExtensions: [SECURITY_EXTENSION_ID],
|
||||
});
|
||||
}
|
||||
|
|
|
@ -200,6 +200,7 @@ export class APMPlugin
|
|||
// This will add an API key to all existing APM package policies
|
||||
addApiKeysToEveryPackagePolicyIfMissing({
|
||||
coreStartPromise: getCoreStart(),
|
||||
licensing: plugins.licensing,
|
||||
pluginStartPromise: getPluginStart(),
|
||||
logger: this.logger,
|
||||
}).catch((e) => {
|
||||
|
|
|
@ -7,9 +7,12 @@
|
|||
|
||||
import { omit } from 'lodash';
|
||||
import type { PackagePolicy } from '@kbn/fleet-plugin/common';
|
||||
import type { CoreStart, Logger } from '@kbn/core/server';
|
||||
import type { CoreStart, Logger, SavedObjectsClientContract } from '@kbn/core/server';
|
||||
import type { FleetStartContract } from '@kbn/fleet-plugin/server';
|
||||
import { getInternalSavedObjectsClient } from '../../../lib/helpers/get_internal_saved_objects_client';
|
||||
import type { LicensingPluginSetup } from '@kbn/licensing-plugin/server';
|
||||
import { filter, lastValueFrom, take } from 'rxjs';
|
||||
|
||||
import { getInternalSavedObjectsClientForSpaceId } from '../../../lib/helpers/get_internal_saved_objects_client';
|
||||
import type { APMPluginStartDependencies } from '../../../types';
|
||||
import { getApmPackagePolicies } from '../get_apm_package_policies';
|
||||
import { createApmAgentConfigApiKey, createApmSourceMapApiKey } from './create_apm_api_keys';
|
||||
|
@ -19,10 +22,12 @@ export async function addApiKeysToEveryPackagePolicyIfMissing({
|
|||
coreStartPromise,
|
||||
pluginStartPromise,
|
||||
logger,
|
||||
licensing,
|
||||
}: {
|
||||
coreStartPromise: Promise<CoreStart>;
|
||||
pluginStartPromise: Promise<APMPluginStartDependencies>;
|
||||
logger: Logger;
|
||||
licensing: LicensingPluginSetup;
|
||||
}) {
|
||||
const coreStart = await coreStartPromise;
|
||||
const { fleet } = await pluginStartPromise;
|
||||
|
@ -30,6 +35,18 @@ export async function addApiKeysToEveryPackagePolicyIfMissing({
|
|||
return;
|
||||
}
|
||||
|
||||
// We need to wait for the licence feature to be available,
|
||||
// to have our internal saved object client with encrypted saved object working properly
|
||||
await lastValueFrom(
|
||||
licensing.license$.pipe(
|
||||
filter(
|
||||
(licence) =>
|
||||
licence.getFeature('security').isEnabled && licence.getFeature('security').isAvailable
|
||||
),
|
||||
take(1)
|
||||
)
|
||||
);
|
||||
|
||||
const apmFleetPolicies = await getApmPackagePolicies({
|
||||
coreStart,
|
||||
fleetPluginStart: fleet,
|
||||
|
@ -37,8 +54,13 @@ export async function addApiKeysToEveryPackagePolicyIfMissing({
|
|||
|
||||
return Promise.all(
|
||||
apmFleetPolicies.items.map((policy) => {
|
||||
const savedObjectsClient = getInternalSavedObjectsClientForSpaceId(
|
||||
coreStart,
|
||||
policy.spaceIds?.[0]
|
||||
);
|
||||
return addApiKeysToPackagePolicyIfMissing({
|
||||
policy,
|
||||
savedObjectsClient,
|
||||
coreStart,
|
||||
fleet,
|
||||
logger,
|
||||
|
@ -50,10 +72,12 @@ export async function addApiKeysToEveryPackagePolicyIfMissing({
|
|||
export async function addApiKeysToPackagePolicyIfMissing({
|
||||
policy,
|
||||
coreStart,
|
||||
savedObjectsClient,
|
||||
fleet,
|
||||
logger,
|
||||
}: {
|
||||
policy: PackagePolicy;
|
||||
savedObjectsClient: SavedObjectsClientContract;
|
||||
coreStart: CoreStart;
|
||||
fleet: FleetStartContract;
|
||||
logger: Logger;
|
||||
|
@ -85,7 +109,7 @@ export async function addApiKeysToPackagePolicyIfMissing({
|
|||
});
|
||||
|
||||
const internalESClient = coreStart.elasticsearch.client.asInternalUser;
|
||||
const savedObjectsClient = await getInternalSavedObjectsClient(coreStart);
|
||||
|
||||
const newPolicy = await fleet.packagePolicyService.update(
|
||||
savedObjectsClient,
|
||||
internalESClient,
|
||||
|
|
|
@ -16,11 +16,11 @@ export async function getApmPackagePolicies({
|
|||
coreStart: CoreStart;
|
||||
fleetPluginStart: NonNullable<APMPluginStartDependencies['fleet']>;
|
||||
}) {
|
||||
// @ts-ignore
|
||||
const savedObjectsClient: SavedObjectsClientContract = await getInternalSavedObjectsClient(
|
||||
coreStart
|
||||
);
|
||||
return await fleetPluginStart.packagePolicyService.list(savedObjectsClient, {
|
||||
kuery: 'ingest-package-policies.package.name:apm',
|
||||
spaceId: '*',
|
||||
});
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ function onPackagePolicyPostCreate({
|
|||
coreStart: CoreStart;
|
||||
logger: Logger;
|
||||
}): PostPackagePolicyPostCreateCallback {
|
||||
return async (packagePolicy) => {
|
||||
return async (packagePolicy, savedObjectsClient) => {
|
||||
if (packagePolicy.package?.name !== 'apm') {
|
||||
return packagePolicy;
|
||||
}
|
||||
|
@ -130,6 +130,7 @@ function onPackagePolicyPostCreate({
|
|||
// add api key to new package policy
|
||||
await addApiKeysToPackagePolicyIfMissing({
|
||||
policy: packagePolicy,
|
||||
savedObjectsClient,
|
||||
coreStart,
|
||||
fleet,
|
||||
logger,
|
||||
|
|
|
@ -131,7 +131,8 @@
|
|||
"@kbn/saved-search-plugin",
|
||||
"@kbn/charts-theme",
|
||||
"@kbn/response-ops-rule-params",
|
||||
"@kbn/entityManager-plugin"
|
||||
"@kbn/entityManager-plugin",
|
||||
"@kbn/core-http-server-utils"
|
||||
],
|
||||
"exclude": ["target/**/*"]
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue