diff --git a/x-pack/plugins/observability_solution/infra/common/source_configuration/source_configuration.ts b/x-pack/plugins/observability_solution/infra/common/source_configuration/source_configuration.ts index 59e5e653ca538..116c30d8274e3 100644 --- a/x-pack/plugins/observability_solution/infra/common/source_configuration/source_configuration.ts +++ b/x-pack/plugins/observability_solution/infra/common/source_configuration/source_configuration.ts @@ -130,15 +130,6 @@ export interface InfraSourceConfiguration /** * Source status */ -const SourceStatusFieldRuntimeType = rt.type({ - name: rt.string, - type: rt.string, - searchable: rt.boolean, - aggregatable: rt.boolean, - displayable: rt.boolean, -}); - -export type InfraSourceIndexField = rt.TypeOf; export const SourceStatusRuntimeType = rt.type({ logIndicesExist: rt.boolean, diff --git a/x-pack/plugins/observability_solution/infra/server/lib/adapters/fields/adapter_types.ts b/x-pack/plugins/observability_solution/infra/server/lib/adapters/fields/adapter_types.ts deleted file mode 100644 index 60b95acf29e02..0000000000000 --- a/x-pack/plugins/observability_solution/infra/server/lib/adapters/fields/adapter_types.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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 type { InfraPluginRequestHandlerContext } from '../../../types'; - -export interface FieldsAdapter { - getIndexFields( - requestContext: InfraPluginRequestHandlerContext, - indices: string - ): Promise; -} - -export interface IndexFieldDescriptor { - name: string; - type: string; - searchable: boolean; - aggregatable: boolean; - displayable: boolean; -} diff --git a/x-pack/plugins/observability_solution/infra/server/lib/adapters/fields/framework_fields_adapter.ts b/x-pack/plugins/observability_solution/infra/server/lib/adapters/fields/framework_fields_adapter.ts deleted file mode 100644 index 45bb8dc0957d9..0000000000000 --- a/x-pack/plugins/observability_solution/infra/server/lib/adapters/fields/framework_fields_adapter.ts +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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 { FieldSpec } from '@kbn/data-views-plugin/common'; -import type { InfraPluginRequestHandlerContext } from '../../../types'; -import { isNoSuchRemoteClusterMessage, NoSuchRemoteClusterError } from '../../sources/errors'; -import { KibanaFramework } from '../framework/kibana_framework_adapter'; -import { FieldsAdapter, IndexFieldDescriptor } from './adapter_types'; - -export class FrameworkFieldsAdapter implements FieldsAdapter { - private framework: KibanaFramework; - - constructor(framework: KibanaFramework) { - this.framework = framework; - } - - public async getIndexFields( - requestContext: InfraPluginRequestHandlerContext, - indices: string - ): Promise { - const indexPatternsService = await this.framework.getIndexPatternsServiceWithRequestContext( - requestContext - ); - - try { - // NOTE: Unfortunately getFieldsForWildcard is typed to "any" here in the data plugin, FieldSpec is used below in the map. - const response = await indexPatternsService.getFieldsForWildcard({ - pattern: indices, - allowNoIndex: true, - }); - - return response.map((field: FieldSpec) => ({ - ...field, - displayable: true, - })); - } catch (error) { - if (isNoSuchRemoteClusterMessage(error.message)) { - throw new NoSuchRemoteClusterError(); - } - throw error; - } - } -} diff --git a/x-pack/plugins/observability_solution/infra/server/lib/adapters/fields/index.ts b/x-pack/plugins/observability_solution/infra/server/lib/adapters/fields/index.ts deleted file mode 100644 index 5d7c09c54b8c1..0000000000000 --- a/x-pack/plugins/observability_solution/infra/server/lib/adapters/fields/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -/* - * 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 * from './adapter_types'; diff --git a/x-pack/plugins/observability_solution/infra/server/lib/domains/fields_domain.ts b/x-pack/plugins/observability_solution/infra/server/lib/domains/fields_domain.ts deleted file mode 100644 index b80fa9d796021..0000000000000 --- a/x-pack/plugins/observability_solution/infra/server/lib/domains/fields_domain.ts +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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 type { InfraPluginRequestHandlerContext } from '../../types'; -import { FieldsAdapter } from '../adapters/fields'; -import { InfraSourceIndexField, InfraSources } from '../sources'; - -export class InfraFieldsDomain { - constructor( - private readonly adapter: FieldsAdapter, - private readonly libs: { sources: InfraSources } - ) {} - - public async getFields( - requestContext: InfraPluginRequestHandlerContext, - sourceId: string, - indexType: 'METRICS' - ): Promise { - const soClient = (await requestContext.core).savedObjects.client; - const { configuration } = await this.libs.sources.getSourceConfiguration(soClient, sourceId); - - const fields = await this.adapter.getIndexFields(requestContext, configuration.metricAlias); - - return fields; - } -} diff --git a/x-pack/plugins/observability_solution/infra/server/lib/infra_types.ts b/x-pack/plugins/observability_solution/infra/server/lib/infra_types.ts index 8cf0fc81a7321..08cf030a16219 100644 --- a/x-pack/plugins/observability_solution/infra/server/lib/infra_types.ts +++ b/x-pack/plugins/observability_solution/infra/server/lib/infra_types.ts @@ -18,13 +18,11 @@ import { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; import { RulesServiceSetup } from '../services/rules'; import { InfraConfig, InfraPluginStartServicesAccessor } from '../types'; import { KibanaFramework } from './adapters/framework/kibana_framework_adapter'; -import { InfraFieldsDomain } from './domains/fields_domain'; import { InfraMetricsDomain } from './domains/metrics_domain'; import { InfraSources } from './sources'; import { InfraSourceStatus } from './source_status'; export interface InfraDomainLibs { - fields: InfraFieldsDomain; logEntries: ILogsSharedLogEntriesDomain; metrics: InfraMetricsDomain; } diff --git a/x-pack/plugins/observability_solution/infra/server/plugin.ts b/x-pack/plugins/observability_solution/infra/server/plugin.ts index 0182d34b76866..61f53b4b9260d 100644 --- a/x-pack/plugins/observability_solution/infra/server/plugin.ts +++ b/x-pack/plugins/observability_solution/infra/server/plugin.ts @@ -23,7 +23,6 @@ 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 { initInfraServer } from './infra_server'; -import { FrameworkFieldsAdapter } from './lib/adapters/fields/framework_fields_adapter'; import { InfraServerPluginSetupDeps, InfraServerPluginStartDeps } from './lib/adapters/framework'; import { KibanaFramework } from './lib/adapters/framework/kibana_framework_adapter'; import { KibanaMetricsAdapter } from './lib/adapters/metrics/kibana_metrics_adapter'; @@ -33,7 +32,6 @@ import { LOGS_RULES_ALERT_CONTEXT, METRICS_RULES_ALERT_CONTEXT, } from './lib/alerting/register_rule_types'; -import { InfraFieldsDomain } from './lib/domains/fields_domain'; import { InfraMetricsDomain } from './lib/domains/metrics_domain'; import { InfraBackendLibs, InfraDomainLibs } from './lib/infra_types'; import { infraSourceConfigurationSavedObjectType, InfraSources } from './lib/sources'; @@ -210,9 +208,6 @@ export class InfraServerPlugin // and make them available via the request context so we can do away with // the wrapper classes const domainLibs: InfraDomainLibs = { - fields: new InfraFieldsDomain(new FrameworkFieldsAdapter(framework), { - sources, - }), logEntries: plugins.logsShared.logEntries, metrics: new InfraMetricsDomain(new KibanaMetricsAdapter(framework)), }; diff --git a/x-pack/plugins/observability_solution/infra/server/routes/metrics_sources/index.ts b/x-pack/plugins/observability_solution/infra/server/routes/metrics_sources/index.ts index 945e0d684ab5e..3540dac3d311c 100644 --- a/x-pack/plugins/observability_solution/infra/server/routes/metrics_sources/index.ts +++ b/x-pack/plugins/observability_solution/infra/server/routes/metrics_sources/index.ts @@ -24,7 +24,7 @@ import { MetricsSourceStatus, partialMetricsSourceConfigurationReqPayloadRT, } from '../../../common/metrics_sources'; -import { InfraSource, InfraSourceIndexField } from '../../lib/sources'; +import { InfraSource } from '../../lib/sources'; import { InfraPluginRequestHandlerContext } from '../../types'; import { getInfraMetricsClient } from '../../lib/helpers/get_infra_metrics_client'; @@ -42,36 +42,24 @@ export const initMetricsSourceConfigurationRoutes = (libs: InfraBackendLibs) => requestContext: InfraPluginRequestHandlerContext, sourceId: string ): Promise => { - const [metricIndicesExistSettled, indexFieldsSettled] = await Promise.allSettled([ - libs.sourceStatus.hasMetricIndices(requestContext, sourceId), - libs.fields.getFields(requestContext, sourceId, 'METRICS'), - ]); - - /** - * Extract values from promises settlements - */ - const metricIndicesExist = isFulfilled(metricIndicesExistSettled) - ? metricIndicesExistSettled.value - : defaultStatus.metricIndicesExist; - const remoteClustersExist = hasRemoteCluster( - indexFieldsSettled, - metricIndicesExistSettled - ); - - /** - * Report gracefully handled rejections - */ - if (!isFulfilled(indexFieldsSettled)) { - logger.error(indexFieldsSettled.reason); - } - if (!isFulfilled(metricIndicesExistSettled)) { - logger.error(metricIndicesExistSettled.reason); - } + try { + const hasMetricIndices = await libs.sourceStatus.hasMetricIndices(requestContext, sourceId); + return { + metricIndicesExist: hasMetricIndices, + remoteClustersExist: true, + }; + } catch (err) { + logger.error(err); + + if (err instanceof NoSuchRemoteClusterError) { + return defaultStatus; + } - return { - metricIndicesExist, - remoteClustersExist, - }; + return { + metricIndicesExist: false, + remoteClustersExist: true, + }; + } }; framework.registerRoute( @@ -283,12 +271,3 @@ export const initMetricsSourceConfigurationRoutes = (libs: InfraBackendLibs) => const isFulfilled = ( promiseSettlement: PromiseSettledResult ): promiseSettlement is PromiseFulfilledResult => promiseSettlement.status === 'fulfilled'; - -const hasRemoteCluster = (...promiseSettlements: Array>) => { - const isRemoteMissing = promiseSettlements.some( - (settlement) => - !isFulfilled(settlement) && settlement.reason instanceof NoSuchRemoteClusterError - ); - - return !isRemoteMissing; -};