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

[Infra] Add alerts section to the container views overview #186071

Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 (
<>
Expand All @@ -59,7 +65,7 @@ export const AlertsSummaryContent = ({
initialTriggerValue={collapsibleStatus}
extraAction={
<EuiFlexGroup alignItems="center" responsive={false}>
{featureFlags.inventoryThresholdAlertRuleEnabled && (
{showCreateRuleFeature && (
<EuiFlexItem grow={false}>
<CreateAlertRuleButton
onClick={toggleAlertFlyout}
Expand All @@ -77,9 +83,14 @@ export const AlertsSummaryContent = ({
</EuiFlexGroup>
}
>
<AlertsOverview onLoaded={onLoaded} dateRange={dateRange} assetId={assetId} />
<AlertsOverview
onLoaded={onLoaded}
dateRange={dateRange}
assetId={assetId}
assetType={assetType}
/>
</Section>
{featureFlags.inventoryThresholdAlertRuleEnabled && (
{showCreateRuleFeature && (
<AlertFlyout
filter={`${assetIdField}: "${assetId}"`}
nodeType={assetType}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export const Overview = () => {
error: fetchMetadataError,
} = useMetadataStateContext();
const { metrics } = useDataViewsContext();

const isFullPageView = renderMode.mode === 'page';

const state = useIntersectingState(ref, { dateRange });
Expand All @@ -61,7 +60,7 @@ export const Overview = () => {
{fetchMetadataError && !metadataLoading ? <MetadataErrorCallout /> : metadataSummarySection}
<SectionSeparator />
</EuiFlexItem>
{asset.type === 'host' ? (
{asset.type === 'host' || asset.type === 'container' ? (
<EuiFlexItem grow={false}>
<AlertsSummaryContent
assetId={asset.id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useSummaryTimeRange } from '@kbn/observability-plugin/public';
import { AlertConsumers } from '@kbn/rule-data-utils';
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import { BrushEndListener, XYBrushEvent } from '@elastic/charts';
import type { InventoryItemType } from '@kbn/metrics-data-access-plugin/common';
import { AlertsCount } from '../../../hooks/use_alerts_count';
import { useKibanaContextForPlugin } from '../../../hooks/use_kibana';
import { createAlertsEsQuery } from '../../../utils/filters/create_alerts_es_query';
Expand All @@ -24,6 +25,7 @@ interface AlertsOverviewProps {
dateRange: TimeRange;
onLoaded: (alertsCount?: AlertsCount) => void;
onRangeSelection?: HostsStateUpdater;
assetType?: InventoryItemType;
}

const alertFeatureIds = [...infraAlertFeatureIds, AlertConsumers.OBSERVABILITY];
Expand All @@ -33,6 +35,7 @@ export const AlertsOverview = ({
dateRange,
onLoaded,
onRangeSelection,
assetType,
}: AlertsOverviewProps) => {
const { services } = useKibanaContextForPlugin();
const [urlState, setUrlState] = useAssetDetailsUrlState();
Expand All @@ -56,8 +59,9 @@ export const AlertsOverview = ({
dateRange,
assetIds: [assetId],
status: alertStatus,
assetType,
}),
[assetId, dateRange, alertStatus]
[dateRange, assetId, alertStatus, assetType]
);

const alertsEsQuery = useMemo(
Expand All @@ -66,8 +70,9 @@ export const AlertsOverview = ({
dateRange,
assetIds: [assetId],
status: ALERT_STATUS_ALL,
assetType,
}),
[assetId, dateRange]
[assetId, assetType, dateRange]
);

const summaryTimeRange = useSummaryTimeRange(dateRange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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,
});

Expand Down