Start monitoring as soon as a server connects

Merged
YO
3d ago
+1764-992

What

  • POST /license/connect takes an optional body { report?: LicenseMonitoringLevel }. The handler validates the level (unknown level: 400, nothing started), starts the connection, then saves the level with the same cloud_report_update audit event as PUT /license/monitoring. A level fixed by cloud.report wins and the request still succeeds. Connect errors (already licensed, license set outside Dagu) leave the level unchanged.
  • The connect URL returned by POST and GET /license/connect carries report=<level> when the level in effect reports, so the approval page in Dagu Console can state what will be reported. internal/license stays unaware of reporting; the handler composes both. dagu license activate is unchanged.
  • The reporter checks for credentials every 5 seconds, instead of every report interval, while the level in effect reports and no license is installed yet. The first report now follows an approval within seconds. A server that reports nothing keeps its interval.
  • License page, "Monitor this server for free" card: the admin picks Health only or Health and run status (default) before connecting. The card reuses the monitoring dialog's choices and "Never sent" line, says reporting starts as soon as the server connects, and shows a level fixed by cloud.report as text, sending no choice. The status is fetched for this card on Community servers too. After approval, no "what to report" prompt appears, and the Monitoring card shows the chosen level at once. "Try again" keeps the choice. The header's "Connect to Dagu Console" keeps today's behavior.
  • Sign-in and setup keep the requested page: login returns to pathname, search, and hash; a server without an admin account remembers the target through setup and returns there after the account is created. Only in-app paths are followed (//host and /\host fall back to /).
  • RFC 002, Browser approval: the admin may choose the report level when starting the connection; the URL carries it as report; reporting starts once the license is granted.

Why

"Connect for free" left the server connected but not monitored: reporting stayed off until the admin returned to the Dagu tab and answered a dialog, and the console approval page said monitoring stays off. Even after a level was chosen, the first report lagged up to a minute. Links such as the startup banner's /license#monitoring also lost their section, or the whole page on a fresh install, on the way through sign-in or setup.

Test plan

Regression tests, confirmed failing before their fix:

  • TestLicenseConnect_Report (chosen level, configured level wins, unknown level, nothing reported) in internal/service/frontend/api/v1/license_test.go. "already licensed" passed before too, since the level was never touched.
  • TestReportWithoutCredentials/reporting in internal/cloudreport/reporter_test.go (got 1m, want 5s). /off guards the unchanged interval.
  • ui/src/pages/license/__tests__/index.test.tsx: "starts the same request from the free monitoring offer" (default runs sent), "reports the level chosen in the offer without asking again", "shows a level set in the configuration in the offer".
  • ui/src/pages/__tests__/login.test.tsx: "returns to the requested page after sign-in" (got /license), "returns only to a page of the app" (got /example.com).
  • ui/src/pages/__tests__/setup.test.tsx: "returns to the requested page after creating the admin account" (got /).
  • New E2E: e2e/license-experience.spec.ts "starts monitoring when a server connects from the free offer" (390px, no horizontal scroll, posted body, no prompt after approval).

Commands run:

  • make test TEST_TARGET=./internal/service/frontend/... (1637 tests pass)
  • make test TEST_TARGET=./internal/cloudreport/... (86 pass)
  • make test TEST_TARGET=./internal/license/... (276 pass)
  • make fmt (no changes beyond this PR), make check (0 issues, all GOOS)
  • cd ui && pnpm test (1497 pass), pnpm typecheck, pnpm build (via make test-e2e)
  • make test-e2e PLAYWRIGHT_TEST_ARGS="e2e/license-experience.spec.ts e2e/getting-started.spec.ts e2e/auth-flows.spec.ts": 6 passed, 4 skipped. The 4 auth-flows tests skip locally without DAGU_LICENSE_PRIVKEY_B64.

Summary by cubic

Choosing what the server reports is now part of connecting for free, so monitoring starts as soon as Dagu Console grants the license instead of waiting for an admin to answer a later dialog, and the first report arrives within seconds of approval.

  • POST /license/connect accepts an optional report level and saves it, unless cloud.report in the configuration fixes the level. Unknown levels return 400.
  • The connect URL carries report=<level>, so the approval page in Dagu Console states what will be reported. When the level cannot be read, starting or reading a connection request fails rather than offer a link that understates reporting.
  • A server that is to report but has no license checks for credentials every 5 seconds, and turning reporting on ends a current wait at once; the first report follows approval within seconds.
  • The license page's free monitoring card lets the admin choose Health or Health and run status before connecting. The card's description matches the chosen level, the choice is skipped when a level is set by config, and no "what to report" prompt appears after approval.
  • Login and setup now return to the full requested path, including query and hash, so section links like /license#monitoring survive sign-in or first-time setup.

Migration

  • No migration steps needed; the new request body is optional and the connect UI defaults to run status.

Summary by CodeRabbit

  • New Features
    • Choose a monitoring level when connecting a server to Dagu Console. If reporting is already configured on the server, that setting takes precedence.
    • Reporting starts when the license is granted, unless reporting is configured as off. The connection flow explains what each option reports.
    • After signing in or completing setup, you’re returned to the page you originally requested.
  • Bug Fixes
    • Failed connection attempts retry with your selected monitoring level.
    • Servers with reporting enabled check for missing credentials every five seconds, helping reporting resume sooner when credentials become available.