Skip to content

Commit

Permalink
[Logs UI][Metrics UI] Remove deprecated config fields from APIs and S…
Browse files Browse the repository at this point in the history
…avedObjects (#115874)

* [Logs UI][Metrics UI] Remove deprecated config fields from APIs

* Fix typecheck

* Fix typecheck

* Fix typecheck

* Fix jest

* Fix functional test

* Remove extraneous timeField args

* Typecheck fix

* Consolidate log file changes to ResolvedLogSourceConfiguration

* Fix merge

* Revert additional logs files

* Revert inventory models

* Revert log_analysis api

* Fix timefield reference in process list

* Restore logs page files, fix typecheck on mock

* Fix functional test

* Restore inventory models index

* Fix typecheck on getFilteredMetrics

* Look CI if you don't tell me all the type errors at once I can't fix them all

* Maybe this is the last typecheck fix who knows
  • Loading branch information
Zacqary authored Oct 29, 2021
1 parent c0d005d commit 6693ef3
Show file tree
Hide file tree
Showing 84 changed files with 155 additions and 411 deletions.
7 changes: 6 additions & 1 deletion x-pack/plugins/infra/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
export const DEFAULT_SOURCE_ID = 'default';
export const METRICS_INDEX_PATTERN = 'metrics-*,metricbeat-*';
export const LOGS_INDEX_PATTERN = 'logs-*,filebeat-*,kibana_sample_data_logs*';
export const TIMESTAMP_FIELD = '@timestamp';
export const METRICS_APP = 'metrics';
export const LOGS_APP = 'logs';

export const METRICS_FEATURE_ID = 'infrastructure';
export const LOGS_FEATURE_ID = 'logs';

export type InfraFeatureId = typeof METRICS_FEATURE_ID | typeof LOGS_FEATURE_ID;

export const TIMESTAMP_FIELD = '@timestamp';
export const TIEBREAKER_FIELD = '_doc';
export const HOST_FIELD = 'host.name';
export const CONTAINER_FIELD = 'container.id';
export const POD_FIELD = 'kubernetes.pod.uid';
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const AggValueRT = rt.type({

export const ProcessListAPIRequestRT = rt.type({
hostTerm: rt.record(rt.string, rt.string),
timefield: rt.string,
indexPattern: rt.string,
to: rt.number,
sortBy: rt.type({
Expand Down Expand Up @@ -102,7 +101,6 @@ export type ProcessListAPIResponse = rt.TypeOf<typeof ProcessListAPIResponseRT>;

export const ProcessListAPIChartRequestRT = rt.type({
hostTerm: rt.record(rt.string, rt.string),
timefield: rt.string,
indexPattern: rt.string,
to: rt.number,
command: rt.string,
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/infra/common/http_api/metrics_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { MetricsUIAggregationRT } from '../inventory_models/types';
import { afterKeyObjectRT } from './metrics_explorer';

export const MetricsAPITimerangeRT = rt.type({
field: rt.string,
from: rt.number,
to: rt.number,
interval: rt.string,
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/infra/common/http_api/metrics_explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export const metricsExplorerMetricRT = rt.intersection([
]);

export const timeRangeRT = rt.type({
field: rt.string,
from: rt.number,
to: rt.number,
interval: rt.string,
Expand Down
23 changes: 8 additions & 15 deletions x-pack/plugins/infra/common/inventory_models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { i18n } from '@kbn/i18n';
import { POD_FIELD, HOST_FIELD, CONTAINER_FIELD } from '../constants';
import { host } from './host';
import { pod } from './pod';
import { awsEC2 } from './aws_ec2';
Expand All @@ -30,31 +31,23 @@ export const findInventoryModel = (type: InventoryItemType) => {
return model;
};

interface InventoryFields {
host: string;
pod: string;
container: string;
timestamp: string;
tiebreaker: string;
}

const LEGACY_TYPES = ['host', 'pod', 'container'];

const getFieldByType = (type: InventoryItemType, fields: InventoryFields) => {
export const getFieldByType = (type: InventoryItemType) => {
switch (type) {
case 'pod':
return fields.pod;
return POD_FIELD;
case 'host':
return fields.host;
return HOST_FIELD;
case 'container':
return fields.container;
return CONTAINER_FIELD;
}
};

export const findInventoryFields = (type: InventoryItemType, fields?: InventoryFields) => {
export const findInventoryFields = (type: InventoryItemType) => {
const inventoryModel = findInventoryModel(type);
if (fields && LEGACY_TYPES.includes(type)) {
const id = getFieldByType(type, fields) || inventoryModel.fields.id;
if (LEGACY_TYPES.includes(type)) {
const id = getFieldByType(type) || inventoryModel.fields.id;
return {
...inventoryModel.fields,
id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ export const logSourceConfigurationOriginRT = rt.keyof({
export type LogSourceConfigurationOrigin = rt.TypeOf<typeof logSourceConfigurationOriginRT>;

const logSourceFieldsConfigurationRT = rt.strict({
container: rt.string,
host: rt.string,
pod: rt.string,
timestamp: rt.string,
tiebreaker: rt.string,
message: rt.array(rt.string),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { DataView, DataViewsContract } from '../../../../../src/plugins/data_views/common';
import { ObjectEntries } from '../utility_types';
import { TIMESTAMP_FIELD, TIEBREAKER_FIELD } from '../constants';
import { ResolveLogSourceConfigurationError } from './errors';
import {
LogSourceColumnConfiguration,
Expand Down Expand Up @@ -61,8 +62,8 @@ const resolveLegacyReference = async (

return {
indices: sourceConfiguration.logIndices.indexName,
timestampField: sourceConfiguration.fields.timestamp,
tiebreakerField: sourceConfiguration.fields.tiebreaker,
timestampField: TIMESTAMP_FIELD,
tiebreakerField: TIEBREAKER_FIELD,
messageField: sourceConfiguration.fields.message,
fields,
runtimeMappings: {},
Expand Down Expand Up @@ -91,8 +92,8 @@ const resolveKibanaIndexPatternReference = async (

return {
indices: indexPattern.title,
timestampField: indexPattern.timeFieldName ?? '@timestamp',
tiebreakerField: '_doc',
timestampField: TIMESTAMP_FIELD,
tiebreakerField: TIEBREAKER_FIELD,
messageField: ['message'],
fields: indexPattern.fields,
runtimeMappings: resolveRuntimeMappings(indexPattern),
Expand Down
5 changes: 0 additions & 5 deletions x-pack/plugins/infra/common/metrics_sources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import * as rt from 'io-ts';
import { omit } from 'lodash';
import {
SourceConfigurationRT,
SourceStatusRuntimeType,
Expand All @@ -22,7 +21,6 @@ export const metricsSourceConfigurationPropertiesRT = rt.strict({
metricAlias: SourceConfigurationRT.props.metricAlias,
inventoryDefaultView: SourceConfigurationRT.props.inventoryDefaultView,
metricsExplorerDefaultView: SourceConfigurationRT.props.metricsExplorerDefaultView,
fields: rt.strict(omit(SourceConfigurationRT.props.fields.props, 'message')),
anomalyThreshold: rt.number,
});

Expand All @@ -32,9 +30,6 @@ export type MetricsSourceConfigurationProperties = rt.TypeOf<

export const partialMetricsSourceConfigurationPropertiesRT = rt.partial({
...metricsSourceConfigurationPropertiesRT.type.props,
fields: rt.partial({
...metricsSourceConfigurationPropertiesRT.type.props.fields.type.props,
}),
});

export type PartialMetricsSourceConfigurationProperties = rt.TypeOf<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,7 @@ export const sourceConfigurationConfigFilePropertiesRT = rt.type({
sources: rt.type({
default: rt.partial({
fields: rt.partial({
timestamp: rt.string,
message: rt.array(rt.string),
tiebreaker: rt.string,
host: rt.string,
container: rt.string,
pod: rt.string,
}),
}),
}),
Expand Down Expand Up @@ -113,11 +108,6 @@ export type InfraSourceConfigurationColumn = rt.TypeOf<typeof SourceConfiguratio
*/

const SourceConfigurationFieldsRT = rt.type({
container: rt.string,
host: rt.string,
pod: rt.string,
tiebreaker: rt.string,
timestamp: rt.string,
message: rt.array(rt.string),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ describe('ExpressionChart', () => {
metricAlias: 'metricbeat-*',
inventoryDefaultView: 'host',
metricsExplorerDefaultView: 'host',
// @ts-ignore
fields: {
timestamp: '@timestamp',
container: 'container.id',
host: 'host.name',
pod: 'kubernetes.pod.uid',
tiebreaker: '_doc',
},
anomalyThreshold: 20,
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ export const createBasicSourceConfiguration = (sourceId: string): LogSourceConfi
},
logColumns: [],
fields: {
container: 'CONTAINER_FIELD',
host: 'HOST_FIELD',
pod: 'POD_FIELD',
tiebreaker: 'TIEBREAKER_FIELD',
timestamp: 'TIMESTAMP_FIELD',
message: ['MESSAGE_FIELD'],
},
name: sourceId,
Expand Down
5 changes: 2 additions & 3 deletions x-pack/plugins/infra/public/containers/ml/infra_ml_module.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const useInfraMLModule = <JobType extends string>({
moduleDescriptor: ModuleDescriptor<JobType>;
}) => {
const { services } = useKibanaContextForPlugin();
const { spaceId, sourceId, timestampField } = sourceConfiguration;
const { spaceId, sourceId } = sourceConfiguration;
const [moduleStatus, dispatchModuleStatus] = useModuleStatus(moduleDescriptor.jobTypes);

const [, fetchJobStatus] = useTrackedPromise(
Expand Down Expand Up @@ -64,7 +64,6 @@ export const useInfraMLModule = <JobType extends string>({
indices: selectedIndices,
sourceId,
spaceId,
timestampField,
},
partitionField,
},
Expand All @@ -91,7 +90,7 @@ export const useInfraMLModule = <JobType extends string>({
dispatchModuleStatus({ type: 'failedSetup' });
},
},
[moduleDescriptor.setUpModule, spaceId, sourceId, timestampField]
[moduleDescriptor.setUpModule, spaceId, sourceId]
);

const [cleanUpModuleRequest, cleanUpModule] = useTrackedPromise(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ export const isJobConfigurationOutdated =
isSubset(
new Set(jobConfiguration.indexPattern.split(',')),
new Set(currentSourceConfiguration.indices)
) &&
jobConfiguration.timestampField === currentSourceConfiguration.timestampField
)
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@ export interface ModuleDescriptor<JobType extends string> {
) => Promise<DeleteJobsResponsePayload>;
validateSetupIndices?: (
indices: string[],
timestampField: string,
fetch: HttpHandler
) => Promise<ValidationIndicesResponsePayload>;
validateSetupDatasets?: (
indices: string[],
timestampField: string,
startTime: number,
endTime: number,
fetch: HttpHandler
Expand All @@ -65,7 +63,6 @@ export interface ModuleSourceConfiguration {
indices: string[];
sourceId: string;
spaceId: string;
timestampField: string;
}

interface ManyCategoriesWarningReason {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,18 @@ export const useMetricHostsModule = ({
indexPattern,
sourceId,
spaceId,
timestampField,
}: {
indexPattern: string;
sourceId: string;
spaceId: string;
timestampField: string;
}) => {
const sourceConfiguration: ModuleSourceConfiguration = useMemo(
() => ({
indices: indexPattern.split(','),
sourceId,
spaceId,
timestampField,
}),
[indexPattern, sourceId, spaceId, timestampField]
[indexPattern, sourceId, spaceId]
);

const infraMLModule = useInfraMLModule({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
MetricsHostsJobType,
bucketSpan,
} from '../../../../../common/infra_ml';
import { TIMESTAMP_FIELD } from '../../../../../common/constants';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import MemoryJob from '../../../../../../ml/server/models/data_recognizer/modules/metrics_ui_hosts/ml/hosts_memory_usage.json';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
Expand Down Expand Up @@ -68,7 +69,7 @@ const setUpModule = async (setUpModuleArgs: SetUpModuleArgs, fetch: HttpHandler)
start,
end,
filter,
moduleSourceConfiguration: { spaceId, sourceId, indices, timestampField },
moduleSourceConfiguration: { spaceId, sourceId, indices },
partitionField,
} = setUpModuleArgs;

Expand All @@ -93,13 +94,13 @@ const setUpModule = async (setUpModuleArgs: SetUpModuleArgs, fetch: HttpHandler)
return {
job_id: id,
data_description: {
time_field: timestampField,
time_field: TIMESTAMP_FIELD,
},
analysis_config,
custom_settings: {
metrics_source_config: {
indexPattern: indexNamePattern,
timestampField,
timestampField: TIMESTAMP_FIELD,
bucketSpan,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,18 @@ export const useMetricK8sModule = ({
indexPattern,
sourceId,
spaceId,
timestampField,
}: {
indexPattern: string;
sourceId: string;
spaceId: string;
timestampField: string;
}) => {
const sourceConfiguration: ModuleSourceConfiguration = useMemo(
() => ({
indices: indexPattern.split(','),
sourceId,
spaceId,
timestampField,
}),
[indexPattern, sourceId, spaceId, timestampField]
[indexPattern, sourceId, spaceId]
);

const infraMLModule = useInfraMLModule({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
MetricK8sJobType,
bucketSpan,
} from '../../../../../common/infra_ml';
import { TIMESTAMP_FIELD } from '../../../../../common/constants';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import MemoryJob from '../../../../../../ml/server/models/data_recognizer/modules/metrics_ui_k8s/ml/k8s_memory_usage.json';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
Expand Down Expand Up @@ -69,7 +70,7 @@ const setUpModule = async (setUpModuleArgs: SetUpModuleArgs, fetch: HttpHandler)
start,
end,
filter,
moduleSourceConfiguration: { spaceId, sourceId, indices, timestampField },
moduleSourceConfiguration: { spaceId, sourceId, indices },
partitionField,
} = setUpModuleArgs;

Expand All @@ -93,13 +94,13 @@ const setUpModule = async (setUpModuleArgs: SetUpModuleArgs, fetch: HttpHandler)
return {
job_id: id,
data_description: {
time_field: timestampField,
time_field: TIMESTAMP_FIELD,
},
analysis_config,
custom_settings: {
metrics_source_config: {
indexPattern: indexNamePattern,
timestampField,
timestampField: TIMESTAMP_FIELD,
bucketSpan,
},
},
Expand Down
Loading

0 comments on commit 6693ef3

Please sign in to comment.