Skip to content

Commit 4cf545f

Browse files
committed
change to check alias
Signed-off-by: Kaituo Li <kaituo@amazon.com>
1 parent f924b45 commit 4cf545f

File tree

5 files changed

+70
-21
lines changed

5 files changed

+70
-21
lines changed

public/pages/DefineDetector/components/CustomResultIndex/CustomResultIndex.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function CustomResultIndex(props: CustomResultIndexProps) {
8989
<EuiFlexItem>
9090
<EuiCallOut
9191
data-test-subj="cannotEditResultIndexCallout"
92-
title="You can't change the custom result index after creating the detector. You can manage the result index using the following three settings inside Anomaly Detection plugin or with the Index Management plugin."
92+
title="You can't change the custom result index after creating the detector. You can manage the result index using the following three settings."
9393
color="warning"
9494
iconType="alert"
9595
size="s"

public/pages/DetectorDetail/containers/DetectorDetail.tsx

+9-7
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import {
4545
getDetector,
4646
stopHistoricalDetector,
4747
} from '../../../redux/reducers/ad';
48-
import { getIndices } from '../../../redux/reducers/opensearch';
48+
import { getAliases, getIndices } from '../../../redux/reducers/opensearch';
4949
import { getErrorMessage, Listener } from '../../../utils/utils';
5050
import { darkModeEnabled } from '../../../utils/opensearchDashboardsUtils';
5151
import { BREADCRUMBS, MDS_BREADCRUMBS } from '../../../utils/constants';
@@ -145,7 +145,7 @@ export const DetectorDetail = (props: DetectorDetailProps) => {
145145
- If the detector is still loading, the result index is not missing.
146146
- If the result index retrieved from the detector is empty, it is not missing.
147147
- If cat indices are being requested, the result index is not missing.
148-
- If visible indices are empty, it is likely there is an issue retrieving existing indices.
148+
- If visible indices/aliaes are empty, it is likely there is an issue retrieving existing indices.
149149
To be safe, we'd rather not show the error message and consider the result index not missing.
150150
- If the result index is not found in the visible indices, then it is missing.
151151
*/
@@ -156,13 +156,14 @@ export const DetectorDetail = (props: DetectorDetailProps) => {
156156
? false
157157
: isCatIndicesRequesting
158158
? false
159-
: isEmpty(visibleIndices)
159+
: isEmpty(visibleIndices) || isEmpty(visibleAliases)
160160
? false
161161
: !containsIndex(resultIndexOrAlias, visibleIndices) && !containsAlias(resultIndexOrAlias, visibleAliases);
162162

163163
// debug message: prints visibleIndices if isResultIndexMissing is true
164164
if (isResultIndexMissing) {
165-
console.log(`isResultIndexMissing is true, visibleIndices: ${visibleIndices}, visibleAliases: ${visibleAliases}, detector result index: ${resultIndexOrAlias}`);
165+
// The JSON.stringify method converts a JavaScript object or value to a JSON string. The optional null parameter is for the replacer function (not used here), and 2 specifies the indentation level for pretty-printing the JSON.
166+
console.log(`isResultIndexMissing is true, visibleIndices: ${JSON.stringify(visibleIndices, null, 2)}, visibleAliases: ${JSON.stringify(visibleAliases, null, 2)}, detector result index: ${resultIndexOrAlias}`);
166167
}
167168

168169
// String to set in the modal if the realtime detector and/or historical analysis
@@ -201,20 +202,21 @@ export const DetectorDetail = (props: DetectorDetailProps) => {
201202
scroll(0, 0);
202203
}, []);
203204

204-
// Getting all visible indices. Will re-fetch if changes to the detector (e.g.,
205+
// Getting all visible indices & aliases. Will re-fetch if changes to the detector (e.g.,
205206
// detector starts, result index recreated or user switches tabs to re-fetch detector)
206207
useEffect(() => {
207-
const getInitialIndices = async () => {
208+
const getInitialIndicesAliases = async () => {
208209
try {
209210
await dispatch(getIndices('', dataSourceId));
211+
await dispatch(getAliases('', dataSourceId));
210212
} catch (error) {
211213
console.error(error);
212214
core.notifications.toasts.addDanger('Error getting all indices');
213215
}
214216
};
215217
// only need to check if indices exist after detector finishes loading
216218
if (!isLoadingDetector) {
217-
getInitialIndices();
219+
getInitialIndicesAliases();
218220
}
219221
}, [detector]);
220222

public/pages/DetectorDetail/containers/__tests__/CustomIndexErrorMsg.test.tsx

+47-4
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ describe('detector detail', () => {
209209
expect(element).toBeNull();
210210
});
211211

212-
test('the result index is not found in the visible indices', () => {
212+
test('the result index is not found in the visible indices but alias is empty', () => {
213213
const detectorInfo = {
214214
detector: getRandomDetector(true, resultIndex),
215215
hasError: false,
@@ -236,7 +236,7 @@ describe('detector detail', () => {
236236
const element = screen.queryByTestId('missingResultIndexCallOut');
237237

238238
// Assert that the element is in the document
239-
expect(element).not.toBeNull();
239+
expect(element).toBeNull();
240240
});
241241

242242
test('the result index is found in the visible indices', () => {
@@ -273,8 +273,9 @@ describe('detector detail', () => {
273273
expect(element).toBeNull();
274274
});
275275

276-
test('the result index prefix is found in the visible indices', () => {
276+
test('the result index prefix is found in the visible aliaes', () => {
277277
const detector = getRandomDetector(true, resultIndex);
278+
const resultIndexFull = resultIndex + '-history-2024.06.05-1';
278279

279280
// Set up the mock implementation for useFetchDetectorInfo
280281
(useFetchDetectorInfo as jest.Mock).mockImplementation(() => ({
@@ -288,7 +289,12 @@ describe('detector detail', () => {
288289
opensearch: {
289290
indices: [
290291
{ health: 'green', index: '.kibana_-962704462_v992471_1' },
291-
{ health: 'green', index: resultIndex + '-history-2024.06.05-1' },
292+
{ health: 'green', index: resultIndexFull},
293+
],
294+
aliases : [
295+
{index: '.opendistro-anomaly-results-history-2024.06.08-1', alias: '.opendistro-anomaly-results'},
296+
{index: resultIndexFull, alias: resultIndex},
297+
{index: '.kibana_1', alias: '.kibana'},
292298
],
293299
requesting: false,
294300
},
@@ -306,4 +312,41 @@ describe('detector detail', () => {
306312
// Assert that the element is not in the document
307313
expect(element).toBeNull();
308314
});
315+
316+
test('the result index prefix is not found in both visible aliaes and indices', () => {
317+
const detector = getRandomDetector(true, resultIndex);
318+
319+
// Set up the mock implementation for useFetchDetectorInfo
320+
(useFetchDetectorInfo as jest.Mock).mockImplementation(() => ({
321+
detector: detector,
322+
hasError: false,
323+
isLoadingDetector: false,
324+
errorMessage: undefined,
325+
}));
326+
327+
const initialState = {
328+
opensearch: {
329+
indices: [
330+
{ health: 'green', index: '.kibana_-962704462_v992471_1' },
331+
],
332+
aliases : [
333+
{index: '.opendistro-anomaly-results-history-2024.06.08-1', alias: '.opendistro-anomaly-results'},
334+
{index: '.kibana_1', alias: '.kibana'},
335+
],
336+
requesting: false,
337+
},
338+
ad: {
339+
detectors: {},
340+
},
341+
alerting: {
342+
monitors: {},
343+
},
344+
};
345+
346+
renderWithRouter(detectorId, initialState);
347+
const element = screen.queryByTestId('missingResultIndexCallOut');
348+
349+
// Assert that the element is not in the document
350+
expect(element).not.toBeNull();
351+
});
309352
});

public/pages/ReviewAndCreate/components/DetectorDefinitionFields/DetectorDefinitionFields.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ export const DetectorDefinitionFields = (
131131
}
132132
};
133133

134+
const minAge = get(props, 'detector.resultIndexMinAge', '-');
135+
const minSize = get(props, 'detector.resultIndexMinSize', '-');
136+
const ttl = get(props, 'detector.resultIndexTtl', '-');
137+
134138
return (
135139
<ContentPanel
136140
title="Detector settings"
@@ -220,19 +224,19 @@ export const DetectorDefinitionFields = (
220224
<EuiFlexItem>
221225
<ConfigCell
222226
title="Custom result index min age"
223-
description={get(props, 'detector.resultIndexMinAge', '-') + ' Days'}
227+
description={minAge === '-' ? minAge : `${minAge} Days`}
224228
/>
225229
</EuiFlexItem>
226230
<EuiFlexItem>
227231
<ConfigCell
228232
title="Custom result index min size"
229-
description={get(props, 'detector.resultIndexMinSize', '-') + ' MB'}
233+
description={minSize == '-' ? minSize : `${minSize} MB`}
230234
/>
231235
</EuiFlexItem>
232236
<EuiFlexItem>
233237
<ConfigCell
234238
title="Custom result index TTL"
235-
description={get(props, 'detector.resultIndexTtl', '-') + ' Days'}
239+
description={ttl == '-' ? ttl : `${ttl} Days`}
236240
/>
237241
</EuiFlexItem>
238242
</EuiFlexGrid>

public/pages/ReviewAndCreate/containers/__tests__/__snapshots__/ReviewAndCreate.test.tsx.snap

+6-6
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ exports[`<ReviewAndCreate /> spec renders the component, validation loading 1`]
424424
<p
425425
class="enabled"
426426
>
427-
- Days
427+
-
428428
</p>
429429
</div>
430430
</div>
@@ -458,7 +458,7 @@ exports[`<ReviewAndCreate /> spec renders the component, validation loading 1`]
458458
<p
459459
class="enabled"
460460
>
461-
- MB
461+
-
462462
</p>
463463
</div>
464464
</div>
@@ -492,7 +492,7 @@ exports[`<ReviewAndCreate /> spec renders the component, validation loading 1`]
492492
<p
493493
class="enabled"
494494
>
495-
- Days
495+
-
496496
</p>
497497
</div>
498498
</div>
@@ -1518,7 +1518,7 @@ exports[`issue in detector validation issues in feature query 1`] = `
15181518
<p
15191519
class="enabled"
15201520
>
1521-
- Days
1521+
-
15221522
</p>
15231523
</div>
15241524
</div>
@@ -1552,7 +1552,7 @@ exports[`issue in detector validation issues in feature query 1`] = `
15521552
<p
15531553
class="enabled"
15541554
>
1555-
- MB
1555+
-
15561556
</p>
15571557
</div>
15581558
</div>
@@ -1586,7 +1586,7 @@ exports[`issue in detector validation issues in feature query 1`] = `
15861586
<p
15871587
class="enabled"
15881588
>
1589-
- Days
1589+
-
15901590
</p>
15911591
</div>
15921592
</div>

0 commit comments

Comments
 (0)