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] Bug fixes from ML integration testing #71564

Merged
merged 3 commits into from
Jul 14, 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
@@ -0,0 +1,43 @@
/*
* 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 { showAlert } from './AnomalyDetectionSetupLink';

describe('#showAlert', () => {
describe('when an environment is selected', () => {
it('should return true when there are no jobs', () => {
const result = showAlert([], 'testing');
expect(result).toBe(true);
});
it('should return true when environment is not included in the jobs', () => {
const result = showAlert(
[{ environment: 'staging' }, { environment: 'production' }],
'testing'
);
expect(result).toBe(true);
});
it('should return false when environment is included in the jobs', () => {
const result = showAlert(
[{ environment: 'staging' }, { environment: 'production' }],
'staging'
);
expect(result).toBe(false);
});
});
describe('there is no environment selected (All)', () => {
it('should return true when there are no jobs', () => {
const result = showAlert([], undefined);
expect(result).toBe(true);
});
it('should return false when there are any number of jobs', () => {
const result = showAlert(
[{ environment: 'staging' }, { environment: 'production' }],
undefined
);
expect(result).toBe(false);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@ export function AnomalyDetectionSetupLink() {
);
const isFetchSuccess = status === FETCH_STATUS.SUCCESS;

// Show alert if there are no jobs OR if no job matches the current environment
const showAlert =
isFetchSuccess && !data.jobs.some((job) => environment === job.environment);

return (
<APMLink path="/settings/anomaly-detection">
<EuiButtonEmpty size="s" color="primary" iconType="inspect">
{ANOMALY_DETECTION_LINK_LABEL}
</EuiButtonEmpty>
{showAlert && (
{isFetchSuccess && showAlert(data.jobs, environment) && (
<EuiToolTip position="bottom" content={getTooltipText(environment)}>
<EuiIcon type="alert" color="danger" />
</EuiToolTip>
Expand Down Expand Up @@ -61,3 +57,16 @@ const ANOMALY_DETECTION_LINK_LABEL = i18n.translate(
'xpack.apm.anomalyDetectionSetup.linkLabel',
{ defaultMessage: `Anomaly detection` }
);

export function showAlert(
jobs: Array<{ environment: string }> = [],
environment: string | undefined
) {
return (
// No job exists, or
jobs.length === 0 ||
// no job exists for the selected environment
(environment !== undefined &&
jobs.every((job) => environment !== job.environment))
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function getMlBucketSize({
body: {
_source: 'bucket_span',
size: 1,
terminateAfter: 1,
terminate_after: 1,
query: {
bool: {
filter: [
Expand Down