-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.x] [Stack Monitoring] Remove 'observability' and 'observabilitySha…
…red' plugin dependencies (#203492) (#204912) # Backport This will backport the following commits from `main` to `8.x`: - [[Stack Monitoring] Remove 'observability' and 'observabilityShared' plugin dependencies (#203492)](#203492) <!--- Backport version: 8.9.8 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Giorgos Bamparopoulos","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-10T16:43:49Z","message":"[Stack Monitoring] Remove 'observability' and 'observabilityShared' plugin dependencies (#203492)\n\n### Summary\r\nA recent [bug](#199902) that\r\naffected some of the pages in Stack Monitoring was caused by changes\r\nrelated to the locators of the logs-related apps.\r\n\r\nThe goal of this PR is to reduce the number of Observability\r\ndependencies that could potentially cause issues in the app by removing\r\nthe `observability` and `observabilityShared` plugin dependencies from\r\nthe `monitoring` plugin.\r\n\r\nCurrently, the `monitoring` plugin is [categorised as\r\nobservability](https://github.com/elastic/kibana/blob/main/x-pack/plugins/monitoring/kibana.jsonc#L7)\r\nbut when the dependency on the `infra` plugin is removed, it can be\r\nmarked as a `platform` plugin.\r\n\r\n### Notes for reviewers\r\n- The components used to render the header menu as well as the\r\n[use_track_metric](https://github.com/elastic/kibana/pull/203492/files#diff-7e39fc60ca80ee551d824ca97f9f879e3364a368a5736cf9178b5943a12ca7a7)\r\nhook were copied from the `observabilityShared` plugin\r\n- There should be no UX and functionality changes in the stack\r\nmonitoring header\r\n- Usage collection could be verified by searching for UI counters sent\r\nby the cluster created for this PR, once telemetry has been sent\r\n\r\n### Testing\r\nThe stateful environment deployed by this PR includes logs and metrics\r\nfor stack monitoring. Please make sure to select a larger time range\r\n(e.g. last 14 days).\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>\r\nCo-authored-by: Elastic Machine <[email protected]>","sha":"7e2f67ebc550167f8b9d678312c69eda1abc921b","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:skip","v9.0.0","ci:project-deploy-observability","Team:obs-ux-management"],"number":203492,"url":"https://github.com/elastic/kibana/pull/203492","mergeCommit":{"message":"[Stack Monitoring] Remove 'observability' and 'observabilityShared' plugin dependencies (#203492)\n\n### Summary\r\nA recent [bug](#199902) that\r\naffected some of the pages in Stack Monitoring was caused by changes\r\nrelated to the locators of the logs-related apps.\r\n\r\nThe goal of this PR is to reduce the number of Observability\r\ndependencies that could potentially cause issues in the app by removing\r\nthe `observability` and `observabilityShared` plugin dependencies from\r\nthe `monitoring` plugin.\r\n\r\nCurrently, the `monitoring` plugin is [categorised as\r\nobservability](https://github.com/elastic/kibana/blob/main/x-pack/plugins/monitoring/kibana.jsonc#L7)\r\nbut when the dependency on the `infra` plugin is removed, it can be\r\nmarked as a `platform` plugin.\r\n\r\n### Notes for reviewers\r\n- The components used to render the header menu as well as the\r\n[use_track_metric](https://github.com/elastic/kibana/pull/203492/files#diff-7e39fc60ca80ee551d824ca97f9f879e3364a368a5736cf9178b5943a12ca7a7)\r\nhook were copied from the `observabilityShared` plugin\r\n- There should be no UX and functionality changes in the stack\r\nmonitoring header\r\n- Usage collection could be verified by searching for UI counters sent\r\nby the cluster created for this PR, once telemetry has been sent\r\n\r\n### Testing\r\nThe stateful environment deployed by this PR includes logs and metrics\r\nfor stack monitoring. Please make sure to select a larger time range\r\n(e.g. last 14 days).\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>\r\nCo-authored-by: Elastic Machine <[email protected]>","sha":"7e2f67ebc550167f8b9d678312c69eda1abc921b"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/203492","number":203492,"mergeCommit":{"message":"[Stack Monitoring] Remove 'observability' and 'observabilityShared' plugin dependencies (#203492)\n\n### Summary\r\nA recent [bug](#199902) that\r\naffected some of the pages in Stack Monitoring was caused by changes\r\nrelated to the locators of the logs-related apps.\r\n\r\nThe goal of this PR is to reduce the number of Observability\r\ndependencies that could potentially cause issues in the app by removing\r\nthe `observability` and `observabilityShared` plugin dependencies from\r\nthe `monitoring` plugin.\r\n\r\nCurrently, the `monitoring` plugin is [categorised as\r\nobservability](https://github.com/elastic/kibana/blob/main/x-pack/plugins/monitoring/kibana.jsonc#L7)\r\nbut when the dependency on the `infra` plugin is removed, it can be\r\nmarked as a `platform` plugin.\r\n\r\n### Notes for reviewers\r\n- The components used to render the header menu as well as the\r\n[use_track_metric](https://github.com/elastic/kibana/pull/203492/files#diff-7e39fc60ca80ee551d824ca97f9f879e3364a368a5736cf9178b5943a12ca7a7)\r\nhook were copied from the `observabilityShared` plugin\r\n- There should be no UX and functionality changes in the stack\r\nmonitoring header\r\n- Usage collection could be verified by searching for UI counters sent\r\nby the cluster created for this PR, once telemetry has been sent\r\n\r\n### Testing\r\nThe stateful environment deployed by this PR includes logs and metrics\r\nfor stack monitoring. Please make sure to select a larger time range\r\n(e.g. last 14 days).\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>\r\nCo-authored-by: Elastic Machine <[email protected]>","sha":"7e2f67ebc550167f8b9d678312c69eda1abc921b"}}]}] BACKPORT-->
- Loading branch information
Showing
15 changed files
with
192 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
x-pack/plugins/monitoring/public/application/hooks/use_track_metric.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* 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 { useEffect, useMemo } from 'react'; | ||
import { METRIC_TYPE, UiCounterMetricType } from '@kbn/analytics'; | ||
import { UsageCollectionSetup } from '@kbn/usage-collection-plugin/public'; | ||
import { useKibana } from '@kbn/kibana-react-plugin/public'; | ||
import { USAGE_COLLECTION_APP_NAME } from '../../../common/constants'; | ||
|
||
/** | ||
* Note: The usage_collection plugin will take care of sending this data to the telemetry server. | ||
* You can find the metrics that are collected by these hooks in Stack Telemetry. | ||
* Search the index `kibana-ui-counter`. You can filter for `eventName` and/or `appName`. | ||
*/ | ||
|
||
interface TrackOptions { | ||
metricType?: UiCounterMetricType; | ||
delay?: number; // in ms | ||
} | ||
type EffectDeps = unknown[]; | ||
|
||
interface ServiceDeps { | ||
usageCollection: UsageCollectionSetup; // TODO: This should really be start. Looking into it. | ||
} | ||
|
||
export type TrackMetricOptions = TrackOptions & { metric: string }; | ||
export type UiTracker = ReturnType<typeof useUiTracker>; | ||
export type TrackEvent = (options: TrackMetricOptions) => void; | ||
|
||
export { METRIC_TYPE }; | ||
|
||
export function useUiTracker<Services extends ServiceDeps>(): TrackEvent { | ||
const reportUiCounter = useKibana<Services>().services?.usageCollection?.reportUiCounter; | ||
const trackEvent = useMemo(() => { | ||
return ({ metric, metricType = METRIC_TYPE.COUNT }: TrackMetricOptions) => { | ||
if (reportUiCounter) { | ||
reportUiCounter(USAGE_COLLECTION_APP_NAME, metricType, metric); | ||
} | ||
}; | ||
}, [reportUiCounter]); | ||
return trackEvent; | ||
} | ||
|
||
export function useTrackMetric<Services extends ServiceDeps>( | ||
{ metric, metricType = METRIC_TYPE.COUNT, delay = 0 }: TrackMetricOptions, | ||
effectDependencies: EffectDeps = [] | ||
) { | ||
const reportUiCounter = useKibana<Services>().services?.usageCollection?.reportUiCounter; | ||
|
||
useEffect(() => { | ||
if (!reportUiCounter) { | ||
// eslint-disable-next-line no-console | ||
console.log( | ||
'usageCollection.reportUiCounter is unavailable. Ensure this is setup via <KibanaContextProvider />.' | ||
); | ||
} else { | ||
let decoratedMetric = metric; | ||
if (delay > 0) { | ||
decoratedMetric += `__delayed_${delay}ms`; | ||
} | ||
const id = setTimeout( | ||
() => reportUiCounter(USAGE_COLLECTION_APP_NAME, metricType, decoratedMetric), | ||
Math.max(delay, 0) | ||
); | ||
return () => clearTimeout(id); | ||
} | ||
// the dependencies are managed externally | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, effectDependencies); | ||
} | ||
|
||
/** | ||
* useTrackPageview is a convenience wrapper for tracking a pageview | ||
* Its metrics will be found at: | ||
* stack_stats.kibana.plugins.ui_metric.{app}.pageview__{path}(__delayed_{n}ms)? | ||
*/ | ||
type TrackPageviewProps = TrackOptions & { path: string }; | ||
|
||
export function useTrackPageview<Services extends ServiceDeps>( | ||
{ path, ...rest }: TrackPageviewProps, | ||
effectDependencies: EffectDeps = [] | ||
) { | ||
useTrackMetric<Services>({ ...rest, metric: `pageview__${path}` }, effectDependencies); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
x-pack/plugins/monitoring/public/components/header_menu/header_menu_portal.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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 { render } from '@testing-library/react'; | ||
import React from 'react'; | ||
import HeaderMenuPortal from './header_menu_portal'; | ||
import { themeServiceMock } from '@kbn/core/public/mocks'; | ||
|
||
describe('HeaderMenuPortal', () => { | ||
describe('when unmounted', () => { | ||
it('calls setHeaderActionMenu with undefined', () => { | ||
const setHeaderActionMenu = jest.fn(); | ||
const theme$ = themeServiceMock.createTheme$(); | ||
|
||
const { unmount } = render( | ||
<HeaderMenuPortal setHeaderActionMenu={setHeaderActionMenu} theme$={theme$}> | ||
test | ||
</HeaderMenuPortal> | ||
); | ||
|
||
unmount(); | ||
|
||
expect(setHeaderActionMenu).toHaveBeenCalledWith(undefined); | ||
}); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
x-pack/plugins/monitoring/public/components/header_menu/header_menu_portal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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 React, { useEffect, useMemo } from 'react'; | ||
import { createHtmlPortalNode, InPortal, OutPortal } from 'react-reverse-portal'; | ||
import { toMountPoint } from '@kbn/kibana-react-plugin/public'; | ||
import type { HeaderMenuPortalProps } from '../../types'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default function HeaderMenuPortal({ | ||
children, | ||
setHeaderActionMenu, | ||
theme$, | ||
}: HeaderMenuPortalProps) { | ||
const portalNode = useMemo(() => createHtmlPortalNode(), []); | ||
|
||
useEffect(() => { | ||
setHeaderActionMenu((element) => { | ||
const mount = toMountPoint(<OutPortal node={portalNode} />, { theme$ }); | ||
return mount(element); | ||
}); | ||
|
||
return () => { | ||
portalNode.unmount(); | ||
setHeaderActionMenu(undefined); | ||
}; | ||
}, [portalNode, setHeaderActionMenu, theme$]); | ||
|
||
return <InPortal node={portalNode}>{children}</InPortal>; | ||
} |
20 changes: 20 additions & 0 deletions
20
x-pack/plugins/monitoring/public/components/header_menu/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* 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 React, { lazy, Suspense } from 'react'; | ||
import { EuiLoadingSpinner } from '@elastic/eui'; | ||
import { HeaderMenuPortalProps } from '../../types'; | ||
|
||
const HeaderMenuPortalLazy = lazy(() => import('./header_menu_portal')); | ||
|
||
export function HeaderMenuPortal(props: HeaderMenuPortalProps) { | ||
return ( | ||
<Suspense fallback={<EuiLoadingSpinner />}> | ||
<HeaderMenuPortalLazy {...props} /> | ||
</Suspense> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters