Skip to content

Commit a170e91

Browse files
Lindsay-00Lingxi Chen
andauthored
Fix for mds in server/wlmRoutes (#411)
* fix for mds in server/wlmRoutes Signed-off-by: Lingxi Chen <[email protected]> * yarn lint fix Signed-off-by: Lingxi Chen <[email protected]> * retrigger ut tests Signed-off-by: Lingxi Chen <[email protected]> * updated route for _wlm/thresholds Signed-off-by: Lingxi Chen <[email protected]> * fix ut Signed-off-by: Lingxi Chen <[email protected]> * triggering test Signed-off-by: Lingxi Chen <[email protected]> --------- Signed-off-by: Lingxi Chen <[email protected]> Co-authored-by: Lingxi Chen <[email protected]>
1 parent 67377d2 commit a170e91

File tree

6 files changed

+1103
-343
lines changed

6 files changed

+1103
-343
lines changed

.github/workflows/build-and-test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ jobs:
5454
- name: Bootstrap plugin/OpenSearch-Dashboards
5555
run: |
5656
cd OpenSearch-Dashboards/plugins/query-insights-dashboards
57+
yarn cache clean --all
5758
yarn osd bootstrap
5859
- name: Run unit tests
5960
run: |

public/pages/WorkloadManagement/WLMMain/WLMMain.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,9 @@ export const WorkloadManagementMain = ({
282282
const thresholds = await core.http.get<{
283283
cpuRejectionThreshold: number;
284284
memoryRejectionThreshold: number;
285-
}>('/api/_wlm/thresholds');
285+
}>('/api/_wlm/thresholds', {
286+
query: { dataSourceId: dataSource.id },
287+
});
286288
const cpuThreshold = thresholds?.cpuRejectionThreshold ?? 1;
287289
const memoryThreshold = thresholds?.memoryRejectionThreshold ?? 1;
288290

server/clusters/wlmPlugin.ts

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
export const WlmPlugin = function (Client: any, config: any, components: any) {
7+
const ca = components.clientAction.factory;
8+
Client.prototype.wlm = components.clientAction.namespaceFactory();
9+
const wlm = Client.prototype.wlm.prototype;
10+
11+
// Get WLM stats across all nodes
12+
wlm.getStats = ca({
13+
url: { fmt: '/_wlm/stats' },
14+
method: 'GET',
15+
});
16+
17+
// Get WLM stats for a specific node
18+
wlm.getNodeStats = ca({
19+
url: {
20+
fmt: '/_wlm/<%=nodeId%>/stats',
21+
req: {
22+
nodeId: { type: 'string', required: true },
23+
},
24+
},
25+
method: 'GET',
26+
});
27+
28+
// List all workload groups
29+
wlm.getWorkloadGroups = ca({
30+
url: { fmt: '/_wlm/workload_group' },
31+
method: 'GET',
32+
});
33+
34+
// Get workload group by name
35+
wlm.getWorkloadGroup = ca({
36+
url: {
37+
fmt: '/_wlm/workload_group/<%=name%>',
38+
req: {
39+
name: { type: 'string', required: true },
40+
},
41+
},
42+
method: 'GET',
43+
});
44+
45+
// Create workload group
46+
wlm.createWorkloadGroup = ca({
47+
url: { fmt: '/_wlm/workload_group' },
48+
method: 'PUT',
49+
needBody: true,
50+
});
51+
52+
// Update workload group
53+
wlm.updateWorkloadGroup = ca({
54+
url: {
55+
fmt: '/_wlm/workload_group/<%=name%>',
56+
req: {
57+
name: { type: 'string', required: true },
58+
},
59+
},
60+
method: 'PUT',
61+
needBody: true,
62+
});
63+
64+
// Delete workload group
65+
wlm.deleteWorkloadGroup = ca({
66+
url: {
67+
fmt: '/_wlm/workload_group/<%=name%>',
68+
req: {
69+
name: { type: 'string', required: true },
70+
},
71+
},
72+
method: 'DELETE',
73+
});
74+
75+
// Get stats for specific workload group
76+
wlm.getWorkloadGroupStats = ca({
77+
url: {
78+
fmt: '/_wlm/stats/<%=workloadGroupId%>',
79+
req: {
80+
workloadGroupId: { type: 'string', required: true },
81+
},
82+
},
83+
method: 'GET',
84+
});
85+
86+
// Create index rule
87+
wlm.createRule = ca({
88+
url: { fmt: '/_rules/workload_group' },
89+
method: 'PUT',
90+
needBody: true,
91+
});
92+
93+
// Get all index rules
94+
wlm.getRules = ca({
95+
url: { fmt: '/_rules/workload_group' },
96+
method: 'GET',
97+
});
98+
99+
// Delete index rule
100+
wlm.deleteRule = ca({
101+
url: {
102+
fmt: '/_rules/workload_group/<%=ruleId%>',
103+
req: {
104+
ruleId: { type: 'string', required: true },
105+
},
106+
},
107+
method: 'DELETE',
108+
});
109+
110+
// Update index rule
111+
wlm.updateRule = ca({
112+
url: {
113+
fmt: '/_rules/workload_group/<%=ruleId%>',
114+
req: {
115+
ruleId: { type: 'string', required: true },
116+
},
117+
},
118+
method: 'PUT',
119+
needBody: true,
120+
});
121+
122+
// Get node level cpu and memory threshold
123+
wlm.getThresholds = ca({
124+
url: { fmt: '/_cluster/settings' },
125+
method: 'GET',
126+
needBody: false,
127+
qs: ['include_defaults'],
128+
});
129+
};

server/plugin.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
ILegacyCustomClusterClient,
1313
} from '../../../src/core/server';
1414
import { QueryInsightsPlugin } from './clusters/queryInsightsPlugin';
15+
import { WlmPlugin } from './clusters/wlmPlugin';
1516

1617
import { QueryInsightsDashboardsPluginSetup, QueryInsightsDashboardsPluginStart } from './types';
1718
import { defineRoutes } from './routes';
@@ -50,10 +51,28 @@ export class QueryInsightsDashboardsPlugin
5051
queryInsightsClient,
5152
};
5253
});
54+
// Register WLM custom client
55+
const wlmClient: ILegacyCustomClusterClient = core.opensearch.legacy.createClient(
56+
'opensearch_wlm',
57+
{
58+
plugins: [WlmPlugin],
59+
}
60+
);
61+
if (dataSourceEnabled) {
62+
dataSource.registerCustomApiSchema(WlmPlugin);
63+
}
64+
65+
// @ts-ignore - Register WLM context
66+
core.http.registerRouteHandlerContext('wlm_plugin', (_context, _request) => {
67+
return {
68+
logger: this.logger,
69+
wlmClient,
70+
};
71+
});
5372

5473
// Register server side APIs
5574
defineRoutes(router, dataSourceEnabled);
56-
defineWlmRoutes(router);
75+
defineWlmRoutes(router, dataSourceEnabled);
5776

5877
return {};
5978
}

0 commit comments

Comments
 (0)