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

Unit tests for expression function and bug fixes #503

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -35,7 +35,6 @@ import {
prettifyErrorMessage,
NO_PERMISSIONS_KEY_WORD,
} from '../../../../../server/utils/helpers';
import { SavedObjectLoader } from '../../../../../../../src/plugins/saved_objects/public';
import {
EmptyAssociatedDetectorMessage,
ConfirmUnlinkDetectorModal,
Expand Down Expand Up @@ -284,7 +283,7 @@ function AssociatedDetectors({ embeddable, closeFlyout, setMode }) {
<div className="associated-detectors">
<EuiFlyout ownFocus size="m" paddingSize="m" onClose={closeFlyout}>
<EuiFlyoutHeader hasBorder>
<EuiTitle size="s">
<EuiTitle>
<h2 id="associated-detectors__title">
Associated anomaly detectors
</h2>
Expand All @@ -303,7 +302,7 @@ function AssociatedDetectors({ embeddable, closeFlyout, setMode }) {
<EuiFlexGroup alignItems="center">
<EuiFlexItem component="span">
<EuiTitle size="xxs">
<h3>{embeddableTitle}</h3>
<h3>Visualization: {embeddableTitle}</h3>
</EuiTitle>
</EuiFlexItem>
<EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
&__flex-group {
height: 100%;
}

&__associate-button {
flex: 0 0 auto;
}
}
9 changes: 6 additions & 3 deletions public/expressions/__tests__/overlay_anomalies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ describe('overlay_anomalies spec', () => {
const receivedAnomalies = await getAnomalies(
ANOMALY_RESULT_SUMMARY_DETECTOR_ID,
1589258564789,
1589258684789
1589258684789,
''
);
expect(receivedAnomalies).toStrictEqual(PARSED_ANOMALIES);
});
Expand All @@ -54,7 +55,8 @@ describe('overlay_anomalies spec', () => {
const receivedAnomalies = await getAnomalies(
ANOMALY_RESULT_SUMMARY_DETECTOR_ID,
1589258564789,
1589258684789
1589258684789,
''
);
expect(receivedAnomalies).toStrictEqual([]);
});
Expand All @@ -63,7 +65,8 @@ describe('overlay_anomalies spec', () => {
const receivedAnomalies = await getAnomalies(
ANOMALY_RESULT_SUMMARY_DETECTOR_ID,
1589258564789,
1589258684789
1589258684789,
''
);
expect(receivedAnomalies).toStrictEqual([]);
});
Expand Down
28 changes: 19 additions & 9 deletions public/expressions/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,32 @@ import { get } from 'lodash';
export const getAnomalies = async (
detectorId: string,
startTime: number,
endTime: number
endTime: number,
resultIndex: string
): Promise<AnomalyData[]> => {
const anomalySummaryQuery = getAnomalySummaryQuery(
startTime,
endTime,
detectorId,
undefined,
false
);

const anomalySummaryResponse = await getClient().post(
`..${AD_NODE_API.DETECTOR}/results/_search`,
{
body: JSON.stringify(anomalySummaryQuery),
}
true
Copy link
Member

Choose a reason for hiding this comment

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

Don't forget to revert this again back to false

Copy link
Member Author

Choose a reason for hiding this comment

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

done

);
let anomalySummaryResponse;
if (resultIndex === '') {
anomalySummaryResponse = await getClient().post(
`..${AD_NODE_API.DETECTOR}/results/_search`,
{
body: JSON.stringify(anomalySummaryQuery),
}
);
} else {
anomalySummaryResponse = await getClient().post(
`..${AD_NODE_API.DETECTOR}/results/_search/${resultIndex}/true`,
{
body: JSON.stringify(anomalySummaryQuery),
}
);
}

return parsePureAnomalies(anomalySummaryResponse);
};
Expand Down
4 changes: 3 additions & 1 deletion public/expressions/overlay_anomalies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export const overlayAnomaliesFunction =
throw new Error(get(detectorResponse, 'error', ''));
}
const detectorName = get(detectorResponse.response, 'name', '');
const resultIndex = get(detectorResponse.response, 'resultIndex', '');
if (detectorName === '') {
throw new Error('Anomaly Detector - Unable to get detector');
}
Expand All @@ -125,7 +126,8 @@ export const overlayAnomaliesFunction =
const anomalies = await getAnomalies(
detectorId,
startTimeInMillis,
endTimeInMillis
endTimeInMillis,
resultIndex
);
const anomalyLayer = convertAnomaliesToPointInTimeEventsVisLayer(
anomalies,
Expand Down
4 changes: 2 additions & 2 deletions public/utils/contextMenu/getActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ export const getActions = () => {
title: i18n.translate(
'dashboard.actions.adMenuItem.associatedAnomalyDetector.displayName',
{
defaultMessage: 'Associated anomaly detector',
defaultMessage: 'Associated detectors',
}
),
icon: 'gear' as EuiIconType,
icon: 'kqlSelector' as EuiIconType,
order: 99,
onClick: getOnClick(FLYOUT_MODES.associated),
},
Expand Down