mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Infra] Remove additional indexFields
related functions (#189706)
Relates to https://github.com/elastic/kibana/issues/180690 ## Summary This PR is a follow-up to https://github.com/elastic/kibana/pull/189541 and removes additional functions related to the `indexFields` that are no longer needed ## Testing Check `metricIndicesExist` and `remoteClustersExist` in the request by changing the settings (in the first video I use metricbeat and no oblt cluster and in the second one I am connected to oblt cluster) https://github.com/user-attachments/assets/59920479-5a42-4a6a-a66a-307ddfc48fd8 https://github.com/user-attachments/assets/ef04120c-6873-4b0c-813c-388147c2b741
This commit is contained in:
parent
6a2d0147fb
commit
a18d60c8c1
8 changed files with 16 additions and 161 deletions
|
@ -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<typeof SourceStatusFieldRuntimeType>;
|
||||
|
||||
export const SourceStatusRuntimeType = rt.type({
|
||||
logIndicesExist: rt.boolean,
|
||||
|
|
|
@ -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<IndexFieldDescriptor[]>;
|
||||
}
|
||||
|
||||
export interface IndexFieldDescriptor {
|
||||
name: string;
|
||||
type: string;
|
||||
searchable: boolean;
|
||||
aggregatable: boolean;
|
||||
displayable: boolean;
|
||||
}
|
|
@ -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<IndexFieldDescriptor[]> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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';
|
|
@ -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<InfraSourceIndexField[]> {
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)),
|
||||
};
|
||||
|
|
|
@ -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<MetricsSourceStatus> => {
|
||||
const [metricIndicesExistSettled, indexFieldsSettled] = await Promise.allSettled([
|
||||
libs.sourceStatus.hasMetricIndices(requestContext, sourceId),
|
||||
libs.fields.getFields(requestContext, sourceId, 'METRICS'),
|
||||
]);
|
||||
try {
|
||||
const hasMetricIndices = await libs.sourceStatus.hasMetricIndices(requestContext, sourceId);
|
||||
return {
|
||||
metricIndicesExist: hasMetricIndices,
|
||||
remoteClustersExist: true,
|
||||
};
|
||||
} catch (err) {
|
||||
logger.error(err);
|
||||
|
||||
/**
|
||||
* Extract values from promises settlements
|
||||
*/
|
||||
const metricIndicesExist = isFulfilled<boolean>(metricIndicesExistSettled)
|
||||
? metricIndicesExistSettled.value
|
||||
: defaultStatus.metricIndicesExist;
|
||||
const remoteClustersExist = hasRemoteCluster<boolean | InfraSourceIndexField[]>(
|
||||
indexFieldsSettled,
|
||||
metricIndicesExistSettled
|
||||
);
|
||||
if (err instanceof NoSuchRemoteClusterError) {
|
||||
return defaultStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Report gracefully handled rejections
|
||||
*/
|
||||
if (!isFulfilled<InfraSourceIndexField[]>(indexFieldsSettled)) {
|
||||
logger.error(indexFieldsSettled.reason);
|
||||
return {
|
||||
metricIndicesExist: false,
|
||||
remoteClustersExist: true,
|
||||
};
|
||||
}
|
||||
if (!isFulfilled<boolean>(metricIndicesExistSettled)) {
|
||||
logger.error(metricIndicesExistSettled.reason);
|
||||
}
|
||||
|
||||
return {
|
||||
metricIndicesExist,
|
||||
remoteClustersExist,
|
||||
};
|
||||
};
|
||||
|
||||
framework.registerRoute(
|
||||
|
@ -283,12 +271,3 @@ export const initMetricsSourceConfigurationRoutes = (libs: InfraBackendLibs) =>
|
|||
const isFulfilled = <Type>(
|
||||
promiseSettlement: PromiseSettledResult<Type>
|
||||
): promiseSettlement is PromiseFulfilledResult<Type> => promiseSettlement.status === 'fulfilled';
|
||||
|
||||
const hasRemoteCluster = <Type>(...promiseSettlements: Array<PromiseSettledResult<Type>>) => {
|
||||
const isRemoteMissing = promiseSettlements.some(
|
||||
(settlement) =>
|
||||
!isFulfilled<Type>(settlement) && settlement.reason instanceof NoSuchRemoteClusterError
|
||||
);
|
||||
|
||||
return !isRemoteMissing;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue