-
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
Co-authored-by: Dario Gieselaar <[email protected]>
- Loading branch information
1 parent
618069a
commit 9b21224
Showing
33 changed files
with
1,157 additions
and
431 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'; | ||
import { Environment } from '../environment_rt'; | ||
|
||
export interface ApmMlJob { | ||
environment: Environment; | ||
version: number; | ||
jobId: string; | ||
jobState?: JOB_STATE; | ||
datafeedId?: string; | ||
datafeedState?: DATAFEED_STATE; | ||
} |
78 changes: 78 additions & 0 deletions
78
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,78 @@ | ||
/* | ||
* 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', | ||
LegacyJobs = 'legacyJobs', | ||
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 hasV1Jobs = jobs.some((job) => job.version === 1); | ||
const hasV2Jobs = jobsForEnvironment.some((job) => job.version === 2); | ||
const hasV3Jobs = jobsForEnvironment.some((job) => job.version === 3); | ||
const hasAnyJobs = jobs.length > 0; | ||
|
||
if (hasV3Jobs) { | ||
return AnomalyDetectionSetupState.UpToDate; | ||
} | ||
|
||
if (hasV2Jobs) { | ||
return AnomalyDetectionSetupState.UpgradeableJobs; | ||
} | ||
|
||
if (hasV1Jobs) { | ||
return AnomalyDetectionSetupState.LegacyJobs; | ||
} | ||
|
||
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
Oops, something went wrong.