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

Removing unused rule data client #200080

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -16,7 +16,6 @@ import type {
MetricsExplorerLocator,
} from '@kbn/observability-shared-plugin/common';
import type { AlertsLocator } from '@kbn/observability-plugin/common';
import { RulesServiceSetup } from '../services/rules';
import { InfraConfig, InfraPluginStartServicesAccessor } from '../types';
import { KibanaFramework } from './adapters/framework/kibana_framework_adapter';
import { InfraMetricsDomain } from './domains/metrics_domain';
Expand All @@ -42,8 +41,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

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading