Skip to content

Commit

Permalink
Adding callback for rule path
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-buttner committed Nov 14, 2022
1 parent d7edbb8 commit 5abc417
Show file tree
Hide file tree
Showing 36 changed files with 129 additions and 17 deletions.
3 changes: 3 additions & 0 deletions packages/kbn-rule-data-utils/src/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ export const ruleDetailsRoute = '/rule/:ruleId';
export const triggersActionsRoute = '/app/management/insightsAndAlerting/triggersActions';

export const getRuleDetailsRoute = (ruleId: string) => ruleDetailsRoute.replace(':ruleId', ruleId);
export const getManagementRuleDetailsFullPath = (id: string): string => {
return `${triggersActionsRoute}${getRuleDetailsRoute(id)}`;
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import uuid from 'uuid';
import { range } from 'lodash';
import { RuleType } from '@kbn/alerting-plugin/server';
import { getManagementRuleDetailsFullPath } from '@kbn/rule-data-utils';
import {
DEFAULT_INSTANCES_TO_GENERATE,
ALERTING_EXAMPLE_APP_ID,
Expand Down Expand Up @@ -76,4 +77,5 @@ export const alertType: RuleType<
};
},
producer: ALERTING_EXAMPLE_APP_ID,
getRulePagePath: getManagementRuleDetailsFullPath,
};
2 changes: 2 additions & 0 deletions x-pack/examples/alerting_example/server/alert_types/astros.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import axios from 'axios';
import { RuleType } from '@kbn/alerting-plugin/server';
import { getManagementRuleDetailsFullPath } from '@kbn/rule-data-utils';
import { Operator, Craft, ALERTING_EXAMPLE_APP_ID } from '../../common/constants';

interface PeopleInSpace {
Expand Down Expand Up @@ -79,4 +80,5 @@ export const alertType: RuleType<
};
},
producer: ALERTING_EXAMPLE_APP_ID,
getRulePagePath: getManagementRuleDetailsFullPath,
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import type { PublicMethodsOf } from '@kbn/utility-types';
import { Logger } from '@kbn/core/server';
import { getRuleDetailsRoute, triggersActionsRoute } from '@kbn/rule-data-utils';
import { asSavedObjectExecutionSource } from '@kbn/actions-plugin/server';
import { isEphemeralTaskRejectedDueToCapacityError } from '@kbn/task-manager-plugin/server';
import { ExecuteOptions as EnqueueExecutionOptions } from '@kbn/actions-plugin/server/create_execute_function';
Expand Down Expand Up @@ -291,7 +290,7 @@ export class ExecutionHandler<

try {
const ruleUrl = new URL(
`${triggersActionsRoute}${getRuleDetailsRoute(this.taskInstance.params.alertId)}`,
this.ruleType.getRulePagePath(this.taskInstance.params.alertId),
this.taskRunnerContext.kibanaBaseUrl
);

Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/alerting/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export interface RuleType<
cancelAlertsOnRuleTimeout?: boolean;
doesSetRecoveryContext?: boolean;
getSummarizedAlerts?: GetSummarizedAlertsFn;
getRulePagePath: (id: string) => string;
}
export type UntypedRuleType = RuleType<
RuleTypeParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { KibanaRequest } from '@kbn/core/server';
import { termQuery } from '@kbn/observability-plugin/server';
import { createLifecycleRuleTypeFactory } from '@kbn/rule-registry-plugin/server';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { getObservabilityRuleDetailsFullPath } from '@kbn/observability-plugin/common/utils/paths';
import {
ApmRuleType,
RULE_TYPES_CONFIG,
Expand Down Expand Up @@ -319,6 +320,7 @@ export function registerAnomalyRuleType({

return {};
},
getRulePagePath: getObservabilityRuleDetailsFullPath,
})
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import { createLifecycleRuleTypeFactory } from '@kbn/rule-registry-plugin/server';
import { termQuery } from '@kbn/observability-plugin/server';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { getObservabilityRuleDetailsFullPath } from '@kbn/observability-plugin/common/utils/paths';
import {
ENVIRONMENT_NOT_DEFINED,
getEnvironmentEsField,
Expand Down Expand Up @@ -206,6 +207,7 @@ export function registerErrorCountRuleType({

return {};
},
getRulePagePath: getObservabilityRuleDetailsFullPath,
})
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { asDuration } from '@kbn/observability-plugin/common/utils/formatters';
import { termQuery } from '@kbn/observability-plugin/server';
import { createLifecycleRuleTypeFactory } from '@kbn/rule-registry-plugin/server';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { getObservabilityRuleDetailsFullPath } from '@kbn/observability-plugin/common/utils/paths';
import { getAlertUrlTransaction } from '../../../../../common/utils/formatters';
import { SearchAggregatedTransactionSetting } from '../../../../../common/aggregated_transactions';
import {
Expand Down Expand Up @@ -279,6 +280,7 @@ export function registerTransactionDurationRuleType({

return {};
},
getRulePagePath: getObservabilityRuleDetailsFullPath,
});

alerting.registerType(ruleType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { createLifecycleRuleTypeFactory } from '@kbn/rule-registry-plugin/server
import { asPercent } from '@kbn/observability-plugin/common/utils/formatters';
import { termQuery } from '@kbn/observability-plugin/server';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { getObservabilityRuleDetailsFullPath } from '@kbn/observability-plugin/common/utils/paths';
import {
ENVIRONMENT_NOT_DEFINED,
getEnvironmentEsField,
Expand Down Expand Up @@ -274,6 +275,7 @@ export function registerTransactionErrorRateRuleType({

return {};
},
getRulePagePath: getObservabilityRuleDetailsFullPath,
})
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { i18n } from '@kbn/i18n';
import { PluginSetupContract } from '@kbn/alerting-plugin/server';
import { getObservabilityRuleDetailsFullPath } from '@kbn/observability-plugin/common/utils/paths';
import { createLogThresholdExecutor, FIRED_ACTIONS } from './log_threshold_executor';
import {
LOG_DOCUMENT_COUNT_RULE_TYPE_ID,
Expand Down Expand Up @@ -142,5 +143,6 @@ export async function registerLogThresholdRuleType(
},
producer: 'logs',
getSummarizedAlerts: libs.logsRules.createGetSummarizedAlerts(),
getRulePagePath: getObservabilityRuleDetailsFullPath,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
AlertInstanceContext as AlertContext,
} from '@kbn/alerting-plugin/server';
import { RecoveredActionGroupId } from '@kbn/alerting-plugin/common';
import { getObservabilityRuleDetailsFullPath } from '@kbn/observability-plugin/common/utils/paths';
import {
createMetricAnomalyExecutor,
FIRED_ACTIONS,
Expand Down Expand Up @@ -114,4 +115,5 @@ export const registerMetricAnomalyRuleType = (
},
],
},
getRulePagePath: getObservabilityRuleDetailsFullPath,
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { schema } from '@kbn/config-schema';
import { i18n } from '@kbn/i18n';
import { ActionGroupIdsOf } from '@kbn/alerting-plugin/common';
import { PluginSetupContract, RuleType } from '@kbn/alerting-plugin/server';
import { getObservabilityRuleDetailsFullPath } from '@kbn/observability-plugin/common/utils/paths';
import { Comparator, METRIC_THRESHOLD_ALERT_TYPE_ID } from '../../../../common/alerting/metrics';
import { METRIC_EXPLORER_AGGREGATIONS } from '../../../../common/http_api';
import { InfraBackendLibs } from '../../infra_types';
Expand Down Expand Up @@ -126,5 +127,6 @@ export async function registerMetricThresholdRuleType(
},
producer: 'infrastructure',
getSummarizedAlerts: libs.metricsRules.createGetSummarizedAlerts(),
getRulePagePath: getObservabilityRuleDetailsFullPath,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
AlertInstanceState,
RuleTypeState,
} from '@kbn/alerting-plugin/common';
import { getManagementRuleDetailsFullPath } from '@kbn/rule-registry-plugin/common/technical_rule_data_field_names';
import { ML_ALERT_TYPES } from '../../../common/constants/alerts';
import { PLUGIN_ID } from '../../../common/constants/app';
import { MINIMUM_FULL_LICENSE } from '../../../common/license';
Expand Down Expand Up @@ -159,5 +160,6 @@ export function registerAnomalyDetectionAlertType({
}
}
},
getRulePagePath: getManagementRuleDetailsFullPath,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
RuleTypeState,
} from '@kbn/alerting-plugin/common';
import type { RuleExecutorOptions } from '@kbn/alerting-plugin/server';
import { getManagementRuleDetailsFullPath } from '@kbn/rule-data-utils';
import { ML_ALERT_TYPES } from '../../../common/constants/alerts';
import { PLUGIN_ID } from '../../../common/constants/app';
import { MINIMUM_FULL_LICENSE } from '../../../common/license';
Expand Down Expand Up @@ -180,5 +181,6 @@ export function registerJobsMonitoringRuleType({
}
}
},
getRulePagePath: getManagementRuleDetailsFullPath,
});
}
2 changes: 2 additions & 0 deletions x-pack/plugins/monitoring/server/alerts/base_rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import { Rule, RuleTypeParams, RawAlertInstance, SanitizedRule } from '@kbn/alerting-plugin/common';
import { ActionsClient } from '@kbn/actions-plugin/server';
import { parseDuration } from '@kbn/alerting-plugin/common';
import { getObservabilityRuleDetailsFullPath } from '@kbn/observability-plugin/common/utils/paths';
import {
AlertState,
AlertNodeState,
Expand Down Expand Up @@ -102,6 +103,7 @@ export class BaseRule {
actionVariables: {
context: actionVariables,
},
getRulePagePath: getObservabilityRuleDetailsFullPath,
};
}

Expand Down
11 changes: 11 additions & 0 deletions x-pack/plugins/observability/common/utils/paths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* 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.
*/

export const observabilityRuleDetailsRoute = '/app/observability/alerts/rules/:ruleId';

export const getObservabilityRuleDetailsFullPath = (id: string): string =>
observabilityRuleDetailsRoute.replace(':ruleId', id);
2 changes: 2 additions & 0 deletions x-pack/plugins/security_solution/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export const DETECTION_RESPONSE_PATH = '/detection_response' as const;
export const DETECTIONS_PATH = '/detections' as const;
export const ALERTS_PATH = '/alerts' as const;
export const RULES_PATH = '/rules' as const;
export const RULE_DETAILS_PATH = `${RULES_PATH}/id` as const;
export const RULES_CREATE_PATH = `${RULES_PATH}/create` as const;
export const EXCEPTIONS_PATH = '/exceptions' as const;
export const HOSTS_PATH = '/hosts' as const;
Expand All @@ -171,6 +172,7 @@ export const APP_MANAGEMENT_PATH = `${APP_PATH}${MANAGEMENT_PATH}` as const;

export const APP_ALERTS_PATH = `${APP_PATH}${ALERTS_PATH}` as const;
export const APP_RULES_PATH = `${APP_PATH}${RULES_PATH}` as const;
export const APP_RULE_DETAILS_PATH = `${APP_PATH}${RULE_DETAILS_PATH}` as const;
export const APP_EXCEPTIONS_PATH = `${APP_PATH}${EXCEPTIONS_PATH}` as const;

export const APP_HOSTS_PATH = `${APP_PATH}${HOSTS_PATH}` as const;
Expand Down
12 changes: 12 additions & 0 deletions x-pack/plugins/security_solution/common/utils/paths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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 { APP_RULE_DETAILS_PATH } from '../constants';

export const getSecuritySolutionRuleDetailsFullPath = (id: string): string => {
return `${APP_RULE_DETAILS_PATH}/${id}`;
};
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import {
APP_UI_ID,
DEFAULT_INDEX_KEY,
DEFAULT_THREAT_INDEX_KEY,
RULE_DETAILS_PATH,
} from '../../../../../common/constants';
import { useGlobalFullScreen } from '../../../../common/containers/use_full_screen';
import { Display } from '../../../../hosts/pages/display';
Expand Down Expand Up @@ -251,31 +252,31 @@ const RuleDetailsPageComponent: React.FC<DetectionEngineComponentProps> = ({
id: RuleDetailTabs.alerts,
name: RULE_DETAILS_TAB_NAME[RuleDetailTabs.alerts],
disabled: false,
href: `/rules/id/${ruleId}/${RuleDetailTabs.alerts}`,
href: `${RULE_DETAILS_PATH}/${ruleId}/${RuleDetailTabs.alerts}`,
},
[RuleDetailTabs.exceptions]: {
id: RuleDetailTabs.exceptions,
name: RULE_DETAILS_TAB_NAME[RuleDetailTabs.exceptions],
disabled: rule == null,
href: `/rules/id/${ruleId}/${RuleDetailTabs.exceptions}`,
href: `${RULE_DETAILS_PATH}/${ruleId}/${RuleDetailTabs.exceptions}`,
},
[RuleDetailTabs.endpointExceptions]: {
id: RuleDetailTabs.endpointExceptions,
name: RULE_DETAILS_TAB_NAME[RuleDetailTabs.endpointExceptions],
disabled: rule == null,
href: `/rules/id/${ruleId}/${RuleDetailTabs.endpointExceptions}`,
href: `${RULE_DETAILS_PATH}/${ruleId}/${RuleDetailTabs.endpointExceptions}`,
},
[RuleDetailTabs.executionResults]: {
id: RuleDetailTabs.executionResults,
name: RULE_DETAILS_TAB_NAME[RuleDetailTabs.executionResults],
disabled: !isExistingRule,
href: `/rules/id/${ruleId}/${RuleDetailTabs.executionResults}`,
href: `${RULE_DETAILS_PATH}/${ruleId}/${RuleDetailTabs.executionResults}`,
},
[RuleDetailTabs.executionEvents]: {
id: RuleDetailTabs.executionEvents,
name: RULE_DETAILS_TAB_NAME[RuleDetailTabs.executionEvents],
disabled: !isExistingRule,
href: `/rules/id/${ruleId}/${RuleDetailTabs.executionEvents}`,
href: `${RULE_DETAILS_PATH}/${ruleId}/${RuleDetailTabs.executionEvents}`,
},
}),
[isExistingRule, rule, ruleId]
Expand Down Expand Up @@ -800,7 +801,7 @@ const RuleDetailsPageComponent: React.FC<DetectionEngineComponentProps> = ({
</Display>
<StyledMinHeightTabContainer>
<Switch>
<Route path={`/rules/id/:detailName/:tabName(${RuleDetailTabs.alerts})`}>
<Route path={`${RULE_DETAILS_PATH}/:detailName/:tabName(${RuleDetailTabs.alerts})`}>
<>
<EuiFlexGroup alignItems="center" justifyContent="spaceBetween">
<EuiFlexItem grow={false}>
Expand Down Expand Up @@ -850,7 +851,9 @@ const RuleDetailsPageComponent: React.FC<DetectionEngineComponentProps> = ({
)}
</>
</Route>
<Route path={`/rules/id/:detailName/:tabName(${RuleDetailTabs.exceptions})`}>
<Route
path={`${RULE_DETAILS_PATH}/:detailName/:tabName(${RuleDetailTabs.exceptions})`}
>
<ExceptionsViewer
rule={rule}
listTypes={[
Expand All @@ -863,7 +866,7 @@ const RuleDetailsPageComponent: React.FC<DetectionEngineComponentProps> = ({
/>
</Route>
<Route
path={`/rules/id/:detailName/:tabName(${RuleDetailTabs.endpointExceptions})`}
path={`${RULE_DETAILS_PATH}/:detailName/:tabName(${RuleDetailTabs.endpointExceptions})`}
>
<ExceptionsViewer
rule={rule}
Expand All @@ -873,10 +876,14 @@ const RuleDetailsPageComponent: React.FC<DetectionEngineComponentProps> = ({
data-test-subj="endpointExceptionsTab"
/>
</Route>
<Route path={`/rules/id/:detailName/:tabName(${RuleDetailTabs.executionResults})`}>
<Route
path={`${RULE_DETAILS_PATH}/:detailName/:tabName(${RuleDetailTabs.executionResults})`}
>
<ExecutionLogTable ruleId={ruleId} selectAlertsTab={navigateToAlertsTab} />
</Route>
<Route path={`/rules/id/:detailName/:tabName(${RuleDetailTabs.executionEvents})`}>
<Route
path={`${RULE_DETAILS_PATH}/:detailName/:tabName(${RuleDetailTabs.executionEvents})`}
>
<ExecutionEventsTable ruleId={ruleId} />
</Route>
</Switch>
Expand Down
10 changes: 5 additions & 5 deletions x-pack/plugins/security_solution/public/rules/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Redirect, Switch } from 'react-router-dom';
import { Route } from '@kbn/kibana-react-plugin/public';
import { TrackApplicationView } from '@kbn/usage-collection-plugin/public';
import * as i18n from './translations';
import { RULES_PATH, SecurityPageName } from '../../common/constants';
import { RULES_PATH, RULE_DETAILS_PATH, SecurityPageName } from '../../common/constants';
import { NotFoundPage } from '../app/404';
import { RulesPage } from '../detection_engine/rule_management_ui/pages/rule_management';
import { CreateRulePage } from '../detection_engine/rule_creation_ui/pages/rule_creation';
Expand All @@ -25,12 +25,12 @@ import { SpyRoute } from '../common/utils/route/spy_routes';

const RulesSubRoutes = [
{
path: '/rules/id/:detailName/edit',
path: `${RULE_DETAILS_PATH}/:detailName/edit`,
main: EditRulePage,
exact: true,
},
{
path: `/rules/id/:detailName/:tabName(${RuleDetailTabs.alerts}|${RuleDetailTabs.exceptions}|${RuleDetailTabs.endpointExceptions}|${RuleDetailTabs.executionResults}|${RuleDetailTabs.executionEvents})`,
path: `${RULE_DETAILS_PATH}/:detailName/:tabName(${RuleDetailTabs.alerts}|${RuleDetailTabs.exceptions}|${RuleDetailTabs.endpointExceptions}|${RuleDetailTabs.executionResults}|${RuleDetailTabs.executionEvents})`,
main: RuleDetailsPage,
exact: true,
},
Expand All @@ -54,7 +54,7 @@ const RulesContainerComponent: React.FC = () => {
<TrackApplicationView viewId={SecurityPageName.rules}>
<Switch>
<Route // Redirect to first tab if none specified
path="/rules/id/:detailName"
path={`${RULE_DETAILS_PATH}/:detailName`}
exact
render={({
match: {
Expand All @@ -65,7 +65,7 @@ const RulesContainerComponent: React.FC = () => {
<Redirect
to={{
...location,
pathname: `/rules/id/${detailName}/${RuleDetailTabs.alerts}`,
pathname: `${RULE_DETAILS_PATH}/${detailName}/${RuleDetailTabs.alerts}`,
search: location.search,
}}
/>
Expand Down
Loading

0 comments on commit 5abc417

Please sign in to comment.