forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[7.x] [Logs UI] Add ML job results APIs (elastic#42356) (elastic#42932)
Backports the following commits to 7.x: - [Logs UI] Add ML job results APIs (elastic#42356)
- Loading branch information
1 parent
78abaf6
commit b03c1e1
Showing
40 changed files
with
1,246 additions
and
801 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
7 changes: 7 additions & 0 deletions
7
x-pack/legacy/plugins/infra/common/http_api/log_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 './results'; |
7 changes: 7 additions & 0 deletions
7
x-pack/legacy/plugins/infra/common/http_api/log_analysis/results/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 './log_entry_rate'; |
73 changes: 73 additions & 0 deletions
73
x-pack/legacy/plugins/infra/common/http_api/log_analysis/results/log_entry_rate.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,73 @@ | ||
/* | ||
* 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 { | ||
badRequestErrorRT, | ||
conflictErrorRT, | ||
forbiddenErrorRT, | ||
metricStatisticsRT, | ||
timeRangeRT, | ||
} from '../../shared'; | ||
|
||
export const LOG_ANALYSIS_GET_LOG_ENTRY_RATE_PATH = | ||
'/api/infra/log_analysis/results/log_entry_rate'; | ||
|
||
/** | ||
* request | ||
*/ | ||
|
||
export const getLogEntryRateRequestPayloadRT = rt.type({ | ||
data: rt.type({ | ||
bucketDuration: rt.number, | ||
sourceId: rt.string, | ||
timeRange: timeRangeRT, | ||
}), | ||
}); | ||
|
||
export type GetLogEntryRateRequestPayload = rt.TypeOf<typeof getLogEntryRateRequestPayloadRT>; | ||
|
||
/** | ||
* response | ||
*/ | ||
|
||
export const logEntryRateAnomaly = rt.type({ | ||
actualLogEntryRate: rt.number, | ||
anomalyScore: rt.number, | ||
duration: rt.number, | ||
startTime: rt.number, | ||
typicalLogEntryRate: rt.number, | ||
}); | ||
|
||
export const logEntryRateHistogramBucket = rt.type({ | ||
anomalies: rt.array(logEntryRateAnomaly), | ||
duration: rt.number, | ||
logEntryRateStats: metricStatisticsRT, | ||
modelLowerBoundStats: metricStatisticsRT, | ||
modelUpperBoundStats: metricStatisticsRT, | ||
startTime: rt.number, | ||
}); | ||
|
||
export const getLogEntryRateSuccessReponsePayloadRT = rt.type({ | ||
data: rt.type({ | ||
bucketDuration: rt.number, | ||
histogramBuckets: rt.array(logEntryRateHistogramBucket), | ||
}), | ||
}); | ||
|
||
export type GetLogEntryRateSuccessResponsePayload = rt.TypeOf< | ||
typeof getLogEntryRateSuccessReponsePayloadRT | ||
>; | ||
|
||
export const getLogEntryRateResponsePayloadRT = rt.union([ | ||
getLogEntryRateSuccessReponsePayloadRT, | ||
badRequestErrorRT, | ||
conflictErrorRT, | ||
forbiddenErrorRT, | ||
]); | ||
|
||
export type GetLogEntryRateReponsePayload = rt.TypeOf<typeof getLogEntryRateResponsePayloadRT>; |
37 changes: 0 additions & 37 deletions
37
x-pack/legacy/plugins/infra/common/http_api/search_results_api.ts
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
x-pack/legacy/plugins/infra/common/http_api/search_summary_api.ts
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
x-pack/legacy/plugins/infra/common/http_api/shared/errors.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,23 @@ | ||
/* | ||
* 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'; | ||
|
||
const createErrorRuntimeType = <Attributes extends rt.Mixed = rt.UndefinedType>( | ||
statusCode: number, | ||
errorCode: string, | ||
attributes?: Attributes | ||
) => | ||
rt.type({ | ||
statusCode: rt.literal(statusCode), | ||
error: rt.literal(errorCode), | ||
message: rt.string, | ||
...(!!attributes ? { attributes } : {}), | ||
}); | ||
|
||
export const badRequestErrorRT = createErrorRuntimeType(400, 'Bad Request'); | ||
export const forbiddenErrorRT = createErrorRuntimeType(403, 'Forbidden'); | ||
export const conflictErrorRT = createErrorRuntimeType(409, 'Conflict'); |
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,9 @@ | ||
/* | ||
* 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 './errors'; | ||
export * from './metric_statistics'; | ||
export * from './time_range'; |
15 changes: 15 additions & 0 deletions
15
x-pack/legacy/plugins/infra/common/http_api/shared/metric_statistics.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,15 @@ | ||
/* | ||
* 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 metricStatisticsRT = rt.type({ | ||
avg: rt.union([rt.number, rt.null]), | ||
count: rt.number, | ||
max: rt.union([rt.number, rt.null]), | ||
min: rt.union([rt.number, rt.null]), | ||
sum: rt.number, | ||
}); |
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
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,8 @@ | ||
/* | ||
* 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 './log_analysis'; | ||
export * from './job_parameters'; |
10 changes: 10 additions & 0 deletions
10
x-pack/legacy/plugins/infra/common/log_analysis/job_parameters.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,10 @@ | ||
/* | ||
* 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 { JobType } from './log_analysis'; | ||
|
||
export const getJobId = (spaceId: string, sourceId: string, jobType: JobType) => | ||
`kibana-logs-ui-${spaceId}-${sourceId}-${jobType}`; |
21 changes: 21 additions & 0 deletions
21
x-pack/legacy/plugins/infra/common/log_analysis/log_analysis.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,21 @@ | ||
/* | ||
* 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 jobTypeRT = rt.keyof({ | ||
'log-entry-rate': null, | ||
}); | ||
|
||
export type JobType = rt.TypeOf<typeof jobTypeRT>; | ||
|
||
export const jobStatusRT = rt.keyof({ | ||
created: null, | ||
missing: null, | ||
running: null, | ||
}); | ||
|
||
export type JobStatus = rt.TypeOf<typeof jobStatusRT>; |
7 changes: 7 additions & 0 deletions
7
x-pack/legacy/plugins/infra/public/containers/logs/log_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 './log_analysis_results'; |
23 changes: 23 additions & 0 deletions
23
x-pack/legacy/plugins/infra/public/containers/logs/log_analysis/log_analysis_results.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,23 @@ | ||
/* | ||
* 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/dist/ts/src'; | ||
import { useMemo } from 'react'; | ||
|
||
import { useLogEntryRate } from './log_entry_rate'; | ||
|
||
export const useLogAnalysisResults = ({ sourceId }: { sourceId: string }) => { | ||
const { isLoading: isLoadingLogEntryRate, logEntryRate } = useLogEntryRate({ sourceId }); | ||
|
||
const isLoading = useMemo(() => isLoadingLogEntryRate, [isLoadingLogEntryRate]); | ||
|
||
return { | ||
isLoading, | ||
logEntryRate, | ||
}; | ||
}; | ||
|
||
export const LogAnalysisResults = createContainer(useLogAnalysisResults); |
65 changes: 65 additions & 0 deletions
65
x-pack/legacy/plugins/infra/public/containers/logs/log_analysis/log_entry_rate.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,65 @@ | ||
/* | ||
* 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 } from 'react'; | ||
import { kfetch } from 'ui/kfetch'; | ||
|
||
import { | ||
getLogEntryRateRequestPayloadRT, | ||
getLogEntryRateSuccessReponsePayloadRT, | ||
GetLogEntryRateSuccessResponsePayload, | ||
LOG_ANALYSIS_GET_LOG_ENTRY_RATE_PATH, | ||
} from '../../../../common/http_api/log_analysis'; | ||
import { createPlainError, throwErrors } from '../../../../common/runtime_types'; | ||
import { useTrackedPromise } from '../../../utils/use_tracked_promise'; | ||
|
||
type LogEntryRateResults = GetLogEntryRateSuccessResponsePayload['data']; | ||
|
||
export const useLogEntryRate = ({ sourceId }: { sourceId: string }) => { | ||
const [logEntryRate, setLogEntryRate] = useState<LogEntryRateResults | null>(null); | ||
|
||
const [getLogEntryRateRequest, getLogEntryRate] = useTrackedPromise( | ||
{ | ||
cancelPreviousOn: 'resolution', | ||
createPromise: async () => { | ||
return await kfetch({ | ||
method: 'POST', | ||
pathname: LOG_ANALYSIS_GET_LOG_ENTRY_RATE_PATH, | ||
body: JSON.stringify( | ||
getLogEntryRateRequestPayloadRT.encode({ | ||
data: { | ||
sourceId, // TODO: get from hook arguments | ||
timeRange: { | ||
startTime: Date.now(), // TODO: get from hook arguments | ||
endTime: Date.now() + 1000 * 60 * 60, // TODO: get from hook arguments | ||
}, | ||
bucketDuration: 15 * 60 * 1000, // TODO: get from hook arguments | ||
}, | ||
}) | ||
), | ||
}); | ||
}, | ||
onResolve: response => { | ||
const { data } = getLogEntryRateSuccessReponsePayloadRT | ||
.decode(response) | ||
.getOrElseL(throwErrors(createPlainError)); | ||
|
||
setLogEntryRate(data); | ||
}, | ||
}, | ||
[sourceId] | ||
); | ||
|
||
const isLoading = useMemo(() => getLogEntryRateRequest.state === 'pending', [ | ||
getLogEntryRateRequest.state, | ||
]); | ||
|
||
return { | ||
getLogEntryRate, | ||
isLoading, | ||
logEntryRate, | ||
}; | ||
}; |
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
Oops, something went wrong.