Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export type ManagementId =
| 'action_policies'
| 'execution_history'
| 'rules'
| 'rule_library'
| 'triggersActions'
| 'triggersActionsAlerts'
| 'triggersActionsConnectors'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export const AGENT_BUILDER_TRACING_USER_DATA_SETTING_ID = 'agentBuilder:tracing:

// Alerting settings
export const ALERTING_V2_ENABLED_SETTING_ID = 'alerting:v2:enabled';
export const ALERTING_V2_SHOW_CLASSIC_ALERTS_TABLE_SETTING_ID =
'alerting:v2:showClassicAlertsTable';

// Context engine settings
export const CONTEXT_ENGINE_ENABLED_SETTING_ID = 'contextEngine:enabled';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {

export const OBSERVABILITY_PROJECT_SETTINGS = [
settings.ALERTING_V2_ENABLED_SETTING_ID,
settings.ALERTING_V2_SHOW_CLASSIC_ALERTS_TABLE_SETTING_ID,
settings.DEFAULT_ROUTE_ID,
settings.OBSERVABILITY_ENABLE_COMPARISON_BY_DEFAULT_ID,
settings.OBSERVABILITY_APM_DEFAULT_SERVICE_ENVIRONMENT_ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

export const ALERTING_V2_ENABLED_SETTING_ID = 'alerting:v2:enabled';

/**
* Space-scoped. When Alerting v2 is enabled, controls whether the classic
* Observability alerts table remains in solution navigation.
*/
export const ALERTING_V2_SHOW_CLASSIC_ALERTS_TABLE_SETTING_ID =
'alerting:v2:showClassicAlertsTable';

export interface AlertingAdvancedSettingValueMap {
[ALERTING_V2_ENABLED_SETTING_ID]: boolean;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export { getAlertingV2ManagementNavPanel } from './get_management_nav_panel';
export {
isAlertingV2Enabled,
shouldShowAlertingV2CreateRuleFlyout,
shouldShowClassicObservabilityAlertsTable,
} from './is_alerting_v2_enabled';

export { normalizeTags } from './normalize_tags';
export { resolveArtifactId } from './resolve_artifact_id';
export { resolveTimeField, type ResolveTimeFieldParams } from './time_field';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { coreMock } from '@kbn/core/public/mocks';
import {
isAlertingV2Enabled,
shouldShowAlertingV2CreateRuleFlyout,
shouldShowClassicObservabilityAlertsTable,
} from './is_alerting_v2_enabled';

describe('isAlertingV2Enabled', () => {
Expand Down Expand Up @@ -87,3 +88,37 @@ describe('shouldShowAlertingV2CreateRuleFlyout', () => {
expect(shouldShowAlertingV2CreateRuleFlyout(core)).toBe(false);
});
});

describe('shouldShowClassicObservabilityAlertsTable', () => {
let core: CoreStart;

beforeEach(() => {
core = coreMock.createStart();
core.settings.globalClient.get = <T>(_key: string) => false as T;
core.settings.client.get = <T>(_key: string) => false as T;
});

it('returns true when alerting v2 is disabled', () => {
expect(shouldShowClassicObservabilityAlertsTable(core)).toBe(true);
});

it('returns false when alerting v2 is enabled and the space setting is off', () => {
core.settings.globalClient.get = <T>(_key: string) => true as T;

expect(shouldShowClassicObservabilityAlertsTable(core)).toBe(false);
});

it('returns true when alerting v2 is enabled and the space setting is on', () => {
core.settings.globalClient.get = <T>(_key: string) => true as T;
core.settings.client.get = <T>(_key: string) => true as T;

expect(shouldShowClassicObservabilityAlertsTable(core)).toBe(true);
});

it('returns false when alerting v2 is enabled and the space setting is unset', () => {
core.settings.globalClient.get = <T>(_key: string) => true as T;
core.settings.client.get = <T>(_key: string) => undefined as T;

expect(shouldShowClassicObservabilityAlertsTable(core)).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
*/

import type { CoreStart } from '@kbn/core-lifecycle-browser';
import { ALERTING_V2_ENABLED_SETTING_ID } from '@kbn/alerting-v2-constants';
import {
ALERTING_V2_ENABLED_SETTING_ID,
ALERTING_V2_SHOW_CLASSIC_ALERTS_TABLE_SETTING_ID,
} from '@kbn/alerting-v2-constants';

/** Feature id from `@kbn/alerting-v2-plugin/common/feature_privileges`. */
const ALERTING_V2_RULES_FEATURE_ID = 'alerting_v2_rules';
Expand Down Expand Up @@ -46,3 +49,21 @@ export const isAlertingV2Enabled = (core: CoreStart): boolean => {
export const shouldShowAlertingV2CreateRuleFlyout = (core: CoreStart): boolean => {
return isAlertingV2Enabled(core) && hasAlertingV2RulesWriteCapability(core);
};

/**
* Returns whether the classic Observability alerts table should appear in
* solution navigation.
*
* Always shown while Alerting v2 is disabled. When v2 is enabled, shown only
* if the space-scoped `alerting:v2:showClassicAlertsTable` setting is true.
*/
export const shouldShowClassicObservabilityAlertsTable = (core: CoreStart): boolean => {
if (!isAlertingV2Enabled(core)) {
return true;
}

return (
core.settings.client.get<boolean>(ALERTING_V2_SHOW_CLASSIC_ALERTS_TABLE_SETTING_ID, false) ===
true
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { i18n } from '@kbn/i18n';
import type { UiSettingsParams } from '@kbn/core/types';
import {
ALERTING_V2_ENABLED_SETTING_ID,
ALERTING_V2_SHOW_CLASSIC_ALERTS_TABLE_SETTING_ID,
type AlertingAdvancedSettingId,
type AlertingAdvancedSettingValueMap,
} from '@kbn/alerting-v2-constants';
Expand Down Expand Up @@ -43,3 +44,25 @@ export const alertingAdvancedSettings = {
experimental: true,
},
} satisfies AlertingV2AdvancedSettingsRegistration;

/**
* Space-scoped settings. Registered via `uiSettings.register` (not
* `registerGlobal`) so each Kibana space can opt in independently.
*/
export const alertingSpaceAdvancedSettings: Record<string, UiSettingsParams<boolean>> = {
[ALERTING_V2_SHOW_CLASSIC_ALERTS_TABLE_SETTING_ID]: {
category: [ALERTING_V2_CATEGORY],
name: i18n.translate('xpack.alertingVTwo.showClassicAlertsTableSettingName', {
defaultMessage: 'Show classic alerts table',
}),
type: 'boolean',
value: false,
description: i18n.translate('xpack.alertingVTwo.showClassicAlertsTableSettingDescription', {
defaultMessage:
'Show the classic Observability alerts table in navigation. Only displays alerts from v1 alerting rules.',
}),
schema: schema.boolean(),
requiresPageReload: true,
experimental: true,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ import {
ACTION_POLICY_EVENT_ACTIONS,
ACTION_POLICY_EVENT_PROVIDER,
} from '../lib/dispatcher/steps/constants';
import { alertingAdvancedSettings } from '../settings/advanced_settings';
import {
alertingAdvancedSettings,
alertingSpaceAdvancedSettings,
} from '../settings/advanced_settings';

/**
* Core platform setup-phase registrations (feature privileges, saved objects,
Expand Down Expand Up @@ -56,6 +59,7 @@ export function bindOnSetup({ bind }: ContainerModuleLoadOptions) {
const uiSettingsSetup = container.get(CoreSetup('uiSettings'));

uiSettingsSetup.registerGlobal(alertingAdvancedSettings);
uiSettingsSetup.register(alertingSpaceAdvancedSettings);

const eventLogService = container.get(
PluginSetup<AlertingServerSetupDependencies['eventLog']>('eventLog')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class ObservabilityNavigation {

/** `goto*` does not call `waitForLoad()` — sidenav may be absent (e.g. classic chrome); call `waitForLoad()` when interacting with nav. */
async goto() {
await this.page.gotoApp('observability');
await this.page.gotoApp('observability/overview');
}

async gotoLanding() {
Expand Down Expand Up @@ -105,6 +105,14 @@ export class ObservabilityNavigation {
return this.sidenav.locator(`[data-test-subj~="nav-item-deepLinkId-${deepLinkId}"]`);
}

/**
* In-app Observability solution sidenav item (classic chrome only).
* Hidden when chrome style is `project` — use the chrome nav helpers there.
*/
classicSidebarNavItem(appId: string, navId: string): Locator {
return this.page.testSubj.locator(`observability-nav-${appId}-${navId}`);
}

navItemInSidenavById(id: string): Locator {
return this.sidenav.locator(`[data-test-subj~="nav-item-id-${id}"]`);
}
Expand All @@ -126,6 +134,14 @@ export class ObservabilityNavigation {
return this.page.testSubj.locator(`~kbnChromeNav-sidePanel_${id}`);
}

navItemInPanelByDeepLinkId(panelId: string, deepLinkId: string): Locator {
return this.sidePanel(panelId).locator(`[data-test-subj~="nav-item-deepLinkId-${deepLinkId}"]`);
}

navItemInPanelById(panelId: string, id: string): Locator {
return this.sidePanel(panelId).locator(`[data-test-subj~="nav-item-id-${id}"]`);
}

nestedPanel(id: string): Locator {
return this.morePopover.locator(`[data-test-subj="kbnChromeNav-nestedPanel-${id}"]`);
}
Expand Down
2 changes: 2 additions & 0 deletions x-pack/solutions/observability/plugins/observability/moon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ dependsOn:
- '@kbn/ai-assistant-common'
- '@kbn/management-settings-ids'
- '@kbn/alerting-v2-utils'
- '@kbn/alerting-v2-constants'
- '@kbn/deeplinks-workflows'
- '@kbn/deeplinks-evals'
- '@kbn/observability-agent-builder-plugin'
Expand All @@ -169,6 +170,7 @@ dependsOn:
- '@kbn/app-header'
- '@kbn/core-chrome-app-menu-components'
- '@kbn/global-search-plugin'
- '@kbn/core-lifecycle-browser'
tags:
- plugin
- prod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export { getCoreVitalsComponent } from './pages/overview/components/sections/ux/
export { ObservabilityAlertSearchBar } from './components/alert_search_bar/get_alert_search_bar_lazy';
export { DatePicker } from './pages/overview/components/date_picker';
export { NightshiftNavigationIcon } from '@kbn/observability-shared-plugin/public';
export { getAlertsNavPanel } from './nav/get_alerts_nav_panel';

export type {
Stat,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { Location } from 'history';
import type { RootNodeDefinition } from '@kbn/core-chrome-browser';
import { coreMock } from '@kbn/core/public/mocks';
import { getAlertsNavPanel } from './get_alerts_nav_panel';

const location = { pathname: '', search: '', hash: '', state: undefined } as Location;
const prepend = (path: string) => path;
const prependWithBasePath = (path: string) => `/s/oblt${path}`;

const isActive = (
getIsActive: RootNodeDefinition['getIsActive'],
pathNameSerialized: string,
pathPrepend: (path: string) => string = prepend
): boolean => {
if (!getIsActive) {
throw new Error('expected getIsActive');
}

return getIsActive({ pathNameSerialized, location, prepend: pathPrepend });
};

describe('getAlertsNavPanel', () => {
it('preserves serverless startsWith active matching on the plain Alerts link', () => {
const core = coreMock.createStart();
core.settings.globalClient.get = <T>(_key: string) => false as T;

const [alertsLink] = getAlertsNavPanel(core);

expect(alertsLink.getIsActive).toEqual(expect.any(Function));
expect(isActive(alertsLink.getIsActive, '/app/observability/alerts')).toBe(true);
expect(isActive(alertsLink.getIsActive, '/app/observability/alerts/abc-123')).toBe(true);
expect(
isActive(
alertsLink.getIsActive,
'/s/oblt/app/observability/alerts/abc-123',
prependWithBasePath
)
).toBe(true);
expect(isActive(alertsLink.getIsActive, '/app/discover')).toBe(false);
expect(isActive(alertsLink.getIsActive, '/app/observability/overview')).toBe(false);
});

it('uses the same active matcher on the v2 panel opener', () => {
const core = coreMock.createStart();
core.settings.globalClient.get = <T>(_key: string) => true as T;

const [alertsPanel] = getAlertsNavPanel(core);

expect(alertsPanel.getIsActive).toEqual(expect.any(Function));
expect(isActive(alertsPanel.getIsActive, '/app/observability/alerts')).toBe(true);
expect(isActive(alertsPanel.getIsActive, '/app/observability/alerts/abc-123')).toBe(true);
expect(isActive(alertsPanel.getIsActive, '/app/discover')).toBe(false);
});
});
Loading
Loading