-
Notifications
You must be signed in to change notification settings - Fork 89
Add Frontend Support for Peer Debug Bundle Trigger and History #485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aliamerj
wants to merge
5
commits into
netbirdio:main
Choose a base branch
from
aliamerj:job-ui
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,26 @@ | ||
| // Parameters for bundle job | ||
| export interface BundleJobParameters { | ||
| anonymize: boolean | ||
| bundle_for: boolean | ||
| bundle_for_time: number | ||
| log_file_count: number | ||
| } | ||
|
|
||
| // Base job | ||
| interface BaseJob { | ||
| ID: string | ||
| AccountID: string | ||
| CompletedAt: Date | null | ||
| CreatedAt: Date | ||
| FailedReason: string | null | ||
| PeerID: string | ||
| Result: string | null | ||
| Status: "pending" | "successed" | "failed" | ||
| TriggeredBy: string | ||
| } | ||
heisbrot marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Discriminated union | ||
| export type Job = | ||
| | (BaseJob & { Type: "bundle"; Parameters: BundleJobParameters }) | ||
| | (BaseJob & { Type: "other"; Parameters: Record<string, any> }) // fallback for unknown types | ||
|
|
||
This file contains hidden or 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,119 @@ | ||
| import FancyToggleSwitch from "@/components/FancyToggleSwitch"; | ||
| import { ModalClose, ModalContent, ModalFooter } from "@/components/modal/Modal"; | ||
| import ModalHeader from "@/components/modal/ModalHeader"; | ||
| import { BugPlay, PlusCircle } from "lucide-react"; | ||
| import { Label } from "@/components/Label"; | ||
| import { Input } from "@/components/Input"; | ||
| import Button from "@/components/Button"; | ||
| import { useState, useMemo } from "react"; | ||
| import HelpText from "@/components/HelpText"; | ||
| import { useApiCall } from "@/utils/api"; | ||
| import { useSWRConfig } from "swr"; | ||
| import { notify } from "@/components/Notification"; | ||
|
|
||
| type Props = { | ||
| peerID: string; | ||
| onSuccess: () => void; | ||
| }; | ||
|
|
||
| export function CreateDebugJobModalContent({ peerID, onSuccess }: Props) { | ||
| const jobRequest = useApiCall(`/peers/${peerID}/jobs`, true); | ||
| const { mutate } = useSWRConfig(); | ||
|
|
||
| const [bundleForTime, setBundleForTime] = useState<number>(5); | ||
| const [logFileCount, setLogFileCount] = useState<number>(10); | ||
| const [anonymize, setAnonymize] = useState<boolean>(true); | ||
|
|
||
| const isValid = useMemo(() => { | ||
| return bundleForTime > 0 && logFileCount > 0; | ||
| }, [bundleForTime, logFileCount]); | ||
|
|
||
| const createDebugJob = async () => { | ||
| notify({ | ||
| title: "Create Debug Job", | ||
| description: "Debug job triggered successfully.", | ||
| loadingMessage: "Creating job...", | ||
| promise: jobRequest | ||
| .post({ | ||
| Type: "bundle", | ||
| Parameters: { | ||
| anonymize, | ||
| bundle_for: true, | ||
| bundle_for_time: bundleForTime, | ||
| log_file_count: logFileCount, | ||
| }, | ||
| }) | ||
| .then((job) => { | ||
| mutate(`/peers/${peerID}/jobs`); | ||
| onSuccess(); | ||
| return job; | ||
| }), | ||
| }); | ||
| }; return ( | ||
| <ModalContent maxWidthClass="max-w-lg"> | ||
heisbrot marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <ModalHeader | ||
| icon={<BugPlay size={20} />} | ||
| title="Create Debug Job" | ||
| description="Generate a debug bundle on this peer with logs and diagnostics. Useful for troubleshooting without CLI access." | ||
| color="netbird" | ||
| /> | ||
|
|
||
| <div className="pb-6"> | ||
| <div className="px-8 flex flex-col gap-6"> | ||
| <div> | ||
| <Label>Bundle Duration (minutes)</Label> | ||
| <HelpText> | ||
| Defines how long logs will be collected for the debug bundle. | ||
| </HelpText> | ||
| <Input | ||
| type="number" | ||
| min={1} | ||
| max={60} | ||
| value={bundleForTime} | ||
| onChange={(e) => setBundleForTime(Number(e.target.value))} | ||
| /> | ||
| </div> | ||
|
|
||
| <div> | ||
| <Label>Log File Count</Label> | ||
| <HelpText> | ||
| Maximum number of log files to include in the bundle. | ||
| </HelpText> | ||
| <Input | ||
| type="number" | ||
| min={1} | ||
| max={50} | ||
| value={logFileCount} | ||
| onChange={(e) => setLogFileCount(Number(e.target.value))} | ||
| /> | ||
| </div> | ||
|
|
||
| <FancyToggleSwitch | ||
| value={anonymize} | ||
| onChange={setAnonymize} | ||
| label="Anonymize Data" | ||
| helpText="Remove sensitive information (IP addresses, peer IDs) from the bundle." | ||
| /> | ||
heisbrot marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </div> | ||
| </div> | ||
|
|
||
|
|
||
| <ModalFooter className="items-center"> | ||
| <div className="flex gap-3 w-full justify-end"> | ||
| <ModalClose asChild> | ||
| <Button variant="secondary">Cancel</Button> | ||
| </ModalClose> | ||
| <Button | ||
| variant="primary" | ||
| disabled={!isValid} | ||
| onClick={createDebugJob} | ||
| > | ||
| <PlusCircle size={16} /> | ||
| Create Job | ||
| </Button> | ||
| </div> | ||
| </ModalFooter> | ||
| </ModalContent> | ||
| ); | ||
| } | ||
|
|
||
This file contains hidden or 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,56 @@ | ||
| import Paragraph from '@/components/Paragraph'; | ||
| import SkeletonTable, { SkeletonTableHeader } from '@/components/skeletons/SkeletonTable'; | ||
| import { usePortalElement } from '@/hooks/usePortalElement'; | ||
| import React, { Suspense, lazy } from 'react' | ||
| import { RemoteJobDropdownButton } from './RemoteJobDropdownButton'; | ||
| import useFetchApi from '@/utils/api'; | ||
| import { Job } from '@/interfaces/Job'; | ||
| const PeerRemoteJobsTable = lazy( | ||
| () => import("@/modules/peer/PeerRemoteJobsTable"), | ||
| ); | ||
| type Props = { | ||
| peerID: string; | ||
| }; | ||
|
|
||
| export const PeerRemoteJobsSection = ({ peerID }: Props) => { | ||
| const { data: jobs, isLoading } = useFetchApi<Job[]>(`/peers/${peerID}/jobs`); | ||
| const { ref: headingRef, portalTarget } = usePortalElement<HTMLHeadingElement>(); | ||
|
|
||
| return ( | ||
| <div className="pb-10 px-8"> | ||
| <div className="max-w-6xl"> | ||
| <div className="flex justify-between items-center mb-5"> | ||
| <div> | ||
| <h2 ref={headingRef}>Remote Jobs</h2> | ||
| <Paragraph> | ||
| Remotely trigger actions such as debug bundles or other tasks on | ||
| this peer, without requiring CLI access. | ||
| </Paragraph> | ||
heisbrot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </div> | ||
|
|
||
| <div className="inline-flex gap-4 justify-end"> | ||
| <RemoteJobDropdownButton /> | ||
| </div> | ||
| </div> | ||
|
|
||
| <Suspense | ||
| fallback={ | ||
| <div> | ||
| <SkeletonTableHeader className="!p-0" /> | ||
| <div className="mt-8 w-full"> | ||
| <SkeletonTable withHeader={false} /> | ||
| </div> | ||
| </div> | ||
| } | ||
| > | ||
| <PeerRemoteJobsTable | ||
| peerID={peerID} | ||
| jobs={jobs} | ||
| isLoading={isLoading} | ||
| headingTarget={portalTarget} | ||
| /> | ||
|
|
||
| </Suspense> | ||
| </div> | ||
| </div>) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.