Alerting: Fix Alerts page filtering (#115178)

* Alerting: fix filtering on alerts page

* exclude __name__ from label filter dropdown list
This commit is contained in:
Lauren
2025-12-12 08:16:55 +00:00
committed by GitHub
parent 35c214249f
commit 3cdfe34ec8
3 changed files with 7 additions and 2 deletions
@@ -58,6 +58,8 @@ export const triageScene = new EmbeddedSceneWithContext({
baseFilters: [],
layout: 'combobox',
expressionBuilder: prometheusExpressionBuilder,
// Filter out __name__ from options as this is the metric name not a filterable label
tagKeyRegexFilter: /^(?!__name__$).*/,
}),
],
}),
@@ -33,7 +33,7 @@ export function convertToWorkbenchRows(series: DataFrame[], groupBy: string[] =
const ruleUIDIndex = fieldIndex.get('grafana_rule_uid');
// These should always exist due to validation above, but handle gracefully
if (!alertnameIndex || !folderIndex || !ruleUIDIndex) {
if (alertnameIndex === undefined || folderIndex === undefined || ruleUIDIndex === undefined) {
return [];
}
@@ -4,9 +4,12 @@ import { AdHocFilterWithLabels } from '@grafana/scenes';
* Custom expression builder for Prometheus that properly handles regex operators.
* Unlike the default builder, this doesn't escape regex metacharacters when using =~ or !~
* operators, allowing users to enter raw regex patterns.
*
* Note: __name__ is excluded from filters as it represents the metric name itself,
* not a label, and should be handled separately in query construction.
*/
export function prometheusExpressionBuilder(filters: AdHocFilterWithLabels[]): string {
const applicableFilters = filters.filter((f) => !f.nonApplicable && !f.hidden);
const applicableFilters = filters.filter((f) => !f.nonApplicable && !f.hidden && f.key !== '__name__');
return applicableFilters.map(renderFilter).join(',');
}