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.
[APM] Offer users upgrade to multi-metric job
Closes elastic#112502
- Loading branch information
1 parent
3223032
commit dff3019
Showing
23 changed files
with
956 additions
and
263 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
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 | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { DATAFEED_STATE, JOB_STATE } from '../../../ml/common/constants/states'; | ||
import { Environment } from '../environment_rt'; | ||
|
||
export interface ApmMlJob { | ||
environment: Environment; | ||
version: number; | ||
jobId: string; | ||
jobState?: JOB_STATE; | ||
datafeedId?: string; | ||
datafeedState?: DATAFEED_STATE; | ||
} |
72 changes: 72 additions & 0 deletions
72
x-pack/plugins/apm/common/anomaly_detection/get_anomaly_detection_setup_state.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,72 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths | ||
import { FETCH_STATUS } from '../../public/hooks/use_fetcher'; | ||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths | ||
import type { APIReturnType } from '../../public/services/rest/createCallApmApi'; | ||
import { ENVIRONMENT_ALL } from '../environment_filter_values'; | ||
|
||
export enum AnomalyDetectionSetupState { | ||
Loading = 'pending', | ||
Failure = 'failure', | ||
Unknown = 'unknown', | ||
NoJobs = 'noJobs', | ||
NoJobsForEnvironment = 'noJobsForEnvironment', | ||
UpgradeableJobs = 'upgradeableJobs', | ||
UpToDate = 'upToDate', | ||
} | ||
|
||
export function getAnomalyDetectionSetupState({ | ||
environment, | ||
jobs, | ||
fetchStatus, | ||
isAuthorized, | ||
}: { | ||
environment: string; | ||
jobs: APIReturnType<'GET /internal/apm/settings/anomaly-detection/jobs'>['jobs']; | ||
fetchStatus: FETCH_STATUS; | ||
isAuthorized: boolean; | ||
}): AnomalyDetectionSetupState { | ||
if (!isAuthorized) { | ||
return AnomalyDetectionSetupState.Unknown; | ||
} | ||
|
||
if (fetchStatus === FETCH_STATUS.LOADING) { | ||
return AnomalyDetectionSetupState.Loading; | ||
} | ||
|
||
if (fetchStatus === FETCH_STATUS.FAILURE) { | ||
return AnomalyDetectionSetupState.Failure; | ||
} | ||
|
||
if (fetchStatus !== FETCH_STATUS.SUCCESS) { | ||
return AnomalyDetectionSetupState.Unknown; | ||
} | ||
|
||
const jobsForEnvironment = | ||
environment === ENVIRONMENT_ALL.value | ||
? jobs | ||
: jobs.filter((job) => job.environment === environment); | ||
|
||
const hasV2Jobs = jobsForEnvironment.some((job) => job.version === 2); | ||
const hasV3Jobs = jobsForEnvironment.some((job) => job.version === 3); | ||
const hasAnyJobs = jobs.length; | ||
|
||
if (hasV3Jobs) { | ||
return AnomalyDetectionSetupState.UpToDate; | ||
} | ||
|
||
if (hasV2Jobs) { | ||
return AnomalyDetectionSetupState.UpgradeableJobs; | ||
} | ||
|
||
if (hasAnyJobs) { | ||
return AnomalyDetectionSetupState.NoJobsForEnvironment; | ||
} | ||
|
||
return AnomalyDetectionSetupState.NoJobs; | ||
} |
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
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.