Skip to content

Commit e5ab664

Browse files
fix: resolve sentry issues in alert list (#8878)
* fix: resolve sentry issues in alert list * chore: update the key --------- Co-authored-by: srikanthccv <[email protected]>
1 parent a3f32b3 commit e5ab664

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

frontend/src/container/FormAlertRules/labels/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const flattenLabels = (labels: Labels): ILabelRecord[] => {
2323
if (!hiddenLabels.includes(key)) {
2424
recs.push({
2525
key,
26-
value: labels[key],
26+
value: labels[key] || '',
2727
});
2828
}
2929
});

frontend/src/container/ListAlertRules/ListAlert.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,11 @@ function ListAlert({ allAlertRules, refetch }: ListAlertProps): JSX.Element {
272272
width: 80,
273273
key: 'severity',
274274
sorter: (a, b): number =>
275-
(a.labels ? a.labels.severity.length : 0) -
276-
(b.labels ? b.labels.severity.length : 0),
275+
(a?.labels?.severity?.length || 0) - (b?.labels?.severity?.length || 0),
277276
render: (value): JSX.Element => {
278-
const objectKeys = Object.keys(value);
277+
const objectKeys = value ? Object.keys(value) : [];
279278
const withSeverityKey = objectKeys.find((e) => e === 'severity') || '';
280-
const severityValue = value[withSeverityKey];
279+
const severityValue = withSeverityKey ? value[withSeverityKey] : '-';
281280

282281
return <Typography>{severityValue}</Typography>;
283282
},
@@ -290,7 +289,7 @@ function ListAlert({ allAlertRules, refetch }: ListAlertProps): JSX.Element {
290289
align: 'center',
291290
width: 100,
292291
render: (value): JSX.Element => {
293-
const objectKeys = Object.keys(value);
292+
const objectKeys = value ? Object.keys(value) : [];
294293
const withOutSeverityKeys = objectKeys.filter((e) => e !== 'severity');
295294

296295
if (withOutSeverityKeys.length === 0) {

frontend/src/pages/AlertDetails/AlertHeader/AlertHeader.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export type AlertHeaderProps = {
1414
state: string;
1515
alert: string;
1616
id: string;
17-
labels: Record<string, string>;
17+
labels: Record<string, string | undefined> | undefined;
1818
disabled: boolean;
1919
};
2020
};
@@ -23,13 +23,14 @@ function AlertHeader({ alertDetails }: AlertHeaderProps): JSX.Element {
2323
const { alertRuleState } = useAlertRule();
2424
const [updatedName, setUpdatedName] = useState(alertName);
2525

26-
const labelsWithoutSeverity = useMemo(
27-
() =>
28-
Object.fromEntries(
26+
const labelsWithoutSeverity = useMemo(() => {
27+
if (labels) {
28+
return Object.fromEntries(
2929
Object.entries(labels).filter(([key]) => key !== 'severity'),
30-
),
31-
[labels],
32-
);
30+
);
31+
}
32+
return {};
33+
}, [labels]);
3334

3435
return (
3536
<div className="alert-info">
@@ -43,7 +44,7 @@ function AlertHeader({ alertDetails }: AlertHeaderProps): JSX.Element {
4344
</div>
4445
</div>
4546
<div className="bottom-section">
46-
{labels.severity && <AlertSeverity severity={labels.severity} />}
47+
{labels?.severity && <AlertSeverity severity={labels.severity} />}
4748

4849
{/* // TODO(shaheer): Get actual data when we are able to get alert firing from state from API */}
4950
{/* <AlertStatus

frontend/src/types/api/alerts/def.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export interface RuleCondition {
4848
seasonality?: string;
4949
}
5050
export interface Labels {
51-
[key: string]: string;
51+
[key: string]: string | undefined;
5252
}
5353

5454
export interface AlertRuleStats {

pkg/transition/migrate_common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ func (mc *migrateCommon) createAggregations(ctx context.Context, queryData map[s
366366
aggregation = map[string]any{
367367
"metricName": aggregateAttr["key"],
368368
"temporality": queryData["temporality"],
369-
"timeAggregation": aggregateOp,
369+
"timeAggregation": queryData["timeAggregation"],
370370
"spaceAggregation": queryData["spaceAggregation"],
371371
}
372372
if reduceTo, ok := queryData["reduceTo"].(string); ok {

0 commit comments

Comments
 (0)