From b79bafe6426a65e2bdbe8ac275be373f606d64df Mon Sep 17 00:00:00 2001 From: Jenny Date: Tue, 11 Jun 2024 12:08:18 +0200 Subject: [PATCH 1/3] Add alerts section for container views --- .../asset_details/tabs/overview/alerts/alerts.tsx | 7 ++++++- .../components/asset_details/tabs/overview/overview.tsx | 2 +- .../public/components/shared/alerts/alerts_overview.tsx | 9 +++++++-- .../infra/public/utils/filters/create_alerts_es_query.ts | 9 +++++++-- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/observability_solution/infra/public/components/asset_details/tabs/overview/alerts/alerts.tsx b/x-pack/plugins/observability_solution/infra/public/components/asset_details/tabs/overview/alerts/alerts.tsx index f33fa9bca6bdf..101e43623ec41 100644 --- a/x-pack/plugins/observability_solution/infra/public/components/asset_details/tabs/overview/alerts/alerts.tsx +++ b/x-pack/plugins/observability_solution/infra/public/components/asset_details/tabs/overview/alerts/alerts.tsx @@ -77,7 +77,12 @@ export const AlertsSummaryContent = ({ } > - + {featureFlags.inventoryThresholdAlertRuleEnabled && ( { {fetchMetadataError && !metadataLoading ? : metadataSummarySection} - {asset.type === 'host' ? ( + {asset.type === 'host' || asset.type === 'container' ? ( // TODO Check integration void; onRangeSelection?: HostsStateUpdater; + assetType?: InventoryItemType; } const alertFeatureIds = [...infraAlertFeatureIds, AlertConsumers.OBSERVABILITY]; @@ -33,6 +35,7 @@ export const AlertsOverview = ({ dateRange, onLoaded, onRangeSelection, + assetType, }: AlertsOverviewProps) => { const { services } = useKibanaContextForPlugin(); const [urlState, setUrlState] = useAssetDetailsUrlState(); @@ -56,8 +59,9 @@ export const AlertsOverview = ({ dateRange, assetIds: [assetId], status: alertStatus, + assetType, }), - [assetId, dateRange, alertStatus] + [dateRange, assetId, alertStatus, assetType] ); const alertsEsQuery = useMemo( @@ -66,8 +70,9 @@ export const AlertsOverview = ({ dateRange, assetIds: [assetId], status: ALERT_STATUS_ALL, + assetType, }), - [assetId, dateRange] + [assetId, assetType, dateRange] ); const summaryTimeRange = useSummaryTimeRange(dateRange); diff --git a/x-pack/plugins/observability_solution/infra/public/utils/filters/create_alerts_es_query.ts b/x-pack/plugins/observability_solution/infra/public/utils/filters/create_alerts_es_query.ts index e80ac2cdf9ac0..5184151619e67 100644 --- a/x-pack/plugins/observability_solution/infra/public/utils/filters/create_alerts_es_query.ts +++ b/x-pack/plugins/observability_solution/infra/public/utils/filters/create_alerts_es_query.ts @@ -8,7 +8,10 @@ import { getTime } from '@kbn/data-plugin/common'; import { ALERT_TIME_RANGE } from '@kbn/rule-data-utils'; import { BoolQuery, buildEsQuery, Filter, type TimeRange } from '@kbn/es-query'; import type { AlertStatus } from '@kbn/observability-plugin/common/typings'; -import { findInventoryFields } from '@kbn/metrics-data-access-plugin/common'; +import { + findInventoryFields, + type InventoryItemType, +} from '@kbn/metrics-data-access-plugin/common'; import { buildCombinedAssetFilter } from './build'; import { ALERT_STATUS_QUERY } from '../../components/shared/alerts/constants'; @@ -20,16 +23,18 @@ export const createAlertsEsQuery = ({ dateRange, assetIds, status, + assetType, }: { dateRange: TimeRange; assetIds: string[]; status?: AlertStatus; + assetType?: InventoryItemType; }): AlertsEsQuery => { const alertStatusFilter = createAlertStatusFilter(status); const dateFilter = createDateFilter(dateRange); const hostsFilter = buildCombinedAssetFilter({ - field: findInventoryFields('host').id, + field: findInventoryFields(assetType ?? 'host').id, values: assetIds, }); From 3e89e13b0fbdcb28b5b1bc9dddf10a5c489f695b Mon Sep 17 00:00:00 2001 From: Jenny Date: Tue, 11 Jun 2024 17:47:54 +0200 Subject: [PATCH 2/3] Check for docker integration --- .../components/asset_details/tabs/overview/overview.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/observability_solution/infra/public/components/asset_details/tabs/overview/overview.tsx b/x-pack/plugins/observability_solution/infra/public/components/asset_details/tabs/overview/overview.tsx index ccfe00b247f9a..1f4b44fdd3a70 100644 --- a/x-pack/plugins/observability_solution/infra/public/components/asset_details/tabs/overview/overview.tsx +++ b/x-pack/plugins/observability_solution/infra/public/components/asset_details/tabs/overview/overview.tsx @@ -23,6 +23,8 @@ import { useIntersectingState } from '../../hooks/use_intersecting_state'; import { CpuProfilingPrompt } from './kpis/cpu_profiling_prompt'; import { ServicesContent } from './services'; import { MetricsContent } from './metrics/metrics'; +import { useIntegrationCheck } from '../../hooks/use_integration_check'; +import { INTEGRATIONS } from '../../constants'; export const Overview = () => { const ref = useRef(null); @@ -34,6 +36,7 @@ export const Overview = () => { error: fetchMetadataError, } = useMetadataStateContext(); const { metrics } = useDataViewsContext(); + const isDockerContainer = useIntegrationCheck({ dependsOn: INTEGRATIONS.docker }); const isFullPageView = renderMode.mode === 'page'; @@ -61,7 +64,7 @@ export const Overview = () => { {fetchMetadataError && !metadataLoading ? : metadataSummarySection} - {asset.type === 'host' || asset.type === 'container' ? ( // TODO Check integration + {asset.type === 'host' || isDockerContainer ? ( Date: Tue, 11 Jun 2024 18:46:44 +0200 Subject: [PATCH 3/3] Show create rule only for docker containers --- .../asset_details/tabs/overview/alerts/alerts.tsx | 10 ++++++++-- .../asset_details/tabs/overview/overview.tsx | 6 +----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/observability_solution/infra/public/components/asset_details/tabs/overview/alerts/alerts.tsx b/x-pack/plugins/observability_solution/infra/public/components/asset_details/tabs/overview/alerts/alerts.tsx index 101e43623ec41..61c39ad461eee 100644 --- a/x-pack/plugins/observability_solution/infra/public/components/asset_details/tabs/overview/alerts/alerts.tsx +++ b/x-pack/plugins/observability_solution/infra/public/components/asset_details/tabs/overview/alerts/alerts.tsx @@ -21,6 +21,8 @@ import { type AlertsCount } from '../../../../../hooks/use_alerts_count'; import { AlertsOverview } from '../../../../shared/alerts/alerts_overview'; import { CreateAlertRuleButton } from '../../../../shared/alerts/links/create_alert_rule_button'; import { LinkToAlertsPage } from '../../../../shared/alerts/links/link_to_alerts_page'; +import { useIntegrationCheck } from '../../../hooks/use_integration_check'; +import { INTEGRATIONS } from '../../../constants'; export const AlertsSummaryContent = ({ assetId, @@ -47,6 +49,10 @@ export const AlertsSummaryContent = ({ }; const assetIdField = findInventoryFields(assetType).id; + const isDockerContainer = useIntegrationCheck({ dependsOn: INTEGRATIONS.docker }); + const showCreateRuleFeature = + featureFlags.inventoryThresholdAlertRuleEnabled && + (assetType !== 'container' || isDockerContainer); return ( <> @@ -59,7 +65,7 @@ export const AlertsSummaryContent = ({ initialTriggerValue={collapsibleStatus} extraAction={ - {featureFlags.inventoryThresholdAlertRuleEnabled && ( + {showCreateRuleFeature && ( - {featureFlags.inventoryThresholdAlertRuleEnabled && ( + {showCreateRuleFeature && ( { const ref = useRef(null); @@ -36,8 +34,6 @@ export const Overview = () => { error: fetchMetadataError, } = useMetadataStateContext(); const { metrics } = useDataViewsContext(); - const isDockerContainer = useIntegrationCheck({ dependsOn: INTEGRATIONS.docker }); - const isFullPageView = renderMode.mode === 'page'; const state = useIntersectingState(ref, { dateRange }); @@ -64,7 +60,7 @@ export const Overview = () => { {fetchMetadataError && !metadataLoading ? : metadataSummarySection} - {asset.type === 'host' || isDockerContainer ? ( + {asset.type === 'host' || asset.type === 'container' ? (