Skip to content

Commit 32075b6

Browse files
committed
Remove most job specifics from setup state hook
1 parent 222df2a commit 32075b6

File tree

4 files changed

+181
-116
lines changed

4 files changed

+181
-116
lines changed

x-pack/legacy/plugins/infra/public/containers/logs/log_analysis/api/ml_setup_module_api.ts

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { kfetch } from 'ui/kfetch';
1212

1313
import { throwErrors, createPlainError } from '../../../../../common/runtime_types';
1414
import { getJobIdPrefix } from '../../../../../common/log_analysis';
15-
import { jobCustomSettingsRT } from './ml_api_types';
15+
// import { jobCustomSettingsRT } from './ml_api_types';
1616

1717
export const callSetupMlModuleAPI = async (
1818
moduleId: string,
@@ -21,8 +21,8 @@ export const callSetupMlModuleAPI = async (
2121
spaceId: string,
2222
sourceId: string,
2323
indexPattern: string,
24-
timeField: string,
25-
bucketSpan: number
24+
jobOverrides: SetupMlModuleJobOverrides[] = [],
25+
datafeedOverrides: SetupMlModuleDatafeedOverrides[] = []
2626
) => {
2727
const response = await kfetch({
2828
method: 'POST',
@@ -34,25 +34,27 @@ export const callSetupMlModuleAPI = async (
3434
indexPatternName: indexPattern,
3535
prefix: getJobIdPrefix(spaceId, sourceId),
3636
startDatafeed: true,
37-
jobOverrides: [
38-
{
39-
job_id: 'log-entry-rate' as const,
40-
analysis_config: {
41-
bucket_span: `${bucketSpan}ms`,
42-
},
43-
data_description: {
44-
time_field: timeField,
45-
},
46-
custom_settings: {
47-
logs_source_config: {
48-
indexPattern,
49-
timestampField: timeField,
50-
bucketSpan,
51-
},
52-
},
53-
},
54-
],
55-
datafeedOverrides: [],
37+
jobOverrides,
38+
datafeedOverrides,
39+
// jobOverrides: [
40+
// {
41+
// job_id: 'log-entry-rate' as const,
42+
// analysis_config: {
43+
// bucket_span: `${bucketSpan}ms`,
44+
// },
45+
// data_description: {
46+
// time_field: timeField,
47+
// },
48+
// custom_settings: {
49+
// logs_source_config: {
50+
// indexPattern,
51+
// timestampField: timeField,
52+
// bucketSpan,
53+
// },
54+
// },
55+
// },
56+
// ],
57+
// datafeedOverrides: [],
5658
})
5759
),
5860
});
@@ -68,23 +70,30 @@ const setupMlModuleTimeParamsRT = rt.partial({
6870
end: rt.number,
6971
});
7072

71-
const setupMlModuleLogEntryRateJobOverridesRT = rt.type({
72-
job_id: rt.literal('log-entry-rate'),
73-
analysis_config: rt.type({
74-
bucket_span: rt.string,
75-
}),
76-
data_description: rt.type({
77-
time_field: rt.string,
78-
}),
79-
custom_settings: jobCustomSettingsRT,
80-
});
73+
const setupMlModuleJobOverridesRT = rt.object;
74+
75+
type SetupMlModuleJobOverrides = rt.TypeOf<typeof setupMlModuleJobOverridesRT>;
76+
77+
const setupMlModuleDatafeedOverridesRT = rt.object;
78+
79+
type SetupMlModuleDatafeedOverrides = rt.TypeOf<typeof setupMlModuleDatafeedOverridesRT>;
80+
// const setupMlModuleLogEntryRateJobOverridesRT = rt.type({
81+
// job_id: rt.literal('log-entry-rate'),
82+
// analysis_config: rt.type({
83+
// bucket_span: rt.string,
84+
// }),
85+
// data_description: rt.type({
86+
// time_field: rt.string,
87+
// }),
88+
// custom_settings: jobCustomSettingsRT,
89+
// });
8190

8291
const setupMlModuleRequestParamsRT = rt.type({
8392
indexPatternName: rt.string,
8493
prefix: rt.string,
8594
startDatafeed: rt.boolean,
86-
jobOverrides: rt.array(setupMlModuleLogEntryRateJobOverridesRT),
87-
datafeedOverrides: rt.array(rt.object),
95+
jobOverrides: rt.array(setupMlModuleJobOverridesRT),
96+
datafeedOverrides: rt.array(setupMlModuleDatafeedOverridesRT),
8897
});
8998

9099
const setupMlModuleRequestPayloadRT = rt.intersection([

x-pack/legacy/plugins/infra/public/containers/logs/log_analysis/log_analysis_jobs.tsx

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@ export const useLogAnalysisJobs = <JobType extends string>({
2020
moduleId,
2121
sourceId,
2222
spaceId,
23-
timeField,
23+
jobParameters,
2424
}: {
2525
indexPattern: string;
2626
jobTypes: JobType[];
2727
moduleId: string;
2828
sourceId: string;
2929
spaceId: string;
30-
timeField: string;
30+
jobParameters: { timestampField: string };
3131
}) => {
3232
const { cleanupMLResources } = useLogAnalysisCleanup({ sourceId, spaceId });
33-
const [statusState, dispatch] = useStatusState({
33+
const [statusState, dispatch] = useStatusState(jobTypes, {
3434
bucketSpan,
3535
indexPattern,
36-
timestampField: timeField,
36+
timestampField: jobParameters.timestampField,
3737
});
3838

3939
const [fetchModuleDefinitionRequest, fetchModuleDefinition] = useTrackedPromise(
@@ -74,8 +74,25 @@ export const useLogAnalysisJobs = <JobType extends string>({
7474
spaceId,
7575
sourceId,
7676
indices.join(','),
77-
timeField,
78-
bucketSpan
77+
[
78+
{
79+
job_id: 'log-entry-rate' as const,
80+
analysis_config: {
81+
bucket_span: `${bucketSpan}ms`,
82+
},
83+
data_description: {
84+
time_field: jobParameters.timestampField,
85+
},
86+
custom_settings: {
87+
logs_source_config: {
88+
indexPattern,
89+
timestampField: jobParameters.timestampField,
90+
bucketSpan,
91+
},
92+
},
93+
},
94+
],
95+
[]
7996
);
8097
},
8198
onResolve: ({ datafeeds, jobs }: SetupMlModuleResponsePayload) => {
@@ -85,7 +102,7 @@ export const useLogAnalysisJobs = <JobType extends string>({
85102
dispatch({ type: 'failedSetup' });
86103
},
87104
},
88-
[spaceId, sourceId, timeField, bucketSpan]
105+
[spaceId, sourceId, jobParameters.timestampField, bucketSpan]
89106
);
90107

91108
const [fetchJobStatusRequest, fetchJobStatus] = useTrackedPromise(

0 commit comments

Comments
 (0)