Skip to content

Commit 3f16c24

Browse files
authored
refactor ppl alerting apis to v1 endpoints (#1378)
* refactor ppl alerting apis to v1 endpoints Signed-off-by: KashKondaka <37753523+KashKondaka@users.noreply.github.com> * fix monitor index unit test Signed-off-by: KashKondaka <37753523+KashKondaka@users.noreply.github.com> * react 18 Signed-off-by: KashKondaka <37753523+KashKondaka@users.noreply.github.com> * update to 3.5 Signed-off-by: KashKondaka <37753523+KashKondaka@users.noreply.github.com> * update open search version to 3.5 in workflow Signed-off-by: KashKondaka <37753523+KashKondaka@users.noreply.github.com> --------- Signed-off-by: KashKondaka <37753523+KashKondaka@users.noreply.github.com>
1 parent 5b842db commit 3f16c24

File tree

18 files changed

+210
-202
lines changed

18 files changed

+210
-202
lines changed

.github/workflows/verify-binary-installation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: 'Install Dashboards with Plugin via Binary'
22

33
on: [push, pull_request]
44
env:
5-
OPENSEARCH_VERSION: '3.0.0-alpha1'
5+
OPENSEARCH_VERSION: '3.5.0'
66
CI: 1
77
# avoid warnings like "tput: No value for $TERM and no -T specified"
88
TERM: xterm

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,23 @@
2828
},
2929
"devDependencies": {
3030
"@babel/plugin-transform-modules-commonjs": "^7.22.9",
31+
"@cfaester/enzyme-adapter-react-18": "^0.8.0",
3132
"@elastic/elastic-eslint-config-kibana": "link:../../packages/opensearch-eslint-config-opensearch-dashboards",
3233
"@elastic/eslint-import-resolver-kibana": "link:../../packages/osd-eslint-import-resolver-opensearch-dashboards",
34+
"@types/react": "^18.2.0",
3335
"cypress": "^13.6.0",
3436
"husky": "^8.0.0",
35-
"lint-staged": "^10.2.0",
36-
"@types/react": "^18.2.0"
37+
"lint-staged": "^10.2.0"
3738
},
3839
"dependencies": {
3940
"@reduxjs/toolkit": "^1.6.1",
4041
"brace": "0.11.1",
4142
"formik": "^2.2.6",
4243
"lodash": "^4.17.21",
44+
"prettier": "^2.1.1",
4345
"query-string": "^6.13.2",
4446
"react-redux": "^8.1.0",
45-
"react-vis": "^1.8.1",
46-
"prettier": "^2.1.1"
47+
"react-vis": "^1.8.1"
4748
},
4849
"resolutions": {
4950
"ansi-regex": "^5.0.1",

public/components/AlertInsight/AlertInsight.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,9 @@ export const AlertInsight: React.FC<AlertInsightProps> = (props: AlertInsightPro
4545
viewMode = 'classic',
4646
} = props;
4747

48-
const isPplMonitorAlert =
49-
viewMode === 'new' ||
50-
Boolean(alert?.monitor_v2_id || alert?.trigger_v2_id || alert?.monitor_v2_name);
48+
const isPplMonitorAlert = viewMode === 'new';
5149

5250
if (isPplMonitorAlert) {
53-
console.log('[AlertInsight] skipping v1 monitor fetch for PPL alert', {
54-
viewMode,
55-
alertId,
56-
hasV2Fields: Boolean(alert?.monitor_v2_id || alert?.trigger_v2_id || alert?.monitor_v2_name),
57-
});
5851
return children;
5952
}
6053

public/components/Breadcrumbs/Breadcrumbs.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,7 @@ const fetchMonitorName = async (id, legacyResource, dataSourceQueryObj, httpClie
142142
};
143143

144144
const extractMonitorNameFromV2 = (payload = {}) => {
145-
const pplMonitor =
146-
payload?.monitor_v2?.ppl_monitor ??
147-
payload?.monitor?.ppl_monitor ??
148-
payload?.ppl_monitor ??
149-
null;
150-
151-
const name = pplMonitor?.name ?? payload?.monitor?.name ?? payload?.name ?? null;
145+
const name = payload?.name ?? payload?.monitor?.name ?? null;
152146
return { name };
153147
};
154148

public/components/Flyout/flyouts/components/AlertsDashboardFlyoutComponentPpl.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ export default class AlertsDashboardFlyoutComponentPpl extends Component {
135135
}
136136

137137
const payload = resp.resp || resp;
138-
const alertsArray = Array.isArray(payload?.alerts_v2) ? payload.alerts_v2 : [];
139-
const totalCountRaw = payload?.total_alerts_v2;
138+
const alertsArray = Array.isArray(payload?.alerts) ? payload.alerts : [];
139+
const totalCountRaw = payload?.totalAlerts;
140140
const totalCount = Number.isFinite(Number(totalCountRaw))
141141
? Number(totalCountRaw)
142142
: alertsArray.length;
@@ -145,7 +145,7 @@ export default class AlertsDashboardFlyoutComponentPpl extends Component {
145145
alertState && alertState !== 'ALL' ? String(alertState).toUpperCase() : undefined;
146146

147147
const filteredAlerts = alertsArray
148-
.filter((alert) => alert.trigger_v2_id === triggerID)
148+
.filter((alert) => alert.trigger_id === triggerID)
149149
.filter((alert) => {
150150
if (!stateFilter) return true;
151151
const stateValue = String(alert?.state || '').toUpperCase();
@@ -156,7 +156,7 @@ export default class AlertsDashboardFlyoutComponentPpl extends Component {
156156
const direction = sortDirection === 'asc' ? 1 : -1;
157157

158158
if (sortField === 'start_time') {
159-
return (Number(a?.triggered_time) - Number(b?.triggered_time)) * direction;
159+
return (Number(a?.start_time) - Number(b?.start_time)) * direction;
160160
}
161161

162162
const valueA = _.get(a, sortField);
@@ -217,7 +217,7 @@ export default class AlertsDashboardFlyoutComponentPpl extends Component {
217217
};
218218

219219
renderQueryResultsPreview = (alert) => {
220-
const results = alert?.query_results;
220+
const results = alert?.ppl_query_results;
221221
const schema = Array.isArray(results?.schema) ? results.schema : [];
222222
const dataRows = Array.isArray(results?.datarows) ? results.datarows : [];
223223

@@ -234,7 +234,7 @@ export default class AlertsDashboardFlyoutComponentPpl extends Component {
234234
};
235235

236236
getItemId = (alert) => {
237-
const version = alert?.monitor_v2_version ?? alert?.version ?? '';
237+
const version = alert?.version ?? '';
238238
return `${alert.id}-${version}`;
239239
};
240240

@@ -251,7 +251,7 @@ export default class AlertsDashboardFlyoutComponentPpl extends Component {
251251
totalAlerts,
252252
} = this.state;
253253

254-
const { monitor = {}, monitor_id, monitor_name, trigger_name, start_time } = this.props;
254+
const { monitor_id, monitor_name, trigger_name, start_time } = this.props;
255255

256256
const pageSizeToUse = size > 0 ? size : DEFAULT_PAGE_SIZE;
257257
const displayedAlerts = alerts.slice(
@@ -260,20 +260,17 @@ export default class AlertsDashboardFlyoutComponentPpl extends Component {
260260
);
261261
const firstAlert = alerts[0] || {};
262262

263-
const severity =
264-
normalizePPLSeverity(firstAlert?.severity) ||
265-
normalizePPLSeverity(_.get(monitor, 'triggers[0].severity')) ||
266-
firstAlert?.severity;
263+
const severity = normalizePPLSeverity(firstAlert?.severity) || firstAlert?.severity;
267264

268-
const condition = firstAlert?.query || monitor?.query || DEFAULT_EMPTY_DATA;
265+
const condition = firstAlert?.ppl_query || DEFAULT_EMPTY_DATA;
269266

270267
const monitorUrl = monitor_id ? `#/monitors/${monitor_id}` : '#/monitors';
271268

272269
const severityDisplay = getSeverityText(severity) || severity || DEFAULT_EMPTY_DATA;
273270

274271
const columns = [
275272
{
276-
field: 'triggered_time',
273+
field: 'start_time',
277274
name: 'Alert triggered time',
278275
sortable: true,
279276
dataType: 'date',
@@ -286,12 +283,13 @@ export default class AlertsDashboardFlyoutComponentPpl extends Component {
286283
},
287284
},
288285
{
289-
field: 'query_results',
286+
field: 'ppl_query_results',
290287
name: '',
291288
align: 'right',
292289
render: (_value, item) => {
293290
const hasResults =
294-
Array.isArray(item?.query_results?.datarows) && item.query_results.datarows.length;
291+
Array.isArray(item?.ppl_query_results?.datarows) &&
292+
item.ppl_query_results.datarows.length;
295293
if (!hasResults) {
296294
return (
297295
<EuiText size="s" color="subdued">

public/pages/CreateMonitor/containers/CreateMonitor/utils/pplAlertingHelpers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ export const getInitialValues = ({
124124
const isPpl =
125125
initialValues?.query_language === 'ppl' ||
126126
monitorToEdit?.query_language === 'ppl' ||
127-
!!monitorToEdit?.ppl_monitor ||
128-
!!monitorToEdit?.monitor_v2?.ppl_monitor;
127+
monitorToEdit?.monitor_type === 'ppl_monitor' ||
128+
!!monitorToEdit?.ppl_monitor;
129129
initialValues.monitor_mode = isPpl ? 'ppl' : 'legacy';
130130
if (isPpl) {
131131
initialValues.searchType = 'query';

public/pages/CreateMonitor/containers/CreateMonitor/utils/pplAlertingMonitorToFormik.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,7 @@ export default function pplAlertingMonitorToFormik(monitorIn) {
1818
const formikValues = _.cloneDeep(FORMIK_INITIAL_VALUES);
1919
if (!monitorIn) return formikValues;
2020

21-
const monitor =
22-
monitorIn?.monitor_v2?.ppl_monitor ||
23-
monitorIn?.monitorV2?.ppl_monitor ||
24-
monitorIn?.ppl_monitor ||
25-
monitorIn ||
26-
{};
21+
const monitor = monitorIn?.ppl_monitor || monitorIn || {};
2722
if (!monitor || Object.keys(monitor).length === 0) return formikValues;
2823

2924
let cronExpression = formikValues.cronExpression;

public/pages/Dashboard/containers/Dashboard.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('Dashboard', () => {
4848
ok: true,
4949
alerts: [],
5050
totalAlerts: 0,
51-
resp: { total_alerts_v2: 0, alerts: [] },
51+
resp: { totalAlerts: 0, alerts: [] },
5252
});
5353
});
5454

public/pages/Dashboard/containers/DashboardPpl.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -219,21 +219,15 @@ export default class DashboardPpl extends Component {
219219
let rawAlerts = [];
220220
let totalFromServer;
221221

222-
const alertsArray = payload?.alerts_v2 || payload?.alertV2s;
222+
const alertsArray = payload?.alerts;
223223
if (Array.isArray(alertsArray)) {
224224
rawAlerts = alertsArray.map((a) => ({
225225
...a,
226-
monitor_id: a.monitor_v2_id,
227-
monitor_name: a.monitor_v2_name,
228-
trigger_id: a.trigger_v2_id,
229-
version: a.monitor_v2_version ?? a.version,
230-
monitorVersion: a.monitor_v2_version,
231-
start_time: a.triggered_time,
232-
trigger_name: a.trigger_v2_name,
233-
end_time: a.expiration_time,
226+
start_time: a.start_time || a.triggered_time,
227+
end_time: a.end_time || a.expiration_time,
234228
state: a.state || 'ACTIVE',
235229
}));
236-
totalFromServer = payload.total_alerts_v2 ?? payload.totalAlertV2s ?? rawAlerts.length;
230+
totalFromServer = payload.totalAlerts ?? rawAlerts.length;
237231
}
238232

239233
if (Array.isArray(monitorIds) && monitorIds.length) {
@@ -245,7 +239,7 @@ export default class DashboardPpl extends Component {
245239
.toLowerCase();
246240
const matchesSearch = (a) => {
247241
if (!q) return true;
248-
const triggerName = a.trigger_name || a.trigger_v2_name || a.triggerName || '';
242+
const triggerName = a.trigger_name || a.triggerName || '';
249243
const normalizedTrigger = String(triggerName).trim().toLowerCase();
250244
return normalizedTrigger.startsWith(q);
251245
};
@@ -279,7 +273,7 @@ export default class DashboardPpl extends Component {
279273
);
280274

281275
const dir = sortDirection === 'asc' ? 1 : -1;
282-
const sortFieldEffective = sortField === 'start_time' ? 'triggered_time' : sortField;
276+
const sortFieldEffective = sortField;
283277
const val = (obj) => _.get(obj, sortFieldEffective);
284278
filtered = filtered.sort((a, b) => {
285279
const av = val(a);
@@ -304,9 +298,9 @@ export default class DashboardPpl extends Component {
304298
const alertsByTriggers = groupAlertsByTrigger(filtered, true).map((row) => {
305299
const latest = _.maxBy(
306300
row.alerts || [],
307-
(a) => (a && (a.triggered_time ?? a.start_time)) || 0
301+
(a) => (a && (a.start_time ?? a.triggered_time)) || 0
308302
);
309-
const ts = latest?.triggered_time ?? latest?.start_time ?? null;
303+
const ts = latest?.start_time ?? latest?.triggered_time ?? null;
310304
return { ...row, lastTriggeredTime: ts };
311305
});
312306
this.setState(

public/pages/Dashboard/utils/tableUtilsPpl.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ export const alertColumnsPpl = (
215215
}
216216
let value = timestamp;
217217
if (value == null && Array.isArray(row?.alerts) && row.alerts.length) {
218-
const newest = _.maxBy(row.alerts, (a) => (a?.triggered_time ?? a?.start_time) || 0);
219-
value = newest?.triggered_time ?? newest?.start_time ?? null;
218+
const newest = _.maxBy(row.alerts, (a) => (a?.start_time ?? a?.triggered_time) || 0);
219+
value = newest?.start_time ?? newest?.triggered_time ?? null;
220220
}
221221
return renderUtcTime(value);
222222
},

0 commit comments

Comments
 (0)