netbird icon indicating copy to clipboard operation
netbird copied to clipboard

[Management/Client] Trigger debug bundle runs from API/Dashboard (#4592)

Open pappz opened this issue 1 month ago • 2 comments

Bugfixes

Describe your changes

Issue ticket number and link

Stack

Checklist

  • [ ] Is it a bug fix
  • [ ] Is a typo/documentation fix
  • [x] Is a feature enhancement
  • [x] It is a refactor
  • [ ] Created tests that fail without the change (if possible)

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • [ ] I added/updated documentation for this change
  • [ ] Documentation is not needed for this change (explain why)

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/__

Summary by CodeRabbit

  • New Features

    • Jobs system: peers can create, list, and retrieve jobs (e.g., request debug bundle generation and upload).
    • API & UI: endpoints and models added for job requests/responses (bundle workloads).
  • Bug Fixes / Improvements

    • Status output now uses full status plus daemon version for more accurate summaries.
    • Log collection improved with fallbacks when primary logs are missing.
    • Debug bundle uploads use presigned streamed uploads for reliability.
  • Other

    • Debug bundles no longer include the prior standalone status string; status is produced differently.

✏️ Tip: You can customize this high-level summary in your review settings.

pappz avatar Nov 21 '25 12:11 pappz

Walkthrough

Adds a per-peer Job subsystem (streaming RPC, manager, persistence, client executor), refactors debug bundle flow (removes DebugBundleRequest.status, renames LogFile→LogPath, centralizes upload), and propagates logPath/profile config into client connect/engine flows. (50 words)

Changes

Cohort / File(s) Summary
Debug bundle refactor
client/proto/daemon.proto, client/cmd/debug.go, client/server/debug.go, client/internal/debug/debug.go, client/internal/debug/upload.go, client/internal/debug/upload_test.go, client/ui/debug.go
Removed status from DebugBundleRequest; renamed generator dependency LogFileLogPath; moved upload logic to client/internal/debug/upload.go (UploadDebugBundle); CLI/UI no longer builds or passes a status string; generator now seeds status from recorder/FullStatus when present.
Status conversion
client/cmd/status.go, client/status/status.go, client/status/status_test.go
ConvertToStatusOutputOverview now accepts *proto.FullStatus and explicit daemonVersion; added ToProtoFullStatus() and updated call sites to pass full status + version.
Client connect & engine
client/internal/connect.go, client/internal/engine.go, client/internal/engine_test.go, client/embed/embed.go, client/server/server.go, client/cmd/up.go
ConnectClient.Run gained logPath parameter; EngineConfig now includes LogPath and ProfileConfig; NewEngine receives profile config; engine integrates job executor, new syncResp mux, and job event processing; call sites updated to pass logPath and job wiring.
Job executor (client)
client/jobexec/executor.go
New Executor with BundleJob() to optionally wait, create debug bundle via debug.BundleGenerator, and upload via debug.UploadDebugBundle; adds MaxBundleWaitTime and ErrJobNotImplemented.
Server debug handling
client/server/debug.go
Server debug handler delegates upload to debug.UploadDebugBundle and uses LogPath in generator dependencies; removed local upload helpers and unused imports.
Management job subsystem
management/server/job/*, management/server/account.go, management/server/peer.go, management/server/account/manager.go, management/server/types/job.go
New job package with Channel and Manager for per-peer channels, pending-job tracking, send/response/cleanup; account manager wired to accept JobManager; job types, validation, mapping and events added.
Persistence for jobs
management/server/store/store.go, management/server/store/sql_store.go
Store interface extended with job methods; SqlStore implements Create/Complete/Get/MarkPendingAsFailed; migrations include types.Job.
Management API & proto
management/internals/shared/grpc/server.go, shared/management/proto/management.proto, shared/management/http/api/openapi.yml, shared/management/http/api/types.gen.go
Added streaming Job RPC and job protobuf messages (JobRequest/JobResponse/BundleParameters/BundleResult/JobStatus); gRPC server implements Job stream, handshake, response receiver and job forwarding; OpenAPI + generated types include Job workload union (bundle).
Client mgmt stream & mocks
shared/management/client/grpc.go, shared/management/client/client.go, shared/management/client/mock.go, shared/management/client/client_test.go
Client streaming logic extended with Job stream helpers; Client interface and MockClient gain Job(...) method; tests/mocks updated to exercise job stream.
HTTP handlers & API types
management/server/http/handlers/peers/peers_handler.go, shared/management/http/api/types.gen.go, shared/management/http/api/openapi.yml
Added HTTP endpoints for peer jobs (Create/List/Get); handlers map Job types to API responses; generated API models and OpenAPI paths/schemas for Job/Workload (bundle).
Tests & wiring updates
many client/ and management/server/*_test.go, client/cmd/testutil_test.go, shared/management/client/client_test.go
Tests and scaffolding updated to instantiate and pass job.NewJobManager(...) into BuildManager and NewServer call sites; mocks expanded with job hooks.
Server wiring & controllers
management/internals/server/controllers.go, management/internals/server/boot.go, management/internals/shared/grpc/*
Added BaseServer.JobManager() accessor; pass JobManager into gRPC server and manager builders; Server stores jobManager and NewServer signature extended.
API tooling / deps
shared/management/http/api/generate.sh, go.mod
oapi-codegen invocation updated to v2; go.mod added github.com/oapi-codegen/runtime v1.1.2 and indirect github.com/apapsch/go-jsonmerge/v2.
Other small changes
assorted files
Activity code for job creation added; mocks and imports updated; minor formatting adjustments across files.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Server as Management gRPC Server
    participant JobMgr as Job Manager
    participant Store as Store/DB
    participant Client as Peer Client (mgmt stream)
    participant Engine as Client Engine / Executor
    participant DebugGen as Debug Bundle Generator
    participant Upload as Upload service

    Server->>JobMgr: CreatePeerJob / SendJob(accountID, peerID, JobRequest)
    JobMgr->>Store: Persist job record (CreatePeerJob)
    Server->>Client: Stream JobRequest to peer (Job RPC)
    Client->>Engine: Executor.BundleJob(params, wait)
    Engine->>DebugGen: Generate bundle (uses LogPath, StatusRecorder)
    DebugGen-->>Engine: bundle file path
    Engine->>Upload: UploadDebugBundle(mgmURL, bundlePath)
    Upload-->>Engine: uploadKey
    Engine->>Client: Return JobResponse (uploadKey)
    Client->>Server: Stream JobResponse back
    Server->>JobMgr: HandleResponse(JobResponse)
    JobMgr->>Store: CompletePeerJob (mark succeeded/failed)

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

  • Areas needing careful review:
    • Job streaming handshake, encryption, retries and error semantics (shared/management/client/grpc.go; management/internals/shared/grpc/server.go)
    • Concurrency, channel lifecycle, pending-job tracking and cleanup (management/server/job/*)
    • Engine integration with job executor, shutdown ordering and goroutine waits (client/internal/engine.go; client/jobexec/executor.go)
    • Store migrations and correctness of job persistence queries/transactions (management/server/store/sql_store.go)
    • HTTP handlers and generated union type correctness and JSON marshaling (management/server/http/handlers/peers/peers_handler.go; shared/management/http/api/types.gen.go)

Possibly related PRs

  • netbirdio/netbird#4807 — overlaps in server controller/NewController signature changes and call-site updates.
  • netbirdio/netbird#4592 — directly overlaps debug bundle/status changes (DebugBundleRequest.status removal; LogFile→LogPath; status conversion updates).
  • netbirdio/netbird#4789 — related gRPC server and BuildManager wiring changes.

Suggested reviewers

  • pascal-fischer
  • crn4

Poem

🐰

I hopped through branches, soft and spry,
Laid down job channels, gave logs a try,
Bundles bundled, uploads sent on cue,
No more lone status strings to skew,
My little paws applaud the new sky.

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is incomplete. It shows only template structure with unchecked/generic items (Bugfixes header, empty 'Describe your changes', no issue link, unspecified documentation). Critical sections lack substance. Fill in the template: summarize changes, link the GitHub issue, explain why documentation is/isn't needed, and mark documentation checkbox accordingly.
Docstring Coverage ⚠️ Warning Docstring coverage is 15.87% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main feature: enabling debug bundle triggering from API/Dashboard with management/client scope. It directly reflects the primary change across the codebase.
✨ Finishing touches
  • [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment
  • [ ] Commit unit tests in branch feature/remote-debug-release

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Nov 21 '25 12:11 coderabbitai[bot]