Skip to content

Commit

Permalink
[APM] Show all alerts in service views & service inventory for consi…
Browse files Browse the repository at this point in the history
…stency with entity inventory (#202025)

## Summary

Closes #201565

This update ensures that the service inventory and service views display
all alerts grouped by `service.name`, regardless of index pattern. This
provides consistent alert visibility across services.


>[!NOTE]
>The presence of two services with alerts in the "before" state, rather
than one, is not due to any changes made in this PR, but rather because
the alerts stopped being active while doing the screenshots.

Screen|Before|After
-|-|-
Entity inventory|![Screenshot 2024-11-27 at 17 04
01](https://github.com/user-attachments/assets/5ec7aa5a-0872-43bb-b4ae-1dcc68ce8e34)|![Screenshot
2024-11-27 at 17 13
58](https://github.com/user-attachments/assets/382ce562-d81b-4cc9-8869-8cf88597b231)
Service inventory|![Screenshot 2024-11-27 at 17 04
54](https://github.com/user-attachments/assets/6a4ff0b0-839f-4004-b240-13e8ccd804a3)|![Screenshot
2024-11-27 at 17 14
14](https://github.com/user-attachments/assets/62a28c6b-be3e-4ff2-bb95-29bc747db83e)
Service detail overview|![Screenshot 2024-11-27 at 17 04
34](https://github.com/user-attachments/assets/53129b4b-cdc6-4bb1-849a-401b82c57327)|![Screenshot
2024-11-27 at 17 05
27](https://github.com/user-attachments/assets/17ee297f-7b6a-46f1-bf98-b38593fa2abe)
Service detail alerts|![Screenshot 2024-11-27 at 17 04
45](https://github.com/user-attachments/assets/ae4ff74e-7d14-48cf-b1f0-76cc3f9e9e1c)|![Screenshot
2024-11-27 at 17 05
49](https://github.com/user-attachments/assets/507d7d6c-0ac8-455b-8aa6-c0ce8f1c756c)
  • Loading branch information
iblancof authored Nov 29, 2024
1 parent 1749c88 commit 8084bd6
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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 { AlertConsumers, type ValidFeatureId } from '@kbn/rule-data-utils';

export const apmAlertingFeatureIds: ValidFeatureId[] = [
AlertConsumers.LOGS,
AlertConsumers.APM,
AlertConsumers.SLO,
AlertConsumers.OBSERVABILITY,
AlertConsumers.INFRASTRUCTURE,
];
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { EuiPanel, EuiFlexItem, EuiFlexGroup } from '@elastic/eui';
import { BoolQuery } from '@kbn/es-query';
import { AlertConsumers } from '@kbn/rule-data-utils';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { apmAlertingFeatureIds } from '../../../../common/alerting/config/apm_alerting_feature_ids';
import { ApmPluginStartDeps } from '../../../plugin';
import { useAnyOfApmParams } from '../../../hooks/use_apm_params';
import { SERVICE_NAME } from '../../../../common/es_fields/apm';
Expand Down Expand Up @@ -107,7 +108,7 @@ export function AlertsOverview() {
alertsTableConfigurationRegistry={alertsTableConfigurationRegistry}
id={'service-overview-alerts'}
configurationId={AlertConsumers.OBSERVABILITY}
featureIds={[AlertConsumers.APM, AlertConsumers.OBSERVABILITY]}
featureIds={apmAlertingFeatureIds}
query={esQuery}
showAlertStatusWithFlapping
cellContext={{ observabilityRuleTypeRegistry }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { DataTier } from '@kbn/observability-shared-plugin/common';
import { searchExcludedDataTiers } from '@kbn/observability-plugin/common/ui_settings_keys';
import { estypes } from '@elastic/elasticsearch';
import { getDataTierFilterCombined } from '@kbn/apm-data-access-plugin/server/utils';
import { apmAlertingFeatureIds } from '../../../common/alerting/config/apm_alerting_feature_ids';
import type { MinimalAPMRouteHandlerResources } from '../../routes/apm_routes/register_apm_server_routes';

export type ApmAlertsClient = Awaited<ReturnType<typeof getApmAlertsClient>>;
Expand All @@ -31,7 +32,7 @@ export async function getApmAlertsClient({

const ruleRegistryPluginStart = await plugins.ruleRegistry.start();
const alertsClient = await ruleRegistryPluginStart.getRacClientWithRequest(request);
const apmAlertsIndices = await alertsClient.getAuthorizedAlertsIndices(['apm']);
const apmAlertsIndices = await alertsClient.getAuthorizedAlertsIndices(apmAlertingFeatureIds);

if (!apmAlertsIndices || isEmpty(apmAlertsIndices)) {
throw Error('No alert indices exist for "apm"');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ describe('useDetailViewRedirect', () => {
expect(url).toBe('service-overview-url');
expect(mockGetRedirectUrl).toHaveBeenCalledWith({
serviceName: 'service-1',
environment: 'prod',
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ export const useDetailViewRedirect = () => {
if (isBuiltinEntityOfType('service', entity)) {
return serviceOverviewLocator?.getRedirectUrl({
serviceName: identityFieldsValue[identityFields[0]],
environment: entity.service?.environment
? castArray(entity.service?.environment)[0]
: undefined,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { termQuery } from '@kbn/observability-plugin/server';
import { ALERT_STATUS, ALERT_STATUS_ACTIVE } from '@kbn/rule-data-utils';
import { AlertsClient } from '../../lib/create_alerts_client.ts/create_alerts_client';
import { AlertsClient } from '../../lib/create_alerts_client/create_alerts_client';
import { getGroupByTermsAgg } from './get_group_by_terms_agg';
import { IdentityFieldsPerEntityType } from './get_identity_fields_per_entity_type';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { createObservabilityEsClient } from '@kbn/observability-utils-server/es/
import * as t from 'io-ts';
import { orderBy } from 'lodash';
import { InventoryEntity, entityColumnIdsRt } from '../../../common/entities';
import { createAlertsClient } from '../../lib/create_alerts_client.ts/create_alerts_client';
import { createAlertsClient } from '../../lib/create_alerts_client/create_alerts_client';
import { createInventoryServerRoute } from '../create_inventory_server_route';
import { getEntityGroupsBy } from './get_entity_groups';
import { getEntityTypes } from './get_entity_types';
Expand Down

0 comments on commit 8084bd6

Please sign in to comment.