-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add empty analysis tab * Add ml capabilities check * Add job status checking functionality * Add a loading page for the job status check * Change types / change method for deriving space ID / change setup requirement filtering check * Use new structure * Change tab syntax * i18n translate message prop * Fix import
- Loading branch information
Showing
15 changed files
with
468 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...k/legacy/plugins/infra/public/containers/logs/log_analysis/api/ml_get_jobs_summary_api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import * as rt from 'io-ts'; | ||
import { kfetch } from 'ui/kfetch'; | ||
import { getJobId } from '../../../../../common/log_analysis'; | ||
import { throwErrors, createPlainError } from '../../../../../common/runtime_types'; | ||
|
||
export const callJobsSummaryAPI = async (spaceId: string, sourceId: string) => { | ||
const response = await kfetch({ | ||
method: 'POST', | ||
pathname: '/api/ml/jobs/jobs_summary', | ||
body: JSON.stringify( | ||
fetchJobStatusRequestPayloadRT.encode({ | ||
jobIds: [getJobId(spaceId, sourceId, 'log-entry-rate')], | ||
}) | ||
), | ||
}); | ||
return fetchJobStatusResponsePayloadRT.decode(response).getOrElseL(throwErrors(createPlainError)); | ||
}; | ||
|
||
export const fetchJobStatusRequestPayloadRT = rt.type({ | ||
jobIds: rt.array(rt.string), | ||
}); | ||
|
||
export type FetchJobStatusRequestPayload = rt.TypeOf<typeof fetchJobStatusRequestPayloadRT>; | ||
|
||
// TODO: Get this to align with the payload - something is tripping it up somewhere | ||
// export const fetchJobStatusResponsePayloadRT = rt.array(rt.type({ | ||
// datafeedId: rt.string, | ||
// datafeedIndices: rt.array(rt.string), | ||
// datafeedState: rt.string, | ||
// description: rt.string, | ||
// earliestTimestampMs: rt.number, | ||
// groups: rt.array(rt.string), | ||
// hasDatafeed: rt.boolean, | ||
// id: rt.string, | ||
// isSingleMetricViewerJob: rt.boolean, | ||
// jobState: rt.string, | ||
// latestResultsTimestampMs: rt.number, | ||
// latestTimestampMs: rt.number, | ||
// memory_status: rt.string, | ||
// nodeName: rt.union([rt.string, rt.undefined]), | ||
// processed_record_count: rt.number, | ||
// fullJob: rt.any, | ||
// auditMessage: rt.any, | ||
// deleting: rt.union([rt.boolean, rt.undefined]), | ||
// })); | ||
|
||
export const fetchJobStatusResponsePayloadRT = rt.any; | ||
|
||
export type FetchJobStatusResponsePayload = rt.TypeOf<typeof fetchJobStatusResponsePayloadRT>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...ck/legacy/plugins/infra/public/containers/logs/log_analysis/log_analysis_capabilities.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { useMemo, useState, useEffect } from 'react'; | ||
import { kfetch } from 'ui/kfetch'; | ||
|
||
import { useTrackedPromise } from '../../../utils/use_tracked_promise'; | ||
import { | ||
getMlCapabilitiesResponsePayloadRT, | ||
GetMlCapabilitiesResponsePayload, | ||
} from './ml_api_types'; | ||
import { throwErrors, createPlainError } from '../../../../common/runtime_types'; | ||
|
||
export const useLogAnalysisCapabilities = () => { | ||
const [mlCapabilities, setMlCapabilities] = useState<GetMlCapabilitiesResponsePayload>( | ||
initialMlCapabilities | ||
); | ||
|
||
const [fetchMlCapabilitiesRequest, fetchMlCapabilities] = useTrackedPromise( | ||
{ | ||
cancelPreviousOn: 'resolution', | ||
createPromise: async () => { | ||
const rawResponse = await kfetch({ | ||
method: 'GET', | ||
pathname: '/api/ml/ml_capabilities', | ||
}); | ||
|
||
return getMlCapabilitiesResponsePayloadRT | ||
.decode(rawResponse) | ||
.getOrElseL(throwErrors(createPlainError)); | ||
}, | ||
onResolve: response => { | ||
setMlCapabilities(response); | ||
}, | ||
}, | ||
[] | ||
); | ||
|
||
useEffect(() => { | ||
fetchMlCapabilities(); | ||
}, []); | ||
|
||
const isLoading = useMemo(() => fetchMlCapabilitiesRequest.state === 'pending', [ | ||
fetchMlCapabilitiesRequest.state, | ||
]); | ||
|
||
return { | ||
hasLogAnalysisCapabilites: mlCapabilities.capabilities.canCreateJob, | ||
isLoading, | ||
}; | ||
}; | ||
|
||
const initialMlCapabilities = { | ||
capabilities: { | ||
canGetJobs: false, | ||
canCreateJob: false, | ||
canDeleteJob: false, | ||
canOpenJob: false, | ||
canCloseJob: false, | ||
canForecastJob: false, | ||
canGetDatafeeds: false, | ||
canStartStopDatafeed: false, | ||
canUpdateJob: false, | ||
canUpdateDatafeed: false, | ||
canPreviewDatafeed: false, | ||
canGetCalendars: false, | ||
canCreateCalendar: false, | ||
canDeleteCalendar: false, | ||
canGetFilters: false, | ||
canCreateFilter: false, | ||
canDeleteFilter: false, | ||
canFindFileStructure: false, | ||
canGetDataFrameJobs: false, | ||
canDeleteDataFrameJob: false, | ||
canPreviewDataFrameJob: false, | ||
canCreateDataFrameJob: false, | ||
canStartStopDataFrameJob: false, | ||
}, | ||
isPlatinumOrTrialLicense: false, | ||
mlFeatureEnabledInSpace: false, | ||
upgradeInProgress: false, | ||
}; |
97 changes: 97 additions & 0 deletions
97
x-pack/legacy/plugins/infra/public/containers/logs/log_analysis/log_analysis_jobs.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import createContainer from 'constate-latest'; | ||
import { useMemo, useEffect, useState } from 'react'; | ||
import { values } from 'lodash'; | ||
import { getJobId } from '../../../../common/log_analysis'; | ||
import { useTrackedPromise } from '../../../utils/use_tracked_promise'; | ||
import { callJobsSummaryAPI } from './api/ml_get_jobs_summary_api'; | ||
|
||
type JobStatus = 'unknown' | 'closed' | 'closing' | 'failed' | 'opened' | 'opening' | 'deleted'; | ||
// type DatafeedStatus = 'unknown' | 'started' | 'starting' | 'stopped' | 'stopping' | 'deleted'; | ||
|
||
export const useLogAnalysisJobs = ({ | ||
indexPattern, | ||
sourceId, | ||
spaceId, | ||
}: { | ||
indexPattern: string; | ||
sourceId: string; | ||
spaceId: string; | ||
}) => { | ||
const [jobStatus, setJobStatus] = useState<{ | ||
logEntryRate: JobStatus; | ||
}>({ | ||
logEntryRate: 'unknown', | ||
}); | ||
|
||
// const [setupMlModuleRequest, setupMlModule] = useTrackedPromise( | ||
// { | ||
// cancelPreviousOn: 'resolution', | ||
// createPromise: async () => { | ||
// kfetch({ | ||
// method: 'POST', | ||
// pathname: '/api/ml/modules/setup', | ||
// body: JSON.stringify( | ||
// setupMlModuleRequestPayloadRT.encode({ | ||
// indexPatternName: indexPattern, | ||
// prefix: getJobIdPrefix(spaceId, sourceId), | ||
// startDatafeed: true, | ||
// }) | ||
// ), | ||
// }); | ||
// }, | ||
// }, | ||
// [indexPattern, spaceId, sourceId] | ||
// ); | ||
|
||
const [fetchJobStatusRequest, fetchJobStatus] = useTrackedPromise( | ||
{ | ||
cancelPreviousOn: 'resolution', | ||
createPromise: async () => { | ||
return callJobsSummaryAPI(spaceId, sourceId); | ||
}, | ||
onResolve: response => { | ||
if (response && response.length) { | ||
const logEntryRate = response.find( | ||
(job: any) => job.id === getJobId(spaceId, sourceId, 'log-entry-rate') | ||
); | ||
setJobStatus({ | ||
logEntryRate: logEntryRate ? logEntryRate.jobState : 'unknown', | ||
}); | ||
} | ||
}, | ||
onReject: error => { | ||
// TODO: Handle errors | ||
}, | ||
}, | ||
[indexPattern, spaceId, sourceId] | ||
); | ||
|
||
useEffect(() => { | ||
fetchJobStatus(); | ||
}, []); | ||
|
||
const isSetupRequired = useMemo(() => { | ||
const jobStates = values(jobStatus); | ||
return ( | ||
jobStates.filter(state => state === 'opened' || state === 'opening').length < jobStates.length | ||
); | ||
}, [jobStatus]); | ||
|
||
const isLoadingSetupStatus = useMemo(() => fetchJobStatusRequest.state === 'pending', [ | ||
fetchJobStatusRequest.state, | ||
]); | ||
|
||
return { | ||
jobStatus, | ||
isSetupRequired, | ||
isLoadingSetupStatus, | ||
}; | ||
}; | ||
|
||
export const LogAnalysisJobs = createContainer(useLogAnalysisJobs); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
x-pack/legacy/plugins/infra/public/containers/logs/log_analysis/ml_api_types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import * as rt from 'io-ts'; | ||
|
||
export const getMlCapabilitiesResponsePayloadRT = rt.type({ | ||
capabilities: rt.type({ | ||
canGetJobs: rt.boolean, | ||
canCreateJob: rt.boolean, | ||
canDeleteJob: rt.boolean, | ||
canOpenJob: rt.boolean, | ||
canCloseJob: rt.boolean, | ||
canForecastJob: rt.boolean, | ||
canGetDatafeeds: rt.boolean, | ||
canStartStopDatafeed: rt.boolean, | ||
canUpdateJob: rt.boolean, | ||
canUpdateDatafeed: rt.boolean, | ||
canPreviewDatafeed: rt.boolean, | ||
}), | ||
isPlatinumOrTrialLicense: rt.boolean, | ||
mlFeatureEnabledInSpace: rt.boolean, | ||
upgradeInProgress: rt.boolean, | ||
}); | ||
|
||
export type GetMlCapabilitiesResponsePayload = rt.TypeOf<typeof getMlCapabilitiesResponsePayloadRT>; |
7 changes: 7 additions & 0 deletions
7
x-pack/legacy/plugins/infra/public/pages/logs/analysis/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export * from './page'; |
44 changes: 44 additions & 0 deletions
44
x-pack/legacy/plugins/infra/public/pages/logs/analysis/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { useContext } from 'react'; | ||
import chrome from 'ui/chrome'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { ColumnarPage } from '../../../components/page'; | ||
import { LoadingPage } from '../../../components/loading_page'; | ||
import { AnalysisPageProviders } from './page_providers'; | ||
import { AnalysisResultsContent } from './page_results_content'; | ||
import { AnalysisSetupContent } from './page_setup_content'; | ||
import { useLogAnalysisJobs } from '../../../containers/logs/log_analysis/log_analysis_jobs'; | ||
import { Source } from '../../../containers/source'; | ||
|
||
export const AnalysisPage = () => { | ||
const { sourceId, source } = useContext(Source.Context); | ||
const spaceId = chrome.getInjected('activeSpace').space.id; | ||
const { isSetupRequired, isLoadingSetupStatus } = useLogAnalysisJobs({ | ||
indexPattern: source ? source.configuration.logAlias : '', | ||
sourceId, | ||
spaceId, | ||
}); | ||
|
||
return ( | ||
<AnalysisPageProviders> | ||
<ColumnarPage data-test-subj="infraLogsAnalysisPage"> | ||
{isLoadingSetupStatus ? ( | ||
<LoadingPage | ||
message={i18n.translate('xpack.infra.logs.analysisPage.loadingMessage', { | ||
defaultMessage: 'Checking status of analysis jobs...', | ||
})} | ||
/> | ||
) : isSetupRequired ? ( | ||
<AnalysisSetupContent /> | ||
) : ( | ||
<AnalysisResultsContent /> | ||
)} | ||
</ColumnarPage> | ||
</AnalysisPageProviders> | ||
); | ||
}; |
17 changes: 17 additions & 0 deletions
17
x-pack/legacy/plugins/infra/public/pages/logs/analysis/page_providers.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { Source, useSource } from '../../../containers/source'; | ||
import { useSourceId } from '../../../containers/source_id'; | ||
|
||
export const AnalysisPageProviders: React.FunctionComponent = ({ children }) => { | ||
const [sourceId] = useSourceId(); | ||
const source = useSource({ sourceId }); | ||
|
||
return <Source.Context.Provider value={source}>{children}</Source.Context.Provider>; | ||
}; |
16 changes: 16 additions & 0 deletions
16
x-pack/legacy/plugins/infra/public/pages/logs/analysis/page_results_content.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { useTrackPageview } from '../../../hooks/use_track_metric'; | ||
|
||
export const AnalysisResultsContent = () => { | ||
useTrackPageview({ app: 'infra_logs', path: 'analysis_results' }); | ||
useTrackPageview({ app: 'infra_logs', path: 'analysis_results', delay: 15000 }); | ||
|
||
return <div>Results</div>; | ||
}; |
16 changes: 16 additions & 0 deletions
16
x-pack/legacy/plugins/infra/public/pages/logs/analysis/page_setup_content.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { useTrackPageview } from '../../../hooks/use_track_metric'; | ||
|
||
export const AnalysisSetupContent = () => { | ||
useTrackPageview({ app: 'infra_logs', path: 'analysis_setup' }); | ||
useTrackPageview({ app: 'infra_logs', path: 'analysis_setup', delay: 15000 }); | ||
|
||
return <div>Setup</div>; | ||
}; |
Oops, something went wrong.