Alerting: Fix Alerts page filtering (#115178)
* Alerting: fix filtering on alerts page * exclude __name__ from label filter dropdown list
This commit is contained in:
@@ -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(',');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user