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

[Infra] Remove additional indexFields related functions #189706

Merged
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 @@ -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,
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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)),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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'),
]);

/**
* Extract values from promises settlements
*/
const metricIndicesExist = isFulfilled<boolean>(metricIndicesExistSettled)
? metricIndicesExistSettled.value
: defaultStatus.metricIndicesExist;
const remoteClustersExist = hasRemoteCluster<boolean | InfraSourceIndexField[]>(
indexFieldsSettled,
metricIndicesExistSettled
);

/**
* Report gracefully handled rejections
*/
if (!isFulfilled<InfraSourceIndexField[]>(indexFieldsSettled)) {
logger.error(indexFieldsSettled.reason);
}
if (!isFulfilled<boolean>(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(
Expand Down Expand Up @@ -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;
};