Skip to content

Commit

Permalink
[APM] Only register items in side nav if user has permissions to see …
Browse files Browse the repository at this point in the history
…app (#101707) (#101728)

Co-authored-by: Søren Louv-Jansen <[email protected]>
  • Loading branch information
kibanamachine and sorenlouv authored Jun 9, 2021
1 parent f9ca6ff commit e0fb513
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 61 deletions.
109 changes: 54 additions & 55 deletions x-pack/plugins/apm/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/

import { i18n } from '@kbn/i18n';
import { of } from 'rxjs';
import { from } from 'rxjs';
import { map } from 'rxjs/operators';
import type { ConfigSchema } from '.';
import {
AppMountParameters,
Expand Down Expand Up @@ -86,19 +87,56 @@ export class ApmPlugin implements Plugin<ApmPluginSetup, ApmPluginStart> {
pluginSetupDeps.home.featureCatalogue.register(featureCatalogueEntry);
}

// register observability nav
const servicesTitle = i18n.translate('xpack.apm.navigation.servicesTitle', {
defaultMessage: 'Services',
});
const tracesTitle = i18n.translate('xpack.apm.navigation.tracesTitle', {
defaultMessage: 'Traces',
});
const serviceMapTitle = i18n.translate(
'xpack.apm.navigation.serviceMapTitle',
{ defaultMessage: 'Service Map' }
);

// register observability nav if user has access to plugin
plugins.observability.navigation.registerSections(
of([
{
label: 'APM',
sortKey: 200,
entries: [
{ label: 'Services', app: 'apm', path: '/services' },
{ label: 'Traces', app: 'apm', path: '/traces' },
{ label: 'Service Map', app: 'apm', path: '/service-map' },
],
},
])
from(core.getStartServices()).pipe(
map(([coreStart]) => {
if (coreStart.application.capabilities.apm.show) {
return [
// APM navigation
{
label: 'APM',
sortKey: 200,
entries: [
{ label: servicesTitle, app: 'apm', path: '/services' },
{ label: tracesTitle, app: 'apm', path: '/traces' },
{ label: serviceMapTitle, app: 'apm', path: '/service-map' },
],
},

// UX navigation
{
label: 'User Experience',
sortKey: 201,
entries: [
{
label: i18n.translate('xpack.apm.ux.overview.heading', {
defaultMessage: 'Overview',
}),
app: 'ux',
path: '/',
matchFullPath: true,
ignoreTrailingSlash: true,
},
],
},
];
}

return [];
})
)
);

const getApmDataHelper = async () => {
Expand Down Expand Up @@ -150,26 +188,6 @@ export class ApmPlugin implements Plugin<ApmPluginSetup, ApmPluginStart> {
},
});

plugins.observability.navigation.registerSections(
of([
{
label: 'User Experience',
sortKey: 201,
entries: [
{
label: i18n.translate('xpack.apm.ux.overview.heading', {
defaultMessage: 'Overview',
}),
app: 'ux',
path: '/',
matchFullPath: true,
ignoreTrailingSlash: true,
},
],
},
])
);

core.application.register({
id: 'apm',
title: 'APM',
Expand All @@ -178,29 +196,10 @@ export class ApmPlugin implements Plugin<ApmPluginSetup, ApmPluginStart> {
appRoute: '/app/apm',
icon: 'plugins/apm/public/icon.svg',
category: DEFAULT_APP_CATEGORIES.observability,
// !! Need to be kept in sync with the routes in x-pack/plugins/apm/public/components/app/Main/route_config/index.tsx
deepLinks: [
{
id: 'services',
title: i18n.translate('xpack.apm.breadcrumb.servicesTitle', {
defaultMessage: 'Services',
}),
path: '/services',
},
{
id: 'traces',
title: i18n.translate('xpack.apm.breadcrumb.tracesTitle', {
defaultMessage: 'Traces',
}),
path: '/traces',
},
{
id: 'service-map',
title: i18n.translate('xpack.apm.breadcrumb.serviceMapTitle', {
defaultMessage: 'Service Map',
}),
path: '/service-map',
},
{ id: 'services', title: servicesTitle, path: '/services' },
{ id: 'traces', title: tracesTitle, path: '/traces' },
{ id: 'service-map', title: serviceMapTitle, path: '/service-map' },
],

async mount(appMountParameters: AppMountParameters<unknown>) {
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -5396,9 +5396,6 @@
"xpack.apm.apply.label": "適用",
"xpack.apm.applyFilter": "{title} フィルターを適用",
"xpack.apm.applyOptions": "オプションを適用",
"xpack.apm.breadcrumb.serviceMapTitle": "サービスマップ",
"xpack.apm.breadcrumb.servicesTitle": "サービス",
"xpack.apm.breadcrumb.tracesTitle": "トレース",
"xpack.apm.chart.annotation.version": "バージョン",
"xpack.apm.chart.cpuSeries.processAverageLabel": "プロセス平均",
"xpack.apm.chart.cpuSeries.processMaxLabel": "プロセス最大",
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -5425,9 +5425,6 @@
"xpack.apm.apply.label": "应用",
"xpack.apm.applyFilter": "应用 {title} 筛选",
"xpack.apm.applyOptions": "应用选项",
"xpack.apm.breadcrumb.serviceMapTitle": "服务地图",
"xpack.apm.breadcrumb.servicesTitle": "服务",
"xpack.apm.breadcrumb.tracesTitle": "追溯",
"xpack.apm.chart.annotation.version": "版本",
"xpack.apm.chart.cpuSeries.processAverageLabel": "进程平均值",
"xpack.apm.chart.cpuSeries.processMaxLabel": "进程最大值",
Expand Down

0 comments on commit e0fb513

Please sign in to comment.