Skip to content

Commit

Permalink
Fix types, delete dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipb committed Oct 1, 2020
1 parent 17f6378 commit f14915d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 367 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ export interface ModuleDescriptor<JobType extends string> {
partitionField?: string
) => Promise<SetupMlModuleResponsePayload>;
cleanUpModule: (spaceId: string, sourceId: string) => Promise<DeleteJobsResponsePayload>;
validateSetupIndices: (
validateSetupIndices?: (
indices: string[],
timestampField: string
) => Promise<ValidationIndicesResponsePayload>;
validateSetupDatasets: (
validateSetupDatasets?: (
indices: string[],
timestampField: string,
startTime: number,
Expand Down
289 changes: 0 additions & 289 deletions x-pack/plugins/infra/public/containers/ml/infra_ml_setup_state.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ import { cleanUpJobsAndDatafeeds } from '../../infra_ml_cleanup';
import { callJobsSummaryAPI } from '../../api/ml_get_jobs_summary_api';
import { callGetMlModuleAPI } from '../../api/ml_get_module';
import { callSetupMlModuleAPI } from '../../api/ml_setup_module_api';
import { callValidateIndicesAPI } from '../../../logs/log_analysis/api/validate_indices';
import { callValidateDatasetsAPI } from '../../../logs/log_analysis/api/validate_datasets';
import {
metricsHostsJobTypes,
getJobId,
MetricsHostsJobType,
DatasetFilter,
bucketSpan,
partitionField,
} from '../../../../../common/infra_ml';
// 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';
Expand Down Expand Up @@ -67,7 +64,7 @@ const setUpModule = async (
end: number | undefined,
datasetFilter: DatasetFilter,
{ spaceId, sourceId, indices, timestampField }: ModuleSourceConfiguration,
pField?: string
partitionField?: string
) => {
const indexNamePattern = indices.join(',');
const jobIds: JobType[] = ['hosts_memory_usage', 'hosts_network_in', 'hosts_network_out'];
Expand All @@ -80,10 +77,10 @@ const setUpModule = async (
...defaultJobConfig.analysis_config,
};

if (pField) {
analysis_config.detectors[0].partition_field_name = pField;
if (analysis_config.influencers.indexOf(pField) === -1) {
analysis_config.influencers.push(pField);
if (partitionField) {
analysis_config.detectors[0].partition_field_name = partitionField;
if (analysis_config.influencers.indexOf(partitionField) === -1) {
analysis_config.influencers.push(partitionField);
}
}

Expand All @@ -106,16 +103,16 @@ const setUpModule = async (
const datafeedOverrides = jobIds.map((id) => {
const { datafeed: defaultDatafeedConfig } = getDefaultJobConfigs(id);

if (!pField || id === 'hosts_memory_usage') {
if (!partitionField || id === 'hosts_memory_usage') {
// Since the host memory usage doesn't have custom aggs, we don't need to do anything to add a partition field
return defaultDatafeedConfig;
}

// If we have a partition field, we need to change the aggregation to do a terms agg at the top level
const aggregations = {
[pField]: {
[partitionField]: {
terms: {
field: pField,
field: partitionField,
},
aggregations: {
...defaultDatafeedConfig.aggregations,
Expand Down Expand Up @@ -166,28 +163,6 @@ const cleanUpModule = async (spaceId: string, sourceId: string) => {
return await cleanUpJobsAndDatafeeds(spaceId, sourceId, metricsHostsJobTypes);
};

const validateSetupIndices = async (indices: string[], timestampField: string) => {
return await callValidateIndicesAPI(indices, [
{
name: timestampField,
validTypes: ['date'],
},
{
name: partitionField,
validTypes: ['keyword'],
},
]);
};

const validateSetupDatasets = async (
indices: string[],
timestampField: string,
startTime: number,
endTime: number
) => {
return await callValidateDatasetsAPI(indices, timestampField, startTime, endTime);
};

export const metricHostsModule: ModuleDescriptor<MetricsHostsJobType> = {
moduleId,
moduleName,
Expand All @@ -199,6 +174,4 @@ export const metricHostsModule: ModuleDescriptor<MetricsHostsJobType> = {
getModuleDefinition,
setUpModule,
cleanUpModule,
validateSetupDatasets,
validateSetupIndices,
};
Loading

0 comments on commit f14915d

Please sign in to comment.