Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APM] Make UI indices space aware (support for spaces) #126176

Merged
merged 10 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions x-pack/plugins/apm/common/apm_saved_object_constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
// the types have to match the names of the saved object mappings
// in /x-pack/plugins/apm/mappings.json

// APM indices
export const APM_INDICES_SAVED_OBJECT_TYPE = 'apm-indices';
export const APM_INDICES_SAVED_OBJECT_ID = 'apm-indices';
// APM index settings
export const APM_INDEX_SETTINGS_SAVED_OBJECT_TYPE = 'apm-indices';
export const APM_INDEX_SETTINGS_SAVED_OBJECT_ID = 'apm-indices';

// APM telemetry
export const APM_TELEMETRY_SAVED_OBJECT_TYPE = 'apm-telemetry';
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import {
EuiButton,
EuiButtonEmpty,
EuiCallOut,
EuiFieldText,
EuiFlexGroup,
EuiFlexItem,
Expand All @@ -19,9 +20,12 @@ import {
EuiToolTip,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import React, { useEffect, useState } from 'react';
import { useKibana } from '../../../../../../../../src/plugins/kibana_react/public';
import { useApmPluginContext } from '../../../../context/apm_plugin/use_apm_plugin_context';
import { useFetcher } from '../../../../hooks/use_fetcher';
import { ApmPluginStartDeps } from '../../../../plugin';
import { clearCache } from '../../../../services/rest/call_api';
import {
APIReturnType,
Expand Down Expand Up @@ -93,6 +97,8 @@ const INITIAL_STATE: ApiResponse = { apmIndexSettings: [] };

export function ApmIndices() {
const { core } = useApmPluginContext();
const { services } = useKibana<ApmPluginStartDeps>();

const { notifications, application } = core;
const canSave = application.capabilities.apm.save;

Expand All @@ -108,6 +114,10 @@ export function ApmIndices() {
[canSave]
);

const { data: space } = useFetcher(() => {
return services.spaces?.getActiveSpace();
}, [services.spaces]);

useEffect(() => {
setApmIndices(
data.apmIndexSettings.reduce(
Expand Down Expand Up @@ -191,6 +201,31 @@ export function ApmIndices() {

<EuiSpacer size="m" />

{space?.name && (
<>
<EuiFlexGroup alignItems="center">
<EuiFlexItem grow={false}>
<EuiCallOut
color="primary"
iconType="spacesApp"
title={
<EuiText size="s">
<FormattedMessage
id="xpack.apm.settings.apmIndices.spaceDescription"
defaultMessage="The index settings apply to the {spaceName} space."
values={{
spaceName: <strong>{space?.name}</strong>,
}}
/>
</EuiText>
}
/>
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer size="m" />
</>
)}

<EuiFlexGroup alignItems="center">
<EuiFlexItem grow={false}>
<EuiForm>
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/apm/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import { getLazyAPMPolicyCreateExtension } from './components/fleet_integration/
import { getLazyAPMPolicyEditExtension } from './components/fleet_integration/lazy_apm_policy_edit_extension';
import { featureCatalogueEntry } from './feature_catalogue_entry';
import type { SecurityPluginStart } from '../../security/public';
import { SpacesPluginStart } from '../../spaces/public';

export type ApmPluginSetup = ReturnType<ApmPlugin['setup']>;

Expand Down Expand Up @@ -82,6 +83,7 @@ export interface ApmPluginStartDeps {
observability: ObservabilityPublicStart;
fleet?: FleetStart;
security?: SecurityPluginStart;
spaces?: SpacesPluginStart;
}

const servicesTitle = i18n.translate('xpack.apm.navigation.servicesTitle', {
Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugins/apm/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
TRANSACTION_TYPE,
} from '../common/elasticsearch_fieldnames';
import { tutorialProvider } from './tutorial';
import { migrateLegacyAPMIndicesToSpaceAware } from './saved_objects/migrations/migrate_legacy_apm_indices_to_space_aware';

export class APMPlugin
implements
Expand Down Expand Up @@ -247,6 +248,11 @@ export class APMPlugin
config: this.currentConfig,
logger: this.logger,
});

migrateLegacyAPMIndicesToSpaceAware({
coreStart: core,
logger: this.logger,
});
}

public stop() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

import { SavedObjectsClient } from 'src/core/server';
import {
APM_INDICES_SAVED_OBJECT_TYPE,
APM_INDICES_SAVED_OBJECT_ID,
APM_INDEX_SETTINGS_SAVED_OBJECT_TYPE,
APM_INDEX_SETTINGS_SAVED_OBJECT_ID,
} from '../../../../common/apm_saved_object_constants';
import { APMConfig } from '../../..';
import { APMRouteHandlerResources } from '../../typings';
import { withApmSpan } from '../../../utils/with_apm_span';
import { ApmIndicesConfig } from '../../../../../observability/common/typings';
import { APMIndices } from '../../../saved_objects/apm_indices';

export type { ApmIndicesConfig };

Expand All @@ -22,13 +23,15 @@ type ISavedObjectsClient = Pick<SavedObjectsClient, 'get'>;
async function getApmIndicesSavedObject(
savedObjectsClient: ISavedObjectsClient
) {
const apmIndices = await withApmSpan('get_apm_indices_saved_object', () =>
savedObjectsClient.get<Partial<ApmIndicesConfig>>(
APM_INDICES_SAVED_OBJECT_TYPE,
APM_INDICES_SAVED_OBJECT_ID
)
const apmIndicesSavedObject = await withApmSpan(
'get_apm_indices_saved_object',
() =>
savedObjectsClient.get<Partial<APMIndices>>(
APM_INDEX_SETTINGS_SAVED_OBJECT_TYPE,
APM_INDEX_SETTINGS_SAVED_OBJECT_ID
)
);
return apmIndices.attributes;
return apmIndicesSavedObject.attributes.apmIndices;
}

export function getApmIndicesConfig(config: APMConfig): ApmIndicesConfig {
Expand Down Expand Up @@ -90,6 +93,6 @@ export async function getApmIndexSettings({
return apmIndices.map((configurationName) => ({
configurationName,
defaultValue: apmIndicesConfig[configurationName], // value defined in kibana[.dev].yml
savedValue: apmIndicesSavedObject[configurationName], // value saved via Saved Objects service
savedValue: apmIndicesSavedObject?.[configurationName], // value saved via Saved Objects service
}));
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ describe('saveApmIndices', () => {
await saveApmIndices(savedObjectsClient, apmIndices);
expect(savedObjectsClient.create).toHaveBeenCalledWith(
expect.any(String),
{ settingA: 'aa', settingF: 'ff', settingG: 'gg' },
{
apmIndices: { settingA: 'aa', settingF: 'ff', settingG: 'gg' },
isSpaceAware: true,
},
expect.any(Object)
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

import { SavedObjectsClientContract } from '../../../../../../../src/core/server';
import {
APM_INDICES_SAVED_OBJECT_TYPE,
APM_INDICES_SAVED_OBJECT_ID,
APM_INDEX_SETTINGS_SAVED_OBJECT_TYPE,
APM_INDEX_SETTINGS_SAVED_OBJECT_ID,
} from '../../../../common/apm_saved_object_constants';
import { APMIndices } from '../../../saved_objects/apm_indices';
import { withApmSpan } from '../../../utils/with_apm_span';
import { ApmIndicesConfig } from './get_apm_indices';

Expand All @@ -18,13 +19,10 @@ export function saveApmIndices(
apmIndices: Partial<ApmIndicesConfig>
) {
return withApmSpan('save_apm_indices', () =>
savedObjectsClient.create(
APM_INDICES_SAVED_OBJECT_TYPE,
removeEmpty(apmIndices),
{
id: APM_INDICES_SAVED_OBJECT_ID,
overwrite: true,
}
savedObjectsClient.create<APMIndices>(
APM_INDEX_SETTINGS_SAVED_OBJECT_TYPE,
{ apmIndices: removeEmpty(apmIndices), isSpaceAware: true },
{ id: APM_INDEX_SETTINGS_SAVED_OBJECT_ID, overwrite: true }
)
);
}
Expand Down
41 changes: 32 additions & 9 deletions x-pack/plugins/apm/server/saved_objects/apm_indices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,43 @@ import { i18n } from '@kbn/i18n';
import { updateApmOssIndexPaths } from './migrations/update_apm_oss_index_paths';
import { ApmIndicesConfigName } from '..';

const properties: { [Property in ApmIndicesConfigName]: { type: 'keyword' } } =
{
sourcemap: { type: 'keyword' },
error: { type: 'keyword' },
onboarding: { type: 'keyword' },
span: { type: 'keyword' },
transaction: { type: 'keyword' },
metric: { type: 'keyword' },
export interface APMIndices {
apmIndices?: {
sourcemap?: string;
error?: string;
onboarding?: string;
span?: string;
transaction?: string;
metric?: string;
};
isSpaceAware?: boolean;
}

const properties: {
apmIndices: {
properties: {
[Property in ApmIndicesConfigName]: { type: 'keyword' };
};
};
isSpaceAware: { type: 'boolean' };
} = {
apmIndices: {
properties: {
sourcemap: { type: 'keyword' },
error: { type: 'keyword' },
onboarding: { type: 'keyword' },
span: { type: 'keyword' },
transaction: { type: 'keyword' },
metric: { type: 'keyword' },
},
},
isSpaceAware: { type: 'boolean' },
};

export const apmIndices: SavedObjectsType = {
name: 'apm-indices',
hidden: false,
namespaceType: 'agnostic',
namespaceType: 'single',
mappings: { properties },
management: {
importableAndExportable: true,
Expand Down
Loading