Skip to content

Commit

Permalink
[Infra] Remove additional indexFields related functions (#189706)
Browse files Browse the repository at this point in the history
Relates to #180690

## Summary

This PR is a follow-up to #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
  • Loading branch information
jennypavlova authored Aug 1, 2024
1 parent 6a2d014 commit a18d60c
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 163 deletions.
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
5 changes: 0 additions & 5 deletions x-pack/plugins/observability_solution/infra/server/plugin.ts
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;
};

0 comments on commit a18d60c

Please sign in to comment.