Skip to content

Commit c1cf4e6

Browse files
Merge pull request #672 from PeterYurkovich/ou-1118
OU-1118: include namespace label in example query
2 parents dbf1a3d + ad98165 commit c1cf4e6

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

web/src/components/MetricsPage.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,7 @@ const QueryBrowserWrapper: FC<{
10571057
}> = ({ customDataSourceName, customDataSource, customDatasourceError, units }) => {
10581058
const { t } = useTranslation(process.env.I18N_NAMESPACE);
10591059
const { plugin } = useMonitoring();
1060+
const [activeNamespace] = useActiveNamespace();
10601061

10611062
const dispatch = useDispatch();
10621063

@@ -1114,7 +1115,11 @@ const QueryBrowserWrapper: FC<{
11141115
const insertExampleQuery = () => {
11151116
const focusedIndex = focusedQuery?.index ?? 0;
11161117
const index = queries[focusedIndex] ? focusedIndex : 0;
1117-
const text = 'sort_desc(sum(sum_over_time(ALERTS{alertstate="firing"}[24h])) by (alertname))';
1118+
const labelMatchers =
1119+
activeNamespace === ALL_NAMESPACES_KEY
1120+
? '{alertstate="firing"}'
1121+
: `{alertstate="firing", namespace="${activeNamespace}"}`;
1122+
const text = `sort_desc(sum(sum_over_time(ALERTS${labelMatchers}[24h])) by (alertname))`;
11181123
dispatch(queryBrowserPatchQuery(index, { isEnabled: true, query: text, text }));
11191124
};
11201125

0 commit comments

Comments
 (0)