Alerting: Allow downloading alert rules from subpath (#64136)

This commit is contained in:
Gilles De Mey 2023-03-03 14:34:06 +01:00 committed by GitHub
parent 4a7fbea7a4
commit 3468804ff5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View File

@ -117,7 +117,7 @@ const ui = {
moreErrorsButton: byRole('button', { name: /more errors/ }), moreErrorsButton: byRole('button', { name: /more errors/ }),
editCloudGroupIcon: byTestId('edit-group'), editCloudGroupIcon: byTestId('edit-group'),
newRuleButton: byRole('link', { name: 'Create alert rule' }), newRuleButton: byRole('link', { name: 'Create alert rule' }),
exportButton: byRole('button', { name: /export/i }), exportButton: byRole('link', { name: /export/i }),
editGroupModal: { editGroupModal: {
dialog: byRole('dialog'), dialog: byRole('dialog'),
namespaceInput: byRole('textbox', { name: /^Namespace/ }), namespaceInput: byRole('textbox', { name: /^Namespace/ }),

View File

@ -27,14 +27,13 @@ import { fetchAllPromAndRulerRulesAction } from './state/actions';
import { useRulesAccess } from './utils/accessControlHooks'; import { useRulesAccess } from './utils/accessControlHooks';
import { RULE_LIST_POLL_INTERVAL_MS } from './utils/constants'; import { RULE_LIST_POLL_INTERVAL_MS } from './utils/constants';
import { getAllRulesSourceNames } from './utils/datasource'; import { getAllRulesSourceNames } from './utils/datasource';
import { createUrl } from './utils/url';
const VIEWS = { const VIEWS = {
groups: RuleListGroupView, groups: RuleListGroupView,
state: RuleListStateView, state: RuleListStateView,
}; };
const onExport = () => window.open('/api/v1/provisioning/alert-rules/export?download=true&format=yaml');
const RuleList = withErrorBoundary( const RuleList = withErrorBoundary(
() => { () => {
const dispatch = useDispatch(); const dispatch = useDispatch();
@ -111,9 +110,17 @@ const RuleList = withErrorBoundary(
</div> </div>
<Stack direction="row" gap={0.5}> <Stack direction="row" gap={0.5}>
{canReadProvisioning && ( {canReadProvisioning && (
<Button icon="download-alt" type="button" onClick={onExport}> <LinkButton
href={createUrl('/api/v1/provisioning/alert-rules/export', {
download: 'true',
format: 'yaml',
})}
icon="download-alt"
target="_blank"
rel="noopener"
>
Export Export
</Button> </LinkButton>
)} )}
{(canCreateGrafanaRules || canCreateCloudRules) && ( {(canCreateGrafanaRules || canCreateCloudRules) && (
<LinkButton <LinkButton