Skip to content

Commit

Permalink
[APM] Improvements to the ML Settings page (#71309)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv authored Jul 13, 2020
1 parent 8a4d0d0 commit 327fed8
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export const AddEnvironments = ({
disabled: currentEnvironments.includes(env),
}));

const [isSaving, setIsSaving] = useState(false);

const [selectedOptions, setSelected] = useState<
Array<EuiComboBoxOptionOption<string>>
>([]);
Expand Down Expand Up @@ -127,9 +129,12 @@ export const AddEnvironments = ({
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
isLoading={isSaving}
isDisabled={isSaving || selectedOptions.length === 0}
fill
disabled={selectedOptions.length === 0}
onClick={async () => {
setIsSaving(true);

const selectedEnvironments = selectedOptions.map(
({ value }) => value as string
);
Expand All @@ -140,6 +145,7 @@ export const AddEnvironments = ({
if (success) {
onCreateJobSuccess();
}
setIsSaving(false);
}}
>
{i18n.translate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import { LicensePrompt } from '../../../shared/LicensePrompt';
import { useLicense } from '../../../../hooks/useLicense';
import { APIReturnType } from '../../../../services/rest/createCallApmApi';

const DEFAULT_VALUE: APIReturnType<'/api/apm/settings/anomaly-detection'> = {
export type AnomalyDetectionApiResponse = APIReturnType<
'/api/apm/settings/anomaly-detection'
>;

const DEFAULT_VALUE: AnomalyDetectionApiResponse = {
jobs: [],
hasLegacyJobs: false,
};
Expand Down Expand Up @@ -80,7 +84,7 @@ export const AnomalyDetection = () => {
) : (
<JobsList
status={status}
anomalyDetectionJobsByEnv={data.jobs}
jobs={data.jobs}
hasLegacyJobs={data.hasLegacyJobs}
onAddEnvironments={() => {
setViewAddEnvironments(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ import { FormattedMessage } from '@kbn/i18n/react';
import { FETCH_STATUS } from '../../../../hooks/useFetcher';
import { ITableColumn, ManagedTable } from '../../../shared/ManagedTable';
import { LoadingStatePrompt } from '../../../shared/LoadingStatePrompt';
import { AnomalyDetectionJobByEnv } from '../../../../../typings/anomaly_detection';
import { MLJobLink } from '../../../shared/Links/MachineLearningLinks/MLJobLink';
import { MLLink } from '../../../shared/Links/MachineLearningLinks/MLLink';
import { getEnvironmentLabel } from '../../../../../common/environment_filter_values';
import { LegacyJobsCallout } from './legacy_jobs_callout';
import { AnomalyDetectionApiResponse } from './index';

const columns: Array<ITableColumn<AnomalyDetectionJobByEnv>> = [
type Jobs = AnomalyDetectionApiResponse['jobs'];

const columns: Array<ITableColumn<Jobs[0]>> = [
{
field: 'environment',
name: i18n.translate(
Expand Down Expand Up @@ -57,13 +59,13 @@ const columns: Array<ITableColumn<AnomalyDetectionJobByEnv>> = [
interface Props {
status: FETCH_STATUS;
onAddEnvironments: () => void;
anomalyDetectionJobsByEnv: AnomalyDetectionJobByEnv[];
jobs: Jobs;
hasLegacyJobs: boolean;
}
export const JobsList = ({
status,
onAddEnvironments,
anomalyDetectionJobsByEnv,
jobs,
hasLegacyJobs,
}: Props) => {
const isLoading =
Expand Down Expand Up @@ -128,7 +130,7 @@ export const JobsList = ({
)
}
columns={columns}
items={isLoading || hasFetchFailure ? [] : anomalyDetectionJobsByEnv}
items={jobs}
/>
<EuiSpacer size="l" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { Logger } from 'kibana/server';
import { Setup } from '../helpers/setup_request';
import { getMlJobsWithAPMGroup } from './get_ml_jobs_by_group';
import { getMlJobsWithAPMGroup } from './get_ml_jobs_with_apm_group';

export async function getAnomalyDetectionJobs(setup: Setup, logger: Logger) {
const { ml } = setup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { Setup } from '../helpers/setup_request';
import { getMlJobsWithAPMGroup } from './get_ml_jobs_by_group';
import { getMlJobsWithAPMGroup } from './get_ml_jobs_with_apm_group';

// Determine whether there are any legacy ml jobs.
// A legacy ML job has a job id that ends with "high_mean_response_time" and created_by=ml-module-apm-transaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ export const anomalyDetectionJobsRoute = createRoute(() => ({
path: '/api/apm/settings/anomaly-detection',
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
const jobs = await getAnomalyDetectionJobs(setup, context.logger);
const [jobs, legacyJobs] = await Promise.all([
getAnomalyDetectionJobs(setup, context.logger),
hasLegacyJobs(setup),
]);
return {
jobs,
hasLegacyJobs: await hasLegacyJobs(setup),
hasLegacyJobs: legacyJobs,
};
},
}));
Expand Down
10 changes: 0 additions & 10 deletions x-pack/plugins/apm/typings/anomaly_detection.ts

This file was deleted.

0 comments on commit 327fed8

Please sign in to comment.