Skip to content

Commit 6aab2f4

Browse files
committed
update read-only data source view
Signed-off-by: Jackie Han <jkhanjob@gmail.com>
1 parent 10c730b commit 6aab2f4

File tree

7 files changed

+49
-28
lines changed

7 files changed

+49
-28
lines changed

public/pages/DetectorDetail/containers/DetectorDetail.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import { DETECTOR_STATE } from '../../../../server/utils/constants';
5959
import { CatIndex } from '../../../../server/models/types';
6060
import { containsIndex } from '../utils/helpers';
6161
import { DataSourceManagementPluginSetup, DataSourceViewConfig } from '../../../../../../src/plugins/data_source_management/public';
62+
import { getNotifications, getSavedObjectsClient } from '../../../services';
6263

6364
export interface DetectorRouterProps {
6465
detectorId?: string;
@@ -378,9 +379,10 @@ export const DetectorDetail = (props: DetectorDetailProps) => {
378379
setMenuMountPoint={props.setActionMenu}
379380
componentType={'DataSourceView'}
380381
componentConfig={{
381-
// give a placeholder label for now, will update it once neo team allows empty label field
382-
activeOption: [{label: 'labelPlaceHolder', id: dataSourceId}],
383-
fullWidth: true
382+
activeOption: [{ id: dataSourceId}],
383+
fullWidth: false,
384+
savedObjects: getSavedObjectsClient(),
385+
notifications: getNotifications(),
384386
}}
385387
/>
386388
)}

public/pages/DetectorsList/containers/List/List.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,15 @@ export const DetectorList = (props: ListProps) => {
170170
const [indexQuery, setIndexQuery] = useState('');
171171
useEffect(() => {
172172
const getInitialIndices = async () => {
173-
await dispatch(getIndices(indexQuery));
173+
await dispatch(getIndices(indexQuery, state.selectedDataSourceId));
174174
};
175175
getInitialIndices();
176176
}, []);
177177

178178
// Getting all initial monitors
179179
useEffect(() => {
180180
const getInitialMonitors = async () => {
181-
dispatch(searchMonitors());
181+
dispatch(searchMonitors(state.selectedDataSourceId));
182182
};
183183
getInitialMonitors();
184184
}, []);
@@ -339,7 +339,7 @@ export const DetectorList = (props: ListProps) => {
339339
if (searchValue !== indexQuery) {
340340
const sanitizedQuery = sanitizeSearchText(searchValue);
341341
setIndexQuery(sanitizedQuery);
342-
await dispatch(getPrioritizedIndices(sanitizedQuery));
342+
await dispatch(getPrioritizedIndices(sanitizedQuery, state.selectedDataSourceId));
343343
setState((state) => ({
344344
...state,
345345
page: 0,
@@ -479,7 +479,7 @@ export const DetectorList = (props: ListProps) => {
479479
DETECTOR_ACTION.START
480480
).map((detector) => detector.id);
481481
const promises = validIds.map(async (id: string) => {
482-
return dispatch(startDetector(id));
482+
return dispatch(startDetector(id, state.selectedDataSourceId));
483483
});
484484
await Promise.all(promises)
485485
.then(() => {
@@ -506,7 +506,7 @@ export const DetectorList = (props: ListProps) => {
506506
DETECTOR_ACTION.STOP
507507
).map((detector) => detector.id);
508508
const promises = validIds.map(async (id: string) => {
509-
return dispatch(stopDetector(id));
509+
return dispatch(stopDetector(id, state.selectedDataSourceId));
510510
});
511511
await Promise.all(promises)
512512
.then(() => {
@@ -538,7 +538,7 @@ export const DetectorList = (props: ListProps) => {
538538
DETECTOR_ACTION.DELETE
539539
).map((detector) => detector.id);
540540
const promises = validIds.map(async (id: string) => {
541-
return dispatch(deleteDetector(id));
541+
return dispatch(deleteDetector(id, state.selectedDataSourceId));
542542
});
543543
await Promise.all(promises)
544544
.then(() => {

public/redux/reducers/alerting.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ const reducer = handleActions<Monitors>(
9494
initialDetectorsState
9595
);
9696

97-
export const searchMonitors = (): APIAction => ({
97+
export const searchMonitors = (dataSourceId: string): APIAction => ({
9898
type: SEARCH_MONITORS,
99-
request: (client: HttpSetup) => client.post(`..${ALERTING_NODE_API._SEARCH}`),
99+
request: (client: HttpSetup) => client.post(`..${ALERTING_NODE_API._SEARCH}/${dataSourceId}`),
100100
});
101101

102102
export const searchAlerts = (

public/redux/reducers/opensearch.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,10 @@ export const getIndices = (searchKey: string = '', dataSourceId: string): APIAct
252252
client.get(`..${AD_NODE_API._INDICES}/${dataSourceId}`, { query: { index: searchKey } }),
253253
});
254254

255-
export const getAliases = (searchKey: string = ''): APIAction => ({
255+
export const getAliases = (searchKey: string = '', dataSourceId: string): APIAction => ({
256256
type: GET_ALIASES,
257257
request: (client: HttpSetup) =>
258-
client.get(`..${AD_NODE_API._ALIASES}`, { query: { alias: searchKey } }),
258+
client.get(`..${AD_NODE_API._ALIASES}/${dataSourceId}`, { query: { alias: searchKey } }),
259259
});
260260

261261
export const getMappings = (searchKey: string = ''): APIAction => ({
@@ -295,11 +295,11 @@ export const deleteIndex = (index: string): APIAction => ({
295295
});
296296

297297
export const getPrioritizedIndices =
298-
(searchKey: string): ThunkAction =>
298+
(searchKey: string, datSourceId: string): ThunkAction =>
299299
async (dispatch, getState) => {
300300
//Fetch Indices and Aliases with text provided
301-
await dispatch(getIndices(searchKey));
302-
await dispatch(getAliases(searchKey));
301+
await dispatch(getIndices(searchKey, datSourceId));
302+
await dispatch(getAliases(searchKey, datSourceId));
303303
const osState = getState().opensearch;
304304
const exactMatchedIndices = osState.indices;
305305
const exactMatchedAliases = osState.aliases;
@@ -311,8 +311,8 @@ export const getPrioritizedIndices =
311311
};
312312
} else {
313313
//No results found for exact match, append wildCard and get partial matches if exists
314-
await dispatch(getIndices(`${searchKey}*`));
315-
await dispatch(getAliases(`${searchKey}*`));
314+
await dispatch(getIndices(`${searchKey}*`, datSourceId));
315+
await dispatch(getAliases(`${searchKey}*`, datSourceId));
316316
const osState = getState().opensearch;
317317
const partialMatchedIndices = osState.indices;
318318
const partialMatchedAliases = osState.aliases;

server/plugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class AnomalyDetectionOpenSearchDashboardsPlugin
8888

8989
// Create services & register with OpenSearch client
9090
const adService = new AdService(client, dataSourceEnabled);
91-
const alertingService = new AlertingService(client);
91+
const alertingService = new AlertingService(client, dataSourceEnabled);
9292
const opensearchService = new OpenSearchService(client, dataSourceEnabled);
9393
const sampleDataService = new SampleDataService(client);
9494

server/routes/alerting.ts

+17-5
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,23 @@ import {
2222
OpenSearchDashboardsResponseFactory,
2323
IOpenSearchDashboardsResponse,
2424
} from '../../../../src/core/server';
25+
import { getClientBasedOnDataSource } from '../utils/helpers';
2526

2627
export function registerAlertingRoutes(
2728
apiRouter: Router,
2829
alertingService: AlertingService
2930
) {
30-
apiRouter.post('/monitors/_search', alertingService.searchMonitors);
31+
apiRouter.post('/monitors/_search/{detectorId}', alertingService.searchMonitors);
3132
apiRouter.get('/monitors/alerts', alertingService.searchAlerts);
3233
}
3334

3435
export default class AlertingService {
3536
private client: any;
37+
dataSourceEnabled: boolean;
3638

37-
constructor(client: any) {
39+
constructor(client: any, dataSourceEnabled: boolean) {
3840
this.client = client;
41+
this.dataSourceEnabled = dataSourceEnabled;
3942
}
4043

4144
searchMonitors = async (
@@ -44,6 +47,8 @@ export default class AlertingService {
4447
opensearchDashboardsResponse: OpenSearchDashboardsResponseFactory
4548
): Promise<IOpenSearchDashboardsResponse<any>> => {
4649
try {
50+
const { dataSourceId } = request.params as { dataSourceId: string };
51+
4752
const requestBody = {
4853
size: MAX_MONITORS,
4954
query: {
@@ -71,9 +76,16 @@ export default class AlertingService {
7176
},
7277
},
7378
};
74-
const response: SearchResponse<Monitor> = await this.client
75-
.asScoped(request)
76-
.callAsCurrentUser('alerting.searchMonitors', { body: requestBody });
79+
80+
const callWithRequest = getClientBasedOnDataSource(
81+
context,
82+
this.dataSourceEnabled,
83+
request,
84+
dataSourceId,
85+
this.client);
86+
87+
const response: SearchResponse<Monitor> = await callWithRequest(
88+
'alerting.searchMonitors', { body: requestBody });
7789
const totalMonitors = get(response, 'hits.total.value', 0);
7890
const allMonitors = get(response, 'hits.hits', []).reduce(
7991
(acc: any, monitor: any) => ({

server/routes/opensearch.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function registerOpenSearchRoutes(
4040
opensearchService: OpenSearchService
4141
) {
4242
apiRouter.get('/_indices/{dataSourceId}', opensearchService.getIndices);
43-
apiRouter.get('/_aliases', opensearchService.getAliases);
43+
apiRouter.get('/_aliases/{dataSourceId}', opensearchService.getAliases);
4444
apiRouter.get('/_mappings', opensearchService.getMapping);
4545
apiRouter.post('/_search', opensearchService.executeSearch);
4646
apiRouter.put('/create_index', opensearchService.createIndex);
@@ -160,10 +160,17 @@ export default class OpenSearchService {
160160
opensearchDashboardsResponse: OpenSearchDashboardsResponseFactory
161161
): Promise<IOpenSearchDashboardsResponse<any>> => {
162162
const { alias } = request.query as { alias: string };
163+
const { dataSourceId } = request.params as { dataSourceId: string };
164+
163165
try {
164-
const response: IndexAlias[] = await this.client
165-
.asScoped(request)
166-
.callAsCurrentUser('cat.aliases', {
166+
const callWithRequest = getClientBasedOnDataSource(
167+
context,
168+
this.dataSourceEnabled,
169+
request,
170+
dataSourceId,
171+
this.client);
172+
const response: IndexAlias[] = await callWithRequest(
173+
'cat.aliases', {
167174
alias,
168175
format: 'json',
169176
h: 'alias,index',

0 commit comments

Comments
 (0)