Compare commits

...

2 Commits

Author SHA1 Message Date
nikhilmantri0902
e8e0f9a9d3 fix: added promql changes 2025-08-21 20:50:19 +05:30
Amlan Kumar Nandy
e5ab664483 fix: resolve sentry issues in alert list (#8878)
* fix: resolve sentry issues in alert list

* chore: update the key

---------

Co-authored-by: srikanthccv <srikanth.chekuri92@gmail.com>
2025-08-21 19:21:15 +05:30
7 changed files with 32 additions and 16 deletions

View File

@@ -23,7 +23,7 @@ export const flattenLabels = (labels: Labels): ILabelRecord[] => {
if (!hiddenLabels.includes(key)) {
recs.push({
key,
value: labels[key],
value: labels[key] || '',
});
}
});

View File

@@ -272,12 +272,11 @@ function ListAlert({ allAlertRules, refetch }: ListAlertProps): JSX.Element {
width: 80,
key: 'severity',
sorter: (a, b): number =>
(a.labels ? a.labels.severity.length : 0) -
(b.labels ? b.labels.severity.length : 0),
(a?.labels?.severity?.length || 0) - (b?.labels?.severity?.length || 0),
render: (value): JSX.Element => {
const objectKeys = Object.keys(value);
const objectKeys = value ? Object.keys(value) : [];
const withSeverityKey = objectKeys.find((e) => e === 'severity') || '';
const severityValue = value[withSeverityKey];
const severityValue = withSeverityKey ? value[withSeverityKey] : '-';
return <Typography>{severityValue}</Typography>;
},
@@ -290,7 +289,7 @@ function ListAlert({ allAlertRules, refetch }: ListAlertProps): JSX.Element {
align: 'center',
width: 100,
render: (value): JSX.Element => {
const objectKeys = Object.keys(value);
const objectKeys = value ? Object.keys(value) : [];
const withOutSeverityKeys = objectKeys.filter((e) => e !== 'severity');
if (withOutSeverityKeys.length === 0) {

View File

@@ -14,7 +14,7 @@ export type AlertHeaderProps = {
state: string;
alert: string;
id: string;
labels: Record<string, string>;
labels: Record<string, string | undefined> | undefined;
disabled: boolean;
};
};
@@ -23,13 +23,14 @@ function AlertHeader({ alertDetails }: AlertHeaderProps): JSX.Element {
const { alertRuleState } = useAlertRule();
const [updatedName, setUpdatedName] = useState(alertName);
const labelsWithoutSeverity = useMemo(
() =>
Object.fromEntries(
const labelsWithoutSeverity = useMemo(() => {
if (labels) {
return Object.fromEntries(
Object.entries(labels).filter(([key]) => key !== 'severity'),
),
[labels],
);
);
}
return {};
}, [labels]);
return (
<div className="alert-info">
@@ -43,7 +44,7 @@ function AlertHeader({ alertDetails }: AlertHeaderProps): JSX.Element {
</div>
</div>
<div className="bottom-section">
{labels.severity && <AlertSeverity severity={labels.severity} />}
{labels?.severity && <AlertSeverity severity={labels.severity} />}
{/* // TODO(shaheer): Get actual data when we are able to get alert firing from state from API */}
{/* <AlertStatus

View File

@@ -48,7 +48,7 @@ export interface RuleCondition {
seasonality?: string;
}
export interface Labels {
[key: string]: string;
[key: string]: string | undefined;
}
export interface AlertRuleStats {

View File

@@ -97,6 +97,14 @@ func PrepareMetricQuery(start, end int64, queryType v3.QueryType, panelType v3.P
}
func BuildPromQuery(promQuery *v3.PromQuery, step, start, end int64) *model.QueryRangeParams {
// Defensive clamp: avoid zero/negative step reaching the PromQL engine
if step <= 0 {
derived := common.MinAllowedStepInterval(start, end)
if derived <= 0 {
derived = 60
}
step = derived
}
return &model.QueryRangeParams{
Query: promQuery.Query,
Start: time.UnixMilli(start),

View File

@@ -875,6 +875,14 @@ func ParseQueryRangeParams(r *http.Request) (*v3.QueryRangeParamsV3, *model.ApiE
queryRangeParams.Start = queryRangeParams.End
}
// Ensure a valid, non-zero step for PromQL range queries.
// Some clients may omit the step; Prometheus engine panics if step == 0.
if queryRangeParams.CompositeQuery.QueryType == v3.QueryTypePromQL {
if queryRangeParams.Step <= 0 {
queryRangeParams.Step = common.MinAllowedStepInterval(queryRangeParams.Start, queryRangeParams.End)
}
}
// replace go template variables in clickhouse query
if queryRangeParams.CompositeQuery.QueryType == v3.QueryTypeClickHouseSQL {
for _, chQuery := range queryRangeParams.CompositeQuery.ClickHouseQueries {

View File

@@ -366,7 +366,7 @@ func (mc *migrateCommon) createAggregations(ctx context.Context, queryData map[s
aggregation = map[string]any{
"metricName": aggregateAttr["key"],
"temporality": queryData["temporality"],
"timeAggregation": aggregateOp,
"timeAggregation": queryData["timeAggregation"],
"spaceAggregation": queryData["spaceAggregation"],
}
if reduceTo, ok := queryData["reduceTo"].(string); ok {