Skip to content

Commit

Permalink
[APM] Update alert rule producer terms in getServicesAlerts query (el…
Browse files Browse the repository at this point in the history
…astic#203100)

## Summary

This PR continues the work from
elastic#201565.
We missed updating the alert rules in the `getServicesAlerts` function,
so this fixes that.

There's an ongoing
[issue](elastic#202415) to test the
alert counts across solutions and ensure it works as expected in all
scenarios.

---------

Co-authored-by: Cauê Marcondes <[email protected]>
  • Loading branch information
iblancof and cauemarcondes authored Dec 5, 2024
1 parent 6178e82 commit b210a3e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
type ValidFeatureId,
} from '@kbn/rule-data-utils';

export const apmAlertingConsumers: ValidFeatureId[] = [
export const APM_ALERTING_CONSUMERS: ValidFeatureId[] = [
AlertConsumers.LOGS,
AlertConsumers.APM,
AlertConsumers.SLO,
Expand All @@ -20,4 +20,4 @@ export const apmAlertingConsumers: ValidFeatureId[] = [
AlertConsumers.ALERTS,
];

export const apmAlertingRuleTypeIds: string[] = [...OBSERVABILITY_RULE_TYPE_IDS];
export const APM_ALERTING_RULE_TYPE_IDS: string[] = [...OBSERVABILITY_RULE_TYPE_IDS];
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { BoolQuery } from '@kbn/es-query';
import { AlertConsumers } from '@kbn/rule-data-utils';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import {
apmAlertingConsumers,
apmAlertingRuleTypeIds,
APM_ALERTING_CONSUMERS,
APM_ALERTING_RULE_TYPE_IDS,
} from '../../../../common/alerting/config/apm_alerting_feature_ids';
import { ApmPluginStartDeps } from '../../../plugin';
import { useAnyOfApmParams } from '../../../hooks/use_apm_params';
Expand Down Expand Up @@ -111,8 +111,8 @@ export function AlertsOverview() {
alertsTableConfigurationRegistry={alertsTableConfigurationRegistry}
id={'service-overview-alerts'}
configurationId={AlertConsumers.OBSERVABILITY}
ruleTypeIds={apmAlertingRuleTypeIds}
consumers={apmAlertingConsumers}
ruleTypeIds={APM_ALERTING_RULE_TYPE_IDS}
consumers={APM_ALERTING_CONSUMERS}
query={esQuery}
showAlertStatusWithFlapping
cellContext={{ observabilityRuleTypeRegistry }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +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 { apmAlertingRuleTypeIds } from '../../../common/alerting/config/apm_alerting_feature_ids';
import { APM_ALERTING_RULE_TYPE_IDS } 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 @@ -32,7 +32,9 @@ export async function getApmAlertsClient({

const ruleRegistryPluginStart = await plugins.ruleRegistry.start();
const alertsClient = await ruleRegistryPluginStart.getRacClientWithRequest(request);
const apmAlertsIndices = await alertsClient.getAuthorizedAlertsIndices(apmAlertingRuleTypeIds);
const apmAlertsIndices = await alertsClient.getAuthorizedAlertsIndices(
APM_ALERTING_RULE_TYPE_IDS
);

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 @@ -18,7 +18,7 @@ import {
ALERT_STATUS_ACTIVE,
ALERT_UUID,
} from '@kbn/rule-data-utils';
import { observabilityFeatureId } from '@kbn/observability-shared-plugin/common';
import { APM_ALERTING_CONSUMERS } from '../../../../common/alerting/config/apm_alerting_feature_ids';
import { SERVICE_NAME } from '../../../../common/es_fields/apm';
import { ServiceGroup } from '../../../../common/service_groups';
import { ApmAlertsClient } from '../../../lib/helpers/get_apm_alerts_client';
Expand Down Expand Up @@ -58,7 +58,7 @@ export async function getServicesAlerts({
query: {
bool: {
filter: [
...termsQuery(ALERT_RULE_PRODUCER, 'apm', observabilityFeatureId),
...termsQuery(ALERT_RULE_PRODUCER, ...APM_ALERTING_CONSUMERS),
...termQuery(ALERT_STATUS, ALERT_STATUS_ACTIVE),
...rangeQuery(start, end),
...kqlQuery(kuery),
Expand Down

0 comments on commit b210a3e

Please sign in to comment.