-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(renterd): generate debug report zip
- Loading branch information
1 parent
3d2a152
commit 2032aef
Showing
13 changed files
with
420 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'renterd': minor | ||
--- | ||
|
||
There is now an option to generate a metadata report for debugging purposes. It can be accessed from the cmd+k menu. Closes https://github.com/SiaFoundation/renterd/issues/1119 Closes https://github.com/SiaFoundation/renterd/issues/1279 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'hostd': minor | ||
'renterd': minor | ||
--- | ||
|
||
The cmd+k menu / command palette dialog now announces itself via assistive technology. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@siafoundation/renterd-react': minor | ||
'@siafoundation/renterd-types': minor | ||
--- | ||
|
||
The alerts API limit and skip params are now optional. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,221 @@ | ||
import { | ||
Dialog, | ||
ConfigFields, | ||
useOnInvalid, | ||
FormSubmitButton, | ||
useDialogFormHelpers, | ||
FieldSwitch, | ||
Label, | ||
} from '@siafoundation/design-system' | ||
import { | ||
useAlerts, | ||
useAutopilotConfig, | ||
useContracts, | ||
useSettingsGouging, | ||
useSettingsPinned, | ||
useSettingsUpload, | ||
} from '@siafoundation/renterd-react' | ||
import { useCallback, useMemo } from 'react' | ||
import { useForm } from 'react-hook-form' | ||
import JSZip from 'jszip' | ||
import { saveAs } from 'file-saver' | ||
import { useApp } from '../contexts/app' | ||
|
||
function getDefaultValues() { | ||
return { | ||
contracts: true, | ||
alerts: true, | ||
autopilot: true, | ||
gouging: true, | ||
upload: true, | ||
pinned: true, | ||
} | ||
} | ||
|
||
type Values = ReturnType<typeof getDefaultValues> | ||
|
||
function getFields(): ConfigFields<Values, never> { | ||
return { | ||
contracts: { | ||
type: 'boolean', | ||
title: 'Contracts', | ||
validation: {}, | ||
}, | ||
alerts: { | ||
type: 'boolean', | ||
title: 'Alerts', | ||
validation: {}, | ||
}, | ||
autopilot: { | ||
type: 'boolean', | ||
title: 'Autopilot', | ||
validation: {}, | ||
}, | ||
gouging: { | ||
type: 'boolean', | ||
title: 'Gouging', | ||
validation: {}, | ||
}, | ||
upload: { | ||
type: 'boolean', | ||
title: 'Upload', | ||
validation: {}, | ||
}, | ||
pinned: { | ||
type: 'boolean', | ||
title: 'Pinned', | ||
validation: {}, | ||
}, | ||
} | ||
} | ||
|
||
type Props = { | ||
trigger?: React.ReactNode | ||
open: boolean | ||
onOpenChange: (val: boolean) => void | ||
} | ||
|
||
export function DebugDialog({ trigger, open, onOpenChange }: Props) { | ||
const { isAutopilotEnabled } = useApp() | ||
const defaultValues = useMemo(() => getDefaultValues(), []) | ||
|
||
const contracts = useContracts() | ||
const alerts = useAlerts({ | ||
params: { | ||
limit: 1000, | ||
}, | ||
}) | ||
const autopilot = useAutopilotConfig({ | ||
disabled: !isAutopilotEnabled, | ||
}) | ||
const gouging = useSettingsGouging() | ||
const upload = useSettingsUpload() | ||
const pinned = useSettingsPinned() | ||
|
||
const form = useForm({ | ||
mode: 'all', | ||
defaultValues, | ||
}) | ||
|
||
const { handleOpenChange } = useDialogFormHelpers({ | ||
form, | ||
onOpenChange, | ||
defaultValues, | ||
initKey: [name], | ||
}) | ||
|
||
const onValid = useCallback( | ||
async (values: Values) => { | ||
const zip = new JSZip() | ||
|
||
// Add all the data to the zip file as JSON files. | ||
if (values.alerts) { | ||
zip.file('alerts.json', JSON.stringify(alerts.data, null, 2)) | ||
} | ||
if (values.contracts) { | ||
zip.file('contracts.json', JSON.stringify(contracts.data, null, 2)) | ||
} | ||
if (isAutopilotEnabled && values.autopilot) { | ||
zip.file('autopilot.json', JSON.stringify(autopilot.data, null, 2)) | ||
} | ||
if (values.gouging) { | ||
zip.file('gouging.json', JSON.stringify(gouging.data, null, 2)) | ||
} | ||
if (values.upload) { | ||
zip.file('upload.json', JSON.stringify(upload.data, null, 2)) | ||
} | ||
if (values.pinned) { | ||
zip.file('pinned.json', JSON.stringify(pinned.data, null, 2)) | ||
} | ||
|
||
// Generate the zip file. | ||
const blob = await zip.generateAsync({ type: 'blob' }) | ||
|
||
// Trigger download. | ||
saveAs(blob, 'renterd-debug.zip') | ||
}, | ||
[ | ||
isAutopilotEnabled, | ||
contracts.data, | ||
alerts.data, | ||
autopilot.data, | ||
gouging.data, | ||
upload.data, | ||
pinned.data, | ||
] | ||
) | ||
|
||
const fields = useMemo(() => getFields(), []) | ||
|
||
const onInvalid = useOnInvalid(fields) | ||
|
||
return ( | ||
<Dialog | ||
title="Generate a debug report" | ||
description="Select which metadata files to include in the generated report." | ||
trigger={trigger} | ||
open={open} | ||
onOpenChange={handleOpenChange} | ||
contentVariants={{ | ||
className: 'w-[400px]', | ||
}} | ||
onSubmit={form.handleSubmit(onValid, onInvalid)} | ||
> | ||
<div className="flex flex-col gap-6 pt-4"> | ||
<div className="flex flex-col gap-2"> | ||
<Label size="14" color="subtle"> | ||
General | ||
</Label> | ||
<div className="flex gap-4"> | ||
<FieldSwitch | ||
size="small" | ||
form={form} | ||
fields={fields} | ||
name="contracts" | ||
/> | ||
<FieldSwitch | ||
size="small" | ||
form={form} | ||
fields={fields} | ||
name="alerts" | ||
/> | ||
</div> | ||
</div> | ||
<div className="flex flex-col gap-2"> | ||
<Label size="14" color="subtle"> | ||
Configuration | ||
</Label> | ||
<div className="flex gap-4"> | ||
{isAutopilotEnabled && ( | ||
<FieldSwitch | ||
size="small" | ||
form={form} | ||
fields={fields} | ||
name="autopilot" | ||
/> | ||
)} | ||
<FieldSwitch | ||
size="small" | ||
form={form} | ||
fields={fields} | ||
name="gouging" | ||
/> | ||
<FieldSwitch | ||
size="small" | ||
form={form} | ||
fields={fields} | ||
name="upload" | ||
/> | ||
<FieldSwitch | ||
size="small" | ||
form={form} | ||
fields={fields} | ||
name="pinned" | ||
/> | ||
</div> | ||
</div> | ||
<FormSubmitButton form={form}>Generate</FormSubmitButton> | ||
</div> | ||
</Dialog> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.