Skip to content

Commit

Permalink
Move job overrides out of the generic jobs hook
Browse files Browse the repository at this point in the history
  • Loading branch information
weltenwort committed Nov 21, 2019
1 parent 4aea65e commit 02aa0e2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { kfetch } from 'ui/kfetch';

import { throwErrors, createPlainError } from '../../../../../common/runtime_types';
import { getJobIdPrefix } from '../../../../../common/log_analysis';
// import { jobCustomSettingsRT } from './ml_api_types';

export const callSetupMlModuleAPI = async (
moduleId: string,
Expand All @@ -36,25 +35,6 @@ export const callSetupMlModuleAPI = async (
startDatafeed: true,
jobOverrides,
datafeedOverrides,
// jobOverrides: [
// {
// job_id: 'log-entry-rate' as const,
// analysis_config: {
// bucket_span: `${bucketSpan}ms`,
// },
// data_description: {
// time_field: timeField,
// },
// custom_settings: {
// logs_source_config: {
// indexPattern,
// timestampField: timeField,
// bucketSpan,
// },
// },
// },
// ],
// datafeedOverrides: [],
})
),
});
Expand All @@ -72,21 +52,11 @@ const setupMlModuleTimeParamsRT = rt.partial({

const setupMlModuleJobOverridesRT = rt.object;

type SetupMlModuleJobOverrides = rt.TypeOf<typeof setupMlModuleJobOverridesRT>;
export type SetupMlModuleJobOverrides = rt.TypeOf<typeof setupMlModuleJobOverridesRT>;

const setupMlModuleDatafeedOverridesRT = rt.object;

type SetupMlModuleDatafeedOverrides = rt.TypeOf<typeof setupMlModuleDatafeedOverridesRT>;
// const setupMlModuleLogEntryRateJobOverridesRT = rt.type({
// job_id: rt.literal('log-entry-rate'),
// analysis_config: rt.type({
// bucket_span: rt.string,
// }),
// data_description: rt.type({
// time_field: rt.string,
// }),
// custom_settings: jobCustomSettingsRT,
// });
export type SetupMlModuleDatafeedOverrides = rt.TypeOf<typeof setupMlModuleDatafeedOverridesRT>;

const setupMlModuleRequestParamsRT = rt.type({
indexPatternName: rt.string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,36 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { useMemo, useCallback } from 'react';
import { useCallback, useMemo } from 'react';

import { callGetMlModuleAPI } from './api/ml_get_module';
import { bucketSpan, getJobId } from '../../../../common/log_analysis';
import { getJobId } from '../../../../common/log_analysis';
import { useTrackedPromise } from '../../../utils/use_tracked_promise';
import { callJobsSummaryAPI } from './api/ml_get_jobs_summary_api';
import { callSetupMlModuleAPI, SetupMlModuleResponsePayload } from './api/ml_setup_module_api';
import { callGetMlModuleAPI } from './api/ml_get_module';
import {
callSetupMlModuleAPI,
SetupMlModuleDatafeedOverrides,
SetupMlModuleJobOverrides,
SetupMlModuleResponsePayload,
} from './api/ml_setup_module_api';
import { useLogAnalysisCleanup } from './log_analysis_cleanup';
import { useStatusState } from './log_analysis_status_state';

export const useLogAnalysisJobs = <JobType extends string>({
bucketSpan,
datafeedOverrides,
indexPattern,
jobOverrides,
jobTypes,
moduleId,
sourceId,
spaceId,
timestampField,
}: {
bucketSpan: number;
datafeedOverrides: SetupMlModuleDatafeedOverrides[];
indexPattern: string;
jobOverrides: SetupMlModuleJobOverrides[];
jobTypes: JobType[];
moduleId: string;
sourceId: string;
Expand Down Expand Up @@ -74,25 +85,8 @@ export const useLogAnalysisJobs = <JobType extends string>({
spaceId,
sourceId,
indices.join(','),
[
{
job_id: 'log-entry-rate' as const,
analysis_config: {
bucket_span: `${bucketSpan}ms`,
},
data_description: {
time_field: timestampField,
},
custom_settings: {
logs_source_config: {
indexPattern,
timestampField,
bucketSpan,
},
},
},
],
[]
jobOverrides,
datafeedOverrides
);
},
onResolve: ({ datafeeds, jobs }: SetupMlModuleResponsePayload) => {
Expand All @@ -102,7 +96,7 @@ export const useLogAnalysisJobs = <JobType extends string>({
dispatch({ type: 'failedSetup' });
},
},
[moduleId, spaceId, sourceId, timestampField, bucketSpan]
[moduleId, spaceId, sourceId, timestampField, bucketSpan, jobOverrides, datafeedOverrides]
);

const [fetchJobStatusRequest, fetchJobStatus] = useTrackedPromise(
Expand All @@ -115,7 +109,7 @@ export const useLogAnalysisJobs = <JobType extends string>({
onResolve: response => {
dispatch({ type: 'fetchedJobStatuses', payload: response, spaceId, sourceId });
},
onReject: err => {
onReject: () => {
dispatch({ type: 'failedFetchingJobStatuses' });
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,6 @@ const getSetupStatus = <JobType extends string>(
) => (previousSetupStatus: SetupStatus) =>
Object.entries<JobStatus>(everyJobStatus).reduce<SetupStatus>(
(setupStatus, [jobType, jobStatus]) => {
// if (!jobTypeRT.is(jobType)) {
// return setupStatus;
// }

const jobId = getJobId(spaceId, sourceId, jobType);
const jobDefinition = jobDefinitions.find(({ id }) => id === jobType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
*/

import createContainer from 'constate';
import { useMemo } from 'react';

import { bucketSpan } from '../../../../common/log_analysis';
import { useLogAnalysisJobs } from '../../../containers/logs/log_analysis';

const jobTypes = ['log-entry-rate'];
Expand All @@ -21,8 +23,34 @@ export const useLogEntryRateJobs = ({
spaceId: string;
timeField: string;
}) => {
const jobOverrides = useMemo(
() => [
{
job_id: 'log-entry-rate' as const,
analysis_config: {
bucket_span: `${bucketSpan}ms`,
},
data_description: {
time_field: timeField,
},
custom_settings: {
logs_source_config: {
indexPattern,
timestampField: timeField,
bucketSpan,
},
},
},
],
[bucketSpan, timeField, indexPattern]
);
const datafeedOverrides = useMemo(() => [], []);

return useLogAnalysisJobs({
bucketSpan,
datafeedOverrides,
indexPattern,
jobOverrides,
jobTypes,
moduleId: 'logs_ui_analysis',
sourceId,
Expand Down

0 comments on commit 02aa0e2

Please sign in to comment.