Skip to content

Commit

Permalink
Deprecate feature flag for Custom threshold rule (elastic#172584)
Browse files Browse the repository at this point in the history
Resolves elastic#171406

- Deprecates following feature flag used for enabling/disabling Custom
threshold rule:
```
xpack.observability.unsafe.thresholdRule.enabled
```
- Removes usage of this flag from code.
- Adding this flag in `kibana.yml` will generate following warning:
```
[WARN ][config.deprecation] You no longer need to configure "xpack.observability.unsafe.thresholdRule.enabled".
```

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
benakansara and kibanamachine authored Dec 7, 2023
1 parent 9e41850 commit 16f09fd
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ jest.spyOn(pluginContext, 'usePluginContext').mockImplementation(() => ({
uptime: { enabled: false },
observability: { enabled: false },
},
thresholdRule: { enabled: false },
},
aiAssistant: {
enabled: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ const withCore = makeDecorator({
uptime: { enabled: false },
observability: { enabled: false },
},
thresholdRule: { enabled: false },
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ jest.spyOn(pluginContext, 'usePluginContext').mockImplementation(() => ({
uptime: { enabled: false },
observability: { enabled: false },
},
thresholdRule: { enabled: false },
},
},
observabilityRuleTypeRegistry: createObservabilityRuleTypeRegistryMock(),
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/observability/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export interface ConfigSchema {
enabled: boolean;
};
};
thresholdRule: {
thresholdRule?: {
enabled: boolean;
};
};
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 @@ -32,7 +32,6 @@ export function KibanaReactStorybookDecorator(Story: ComponentType) {
uptime: { enabled: false },
observability: { enabled: false },
},
thresholdRule: { enabled: false },
},
};

Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/observability/public/utils/test_helper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const defaultConfig: ConfigSchema = {
uptime: { enabled: false },
observability: { enabled: false },
},
thresholdRule: { enabled: false },
},
};

Expand Down
9 changes: 6 additions & 3 deletions x-pack/plugins/observability/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,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 }),
traditional: schema.boolean({ defaultValue: false }),
}),
}),
}),
Expand All @@ -70,7 +70,10 @@ export const config: PluginConfigDescriptor = {
},
},
schema: configSchema,
deprecations: ({ unused }) => [unused('unsafe.alertDetails.logs.enabled', { level: 'warning' })],
deprecations: ({ unused }) => [
unused('unsafe.thresholdRule.enabled', { level: 'warning' }),
unused('unsafe.alertDetails.logs.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
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ export default createTestConfig({
suiteTags: { exclude: ['skipSvlOblt'] },
services,
// add feature flags
kbnServerArgs: [
'--xpack.observability.unsafe.thresholdRule.enabled=true',
'--xpack.infra.enabled=true',
],
kbnServerArgs: ['--xpack.infra.enabled=true'],
// load tests in the index file
testFiles: [require.resolve('./index.feature_flags.ts')],

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export default createTestConfig({
kbnServerArgs: [
'--xpack.infra.enabled=true',
'--xpack.infra.featureFlags.customThresholdAlertsEnabled=true',
'--xpack.observability.unsafe.thresholdRule.enabled=true',
],
// load tests in the index file
testFiles: [require.resolve('./index.feature_flags.ts')],
Expand Down

0 comments on commit 16f09fd

Please sign in to comment.