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

Deprecate feature flag for Custom threshold rule #172584

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,16 @@ const withCore = makeDecorator({
},
} as unknown as Partial<CoreStart>);

const config: ConfigSchema = {
const config = {
unsafe: {
alertDetails: {
logs: { enabled: false },
metrics: { enabled: false },
uptime: { enabled: false },
observability: { enabled: false },
},
thresholdRule: { enabled: false },
},
};
} as ConfigSchema;

return (
<MemoryRouter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,52 +115,49 @@ export const registerObservabilityRuleTypes = async (
priority: 100,
});

if (config.unsafe.thresholdRule.enabled) {
observabilityRuleTypeRegistry.register({
id: OBSERVABILITY_THRESHOLD_RULE_TYPE_ID,
description: i18n.translate(
'xpack.observability.customThreshold.rule.alertFlyout.alertDescription',
{
defaultMessage:
'Alert when any Observability data type reaches or exceeds a given value.',
}
),
iconClass: 'bell',
documentationUrl(docLinks) {
return `${docLinks.links.observability.customThreshold}`;
},
ruleParamsExpression: lazy(
() => import('../components/custom_threshold/custom_threshold_rule_expression')
),
validate: validateCustomThreshold,
defaultActionMessage: thresholdDefaultActionMessage,
defaultRecoveryMessage: thresholdDefaultRecoveryMessage,
requiresAppContext: false,
format: ({ fields }) => {
const searchConfiguration = fields[ALERT_RULE_PARAMETERS]?.searchConfiguration as
| SerializedSearchSourceFields
| undefined;
const criteria = fields[ALERT_RULE_PARAMETERS]?.criteria as MetricExpression[];
const metrics: CustomThresholdExpressionMetric[] =
criteria.length === 1 ? criteria[0].metrics : [];

const dataViewId = getDataViewId(searchConfiguration);
return {
reason: fields[ALERT_REASON] ?? '-',
link: getViewInAppUrl(
metrics,
fields[ALERT_START],
logExplorerLocator,
(searchConfiguration?.query as { query: string }).query,
dataViewId
),
hasBasePath: true,
};
},
alertDetailsAppSection: lazy(
() => import('../components/custom_threshold/components/alert_details_app_section')
),
priority: 5,
});
}
observabilityRuleTypeRegistry.register({
id: OBSERVABILITY_THRESHOLD_RULE_TYPE_ID,
description: i18n.translate(
'xpack.observability.customThreshold.rule.alertFlyout.alertDescription',
{
defaultMessage: 'Alert when any Observability data type reaches or exceeds a given value.',
}
),
iconClass: 'bell',
documentationUrl(docLinks) {
return `${docLinks.links.observability.customThreshold}`;
},
ruleParamsExpression: lazy(
() => import('../components/custom_threshold/custom_threshold_rule_expression')
),
validate: validateCustomThreshold,
defaultActionMessage: thresholdDefaultActionMessage,
defaultRecoveryMessage: thresholdDefaultRecoveryMessage,
requiresAppContext: false,
format: ({ fields }) => {
const searchConfiguration = fields[ALERT_RULE_PARAMETERS]?.searchConfiguration as
| SerializedSearchSourceFields
| undefined;
const criteria = fields[ALERT_RULE_PARAMETERS]?.criteria as MetricExpression[];
const metrics: CustomThresholdExpressionMetric[] =
criteria.length === 1 ? criteria[0].metrics : [];

const dataViewId = getDataViewId(searchConfiguration);
return {
reason: fields[ALERT_REASON] ?? '-',
link: getViewInAppUrl(
metrics,
fields[ALERT_START],
logExplorerLocator,
(searchConfiguration?.query as { query: string }).query,
dataViewId
),
hasBasePath: true,
};
},
alertDetailsAppSection: lazy(
() => import('../components/custom_threshold/components/alert_details_app_section')
),
priority: 5,
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@ export function KibanaReactStorybookDecorator(Story: ComponentType) {
} as unknown as AppMountParameters;
const observabilityRuleTypeRegistry = createObservabilityRuleTypeRegistryMock();

const config: ConfigSchema = {
const config = {
unsafe: {
alertDetails: {
logs: { enabled: false },
metrics: { enabled: false },
uptime: { enabled: false },
observability: { enabled: false },
},
thresholdRule: { enabled: false },
},
};
} as ConfigSchema;

const mockTheme: CoreTheme = {
darkMode: false,
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/observability/public/utils/test_helper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ const defaultConfig: ConfigSchema = {
uptime: { enabled: false },
observability: { enabled: false },
},
thresholdRule: { enabled: false },
},
};
} as ConfigSchema;

const queryClient = new QueryClient({
defaultOptions: {
Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/observability/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ const configSchema = schema.object({
}),
thresholdRule: schema.object({
enabled: offeringBasedSchema({
serverless: schema.boolean({ defaultValue: true }),
traditional: schema.boolean({ defaultValue: true }),
serverless: schema.boolean({ defaultValue: false }),
benakansara marked this conversation as resolved.
Show resolved Hide resolved
traditional: schema.boolean({ defaultValue: false }),
}),
}),
}),
Expand All @@ -71,6 +71,7 @@ export const config: PluginConfigDescriptor = {
},
},
schema: configSchema,
deprecations: ({ unused }) => [unused('unsafe.thresholdRule.enabled', { level: 'warning' })],
};

export type ObservabilityConfig = TypeOf<typeof configSchema>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,35 +58,32 @@ export function registerRuleTypes(
sloBurnRateRuleType(createLifecycleRuleExecutorSLO, basePath, locators.alertsLocator)
);

// Threshold RULE
if (config.unsafe.thresholdRule.enabled) {
const ruleDataClientThreshold = ruleDataService.initializeIndex({
feature: observabilityFeatureId,
registrationContext: THRESHOLD_RULE_REGISTRATION_CONTEXT,
dataset: Dataset.alerts,
componentTemplateRefs: [],
componentTemplates: [
{
name: 'mappings',
mappings: mappingFromFieldMap({ ...legacyExperimentalFieldMap }, 'strict'),
},
],
});
const ruleDataClientThreshold = ruleDataService.initializeIndex({
feature: observabilityFeatureId,
registrationContext: THRESHOLD_RULE_REGISTRATION_CONTEXT,
dataset: Dataset.alerts,
componentTemplateRefs: [],
componentTemplates: [
{
name: 'mappings',
mappings: mappingFromFieldMap({ ...legacyExperimentalFieldMap }, 'strict'),
},
],
});

const createLifecycleRuleExecutorThreshold = createLifecycleExecutor(
logger.get('rules'),
ruleDataClientThreshold
);
const createLifecycleRuleExecutorThreshold = createLifecycleExecutor(
logger.get('rules'),
ruleDataClientThreshold
);

alertingPlugin.registerType(
thresholdRuleType(
createLifecycleRuleExecutorThreshold,
basePath,
config,
logger,
ruleDataClientThreshold,
locators
)
);
}
alertingPlugin.registerType(
thresholdRuleType(
createLifecycleRuleExecutorThreshold,
basePath,
config,
logger,
ruleDataClientThreshold,
locators
)
);
}
1 change: 0 additions & 1 deletion x-pack/test/alerting_api_integration/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ export function createTestConfig(name: string, options: CreateTestConfigOptions)
'--xpack.alerting.healthCheck.interval="1s"',
'--xpack.alerting.rules.minimumScheduleInterval.value="1s"',
'--xpack.alerting.rules.run.alerts.max=20',
'--xpack.observability.unsafe.thresholdRule.enabled=true',
`--xpack.alerting.rules.run.actions.connectorTypeOverrides=${JSON.stringify([
{ id: 'test.capped', max: '1' },
])}`,
Expand Down