Skip to content

Commit

Permalink
Removing unused rule data client
Browse files Browse the repository at this point in the history
  • Loading branch information
ymao1 committed Nov 13, 2024
1 parent 1f5fe1d commit 8219edd
Show file tree
Hide file tree
Showing 16 changed files with 7 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type {
RegistrationCallback,
RegisterFunction,
} from '@kbn/observability-ai-assistant-plugin/server/service/types';
import type { IRuleDataClient } from '@kbn/rule-registry-plugin/server';
import type { APMConfig } from '..';
import type { ApmFeatureFlags } from '../../common/apm_feature_flags';
import { APMEventClient } from '../lib/helpers/create_es_client/create_apm_event_client';
Expand All @@ -38,15 +37,13 @@ export function registerAssistantFunctions({
featureFlags,
logger,
kibanaVersion,
ruleDataClient,
plugins,
}: {
coreSetup: CoreSetup;
config: APMConfig;
featureFlags: ApmFeatureFlags;
logger: Logger;
kibanaVersion: string;
ruleDataClient: IRuleDataClient;
plugins: APMRouteHandlerResources['plugins'];
}): RegistrationCallback {
return async ({ resources, functions: { registerFunction }, scopes }) => {
Expand All @@ -69,7 +66,6 @@ export function registerAssistantFunctions({
featureFlags,
logger,
kibanaVersion,
ruleDataClient,
plugins,
getApmIndices: async () => {
const coreContext = await resources.context.core;
Expand Down
25 changes: 1 addition & 24 deletions x-pack/plugins/observability_solution/apm/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@

import { CoreSetup, CoreStart, Logger, Plugin, PluginInitializerContext } from '@kbn/core/server';
import { isEmpty, mapValues } from 'lodash';
import { Dataset } from '@kbn/rule-registry-plugin/server';
import { mappingFromFieldMap } from '@kbn/alerting-plugin/common';
import { alertsLocatorID } from '@kbn/observability-plugin/common';
import { APMConfig, APM_SERVER_FEATURE_ID } from '.';
import { APM_FEATURE, registerFeaturesUsage } from './feature';
import {
registerApmRuleTypes,
apmRuleTypeAlertFieldMap,
APM_RULE_TYPE_ALERT_CONTEXT,
} from './routes/alerts/register_apm_rule_types';
import { registerApmRuleTypes } from './routes/alerts/register_apm_rule_types';
import { registerFleetPolicyCallbacks } from './routes/fleet/register_fleet_policy_callbacks';
import { createApmTelemetry } from './lib/apm_telemetry';
import { getInternalSavedObjectsClient } from './lib/helpers/get_internal_saved_objects_client';
Expand Down Expand Up @@ -89,20 +83,6 @@ export class APMPlugin
const getPluginStart = () =>
core.getStartServices().then(([coreStart, pluginStart]) => pluginStart);

const { ruleDataService } = plugins.ruleRegistry;
const ruleDataClient = ruleDataService.initializeIndex({
feature: APM_SERVER_FEATURE_ID,
registrationContext: APM_RULE_TYPE_ALERT_CONTEXT,
dataset: Dataset.alerts,
componentTemplateRefs: [],
componentTemplates: [
{
name: 'mappings',
mappings: mappingFromFieldMap(apmRuleTypeAlertFieldMap, 'strict'),
},
],
});

const resourcePlugins = mapValues(plugins, (value, key) => {
return {
setup: value,
Expand Down Expand Up @@ -156,7 +136,6 @@ export class APMPlugin
config: currentConfig,
featureFlags: currentConfig.featureFlags,
repository: getGlobalApmServerRouteRepository(),
ruleDataClient,
plugins: resourcePlugins,
telemetryUsageCounter,
kibanaVersion,
Expand All @@ -173,7 +152,6 @@ export class APMPlugin
logger: this.logger!.get('rule'),
ml: plugins.ml,
observability: plugins.observability,
ruleDataClient,
alertsLocator: plugins.share.url.locators.get(alertsLocatorID),
});
}
Expand Down Expand Up @@ -218,7 +196,6 @@ export class APMPlugin
kibanaVersion,
logger: this.logger.get('assistant'),
plugins: resourcePlugins,
ruleDataClient,
})
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
type IRuleTypeAlerts,
} from '@kbn/alerting-plugin/server';
import { ObservabilityPluginSetup } from '@kbn/observability-plugin/server';
import { IRuleDataClient } from '@kbn/rule-registry-plugin/server';
import { MlPluginSetup } from '@kbn/ml-plugin/server';
import { legacyExperimentalFieldMap, ObservabilityApmAlert } from '@kbn/alerts-as-data-utils';
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
Expand Down Expand Up @@ -107,7 +106,6 @@ export interface RegisterRuleDependencies {
logger: Logger;
ml?: MlPluginSetup;
observability: ObservabilityPluginSetup;
ruleDataClient: IRuleDataClient;
alertsLocator?: LocatorPublic<AlertsLocatorParams>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export function registerAnomalyRuleType({
basePath,
logger,
ml,
ruleDataClient,
}: RegisterRuleDependencies) {
if (!alerting) {
throw new Error('Cannot register anomaly rule type. The alerting plugin needs to be enabled.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export function registerErrorCountRuleType({
basePath,
getApmIndices,
logger,
ruleDataClient,
}: RegisterRuleDependencies) {
if (!alerting) {
throw new Error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ export function registerTransactionErrorRateRuleType({
basePath,
getApmIndices,
logger,
ruleDataClient,
}: RegisterRuleDependencies) {
if (!alerting) {
throw new Error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import { IBasePath, Logger } from '@kbn/core/server';
import { elasticsearchServiceMock } from '@kbn/core/server/mocks';
import { IRuleDataClient } from '@kbn/rule-registry-plugin/server';
import { ruleRegistryMocks } from '@kbn/rule-registry-plugin/server/mocks';
import { PluginSetupContract as AlertingPluginSetupContract } from '@kbn/alerting-plugin/server';
import { ObservabilityPluginSetup } from '@kbn/observability-plugin/server';
import { DEFAULT_FLAPPING_SETTINGS } from '@kbn/alerting-plugin/common';
Expand Down Expand Up @@ -75,9 +73,6 @@ export const createRuleTypeMocks = () => {
getAlertDetailsConfig: jest.fn().mockReturnValue({ apm: true }),
} as unknown as ObservabilityPluginSetup,
logger: loggerMock,
ruleDataClient: ruleRegistryMocks.createRuleDataClient(
'.alerts-observability.apm.alerts'
) as IRuleDataClient,
} as unknown as RegisterRuleDependencies;

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { jsonRt, mergeRt } from '@kbn/io-ts-utils';
import { InspectResponse } from '@kbn/observability-plugin/typings/common';
import apm from 'elastic-apm-node';
import { VersionedRouteRegistrar } from '@kbn/core-http-server';
import { IRuleDataClient } from '@kbn/rule-registry-plugin/server';
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
import { ApmFeatureFlags } from '../../../common/apm_feature_flags';
import type {
Expand Down Expand Up @@ -59,7 +58,6 @@ export function registerRoutes({
plugins,
logger,
config,
ruleDataClient,
telemetryUsageCounter,
kibanaVersion,
}: {
Expand All @@ -69,7 +67,6 @@ export function registerRoutes({
logger: APMRouteHandlerResources['logger'];
repository: ServerRouteRepository;
config: APMRouteHandlerResources['config'];
ruleDataClient: APMRouteHandlerResources['ruleDataClient'];
telemetryUsageCounter?: TelemetryUsageCounter;
kibanaVersion: string;
}) {
Expand Down Expand Up @@ -135,7 +132,6 @@ export function registerRoutes({
},
validatedParams
),
ruleDataClient,
kibanaVersion,
}).then((value: Record<string, any> | undefined | null) => {
return {
Expand Down Expand Up @@ -268,7 +264,6 @@ export interface APMRouteHandlerResources {
logger: Logger;
core: APMCore;
plugins: Plugins;
ruleDataClient: IRuleDataClient;
telemetryUsageCounter?: TelemetryUsageCounter;
kibanaVersion: string;
getApmIndices: () => Promise<APMIndices>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ export interface InfraBackendLibs extends InfraDomainLibs {
basePath: IBasePath;
configuration: InfraConfig;
framework: KibanaFramework;
logsRules: RulesServiceSetup;
metricsRules: RulesServiceSetup;
sources: InfraSources;
sourceStatus: InfraSourceStatus;
getAlertDetailsConfig: () => ObservabilityConfig['unsafe']['alertDetails'];
Expand Down
21 changes: 0 additions & 21 deletions x-pack/plugins/observability_solution/infra/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
} from '@kbn/observability-shared-plugin/common';
import { type AlertsLocatorParams, alertsLocatorID } from '@kbn/observability-plugin/common';
import { mapValues } from 'lodash';
import { LOGS_FEATURE_ID, METRICS_FEATURE_ID } from '../common/constants';
import { publicConfigKeys } from '../common/plugin_config_types';
import { LOGS_FEATURE, METRICS_FEATURE } from './features';
import { registerRoutes } from './infra_server';
Expand All @@ -34,10 +33,6 @@ import { KibanaFramework } from './lib/adapters/framework/kibana_framework_adapt
import { KibanaMetricsAdapter } from './lib/adapters/metrics/kibana_metrics_adapter';
import { InfraElasticsearchSourceStatusAdapter } from './lib/adapters/source_status';
import { registerRuleTypes } from './lib/alerting';
import {
LOGS_RULES_ALERT_CONTEXT,
METRICS_RULES_ALERT_CONTEXT,
} from './lib/alerting/register_rule_types';
import { InfraMetricsDomain } from './lib/domains/metrics_domain';
import { InfraBackendLibs, InfraDomainLibs } from './lib/infra_types';
import { infraSourceConfigurationSavedObjectType, InfraSources } from './lib/sources';
Expand All @@ -49,7 +44,6 @@ import {
} from './saved_objects';
import { InventoryViewsService } from './services/inventory_views';
import { MetricsExplorerViewsService } from './services/metrics_explorer_views';
import { RulesService } from './services/rules';
import {
InfraConfig,
InfraPluginCoreSetup,
Expand Down Expand Up @@ -153,26 +147,13 @@ export class InfraServerPlugin
public libs!: InfraBackendLibs;
public logger: Logger;

private logsRules: RulesService;
private metricsRules: RulesService;
private inventoryViews: InventoryViewsService;
private metricsExplorerViews?: MetricsExplorerViewsService;

constructor(context: PluginInitializerContext<InfraConfig>) {
this.config = context.config.get();
this.logger = context.logger.get();

this.logsRules = new RulesService(
LOGS_FEATURE_ID,
LOGS_RULES_ALERT_CONTEXT,
this.logger.get('logsRules')
);
this.metricsRules = new RulesService(
METRICS_FEATURE_ID,
METRICS_RULES_ALERT_CONTEXT,
this.logger.get('metricsRules')
);

this.inventoryViews = new InventoryViewsService(this.logger.get('inventoryViews'));
this.metricsExplorerViews = this.config.featureFlags.metricsExplorerEnabled
? new MetricsExplorerViewsService(this.logger.get('metricsExplorerViews'))
Expand Down Expand Up @@ -251,8 +232,6 @@ export class InfraServerPlugin
sourceStatus,
...domainLibs,
handleEsError,
logsRules: this.logsRules.setup(core, plugins),
metricsRules: this.metricsRules.setup(core, plugins),
getStartServices: () => core.getStartServices(),
getAlertDetailsConfig: () => plugins.observability.getAlertDetailsConfig(),
logger: this.logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { PluginSetupContract as AlertingPluginSetup } from '@kbn/alerting-plugin/server';
import { IRuleDataClient, RuleRegistryPluginSetupContract } from '@kbn/rule-registry-plugin/server';
import { RuleRegistryPluginSetupContract } from '@kbn/rule-registry-plugin/server';
export interface RulesServiceSetupDeps {
alerting: AlertingPluginSetup;
ruleRegistry: RuleRegistryPluginSetupContract;
Expand All @@ -15,9 +15,7 @@ export interface RulesServiceSetupDeps {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface RulesServiceStartDeps {}

export interface RulesServiceSetup {
ruleDataClient: IRuleDataClient;
}
export interface RulesServiceSetup {}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface RulesServiceStart {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import {
SavedObjectsClient,
SavedObjectsClientContract,
} from '@kbn/core/server';
import { mappingFromFieldMap } from '@kbn/alerting-plugin/common';
import { Dataset } from '@kbn/rule-registry-plugin/server';
import {
SyntheticsPluginsSetupDependencies,
SyntheticsPluginsStartDependencies,
Expand All @@ -28,8 +26,6 @@ import { registerSyntheticsSavedObjects } from './saved_objects/saved_objects';
import { UptimeConfig } from './config';
import { SyntheticsService } from './synthetics_service/synthetics_service';
import { syntheticsServiceApiKey } from './saved_objects/service_api_key';
import { SYNTHETICS_RULE_TYPES_ALERT_CONTEXT } from '../common/constants/synthetics_alerts';
import { syntheticsRuleTypeFieldMap } from './alert_rules/common';

export class Plugin implements PluginType {
private savedObjectsClient?: SavedObjectsClientContract;
Expand All @@ -47,21 +43,6 @@ export class Plugin implements PluginType {
public setup(core: CoreSetup, plugins: SyntheticsPluginsSetupDependencies) {
const config = this.initContext.config.get<UptimeConfig>();

const { ruleDataService } = plugins.ruleRegistry;

const ruleDataClient = ruleDataService.initializeIndex({
feature: 'uptime',
registrationContext: SYNTHETICS_RULE_TYPES_ALERT_CONTEXT,
dataset: Dataset.alerts,
componentTemplateRefs: [],
componentTemplates: [
{
name: 'mappings',
mappings: mappingFromFieldMap(syntheticsRuleTypeFieldMap, 'strict'),
},
],
});

this.server = {
config,
router: core.http.createRouter(),
Expand All @@ -85,7 +66,7 @@ export class Plugin implements PluginType {

plugins.features.registerKibanaFeature(syntheticsFeature);

initSyntheticsServer(this.server, this.syntheticsMonitorClient, plugins, ruleDataClient);
initSyntheticsServer(this.server, this.syntheticsMonitorClient, plugins);

registerSyntheticsSavedObjects(core.savedObjects, plugins.encryptedSavedObjects);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { IRuleDataClient } from '@kbn/rule-registry-plugin/server';
import { registerSyntheticsTLSCheckRule } from './alert_rules/tls_rule/tls_rule';
import { registerSyntheticsStatusCheckRule } from './alert_rules/status_rule/monitor_status_rule';
import { SyntheticsPluginsSetupDependencies, SyntheticsServerSetup } from './types';
Expand All @@ -16,8 +15,7 @@ import { syntheticsAppPublicRestApiRoutes, syntheticsAppRestApiRoutes } from './
export const initSyntheticsServer = (
server: SyntheticsServerSetup,
syntheticsMonitorClient: SyntheticsMonitorClient,
plugins: SyntheticsPluginsSetupDependencies,
ruleDataClient: IRuleDataClient
plugins: SyntheticsPluginsSetupDependencies
) => {
const { router } = server;
syntheticsAppRestApiRoutes.forEach((route) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
*/

import { IBasePath, Logger } from '@kbn/core/server';
import type { IRuleDataClient } from '@kbn/rule-registry-plugin/server';
import { ruleRegistryMocks } from '@kbn/rule-registry-plugin/server/mocks';
import { alertsMock } from '@kbn/alerting-plugin/server/mocks';
import type { AlertsLocatorParams } from '@kbn/observability-plugin/common';
import { LocatorPublic } from '@kbn/share-plugin/common';
Expand Down Expand Up @@ -91,9 +89,6 @@ export const createRuleTypeMocks = (recoveredAlerts: Array<Record<string, any>>
return {
dependencies: {
logger: loggerMock,
ruleDataClient: ruleRegistryMocks.createRuleDataClient(
'.alerts-observability.uptime.alerts'
) as IRuleDataClient,
},
services,
scheduleActions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import { Logger } from '@kbn/core/server';
import { IRuleDataClient } from '@kbn/rule-registry-plugin/server';
import { getRequestValidation } from '@kbn/core-http-server';
import { INITIAL_REST_VERSION } from '../../common/constants';
import { DynamicSettingsSchema } from './routes/dynamic_settings';
Expand Down Expand Up @@ -36,7 +35,6 @@ export type UMServerLibs = typeof libs;
export const initUptimeServer = (
server: UptimeServerSetup,
plugins: UptimeCorePluginsSetup,
ruleDataClient: IRuleDataClient,
logger: Logger,
router: UptimeRouter
) => {
Expand Down
Loading

0 comments on commit 8219edd

Please sign in to comment.