Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APM] Improvements to the ML Settings page #71309

Merged
merged 4 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason to pick a long name when we can pick a short :) (the context makes it obvious what type of job this is)

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 { ENVIRONMENT_NOT_DEFINED } 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 @@ -64,13 +66,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 @@ -135,7 +137,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),
]);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run requests in parallel

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.