From e53c8fd040d09865e53bd85e449583e81d2f45e5 Mon Sep 17 00:00:00 2001 From: GitCaddy Date: Sun, 11 Jan 2026 15:38:01 +0000 Subject: [PATCH] feat: add Check Now button for on-demand bandwidth testing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add BandwidthTestRequestedAt field to ActionRunner model - Update to actions-proto-go v0.5.7 with RequestBandwidthTest field - Add RunnerRequestBandwidthTest handler and route - Update FetchTask to check and return bandwidth test request flag - Add Check Now button to runner capabilities panel - Add locale strings for bandwidth test feature 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- go.mod | 2 +- go.sum | 4 +-- models/actions/runner.go | 2 ++ options/locale/locale_en-US.json | 3 ++ routers/api/actions/runner/runner.go | 17 ++++++++-- routers/web/shared/actions/runners.go | 40 +++++++++++++++++++++++ routers/web/web.go | 1 + templates/shared/actions/runner_edit.tmpl | 20 ++++++++++-- 8 files changed, 82 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index f38e9ac96b..298bff8974 100644 --- a/go.mod +++ b/go.mod @@ -314,7 +314,7 @@ replace github.com/nektos/act => gitea.com/gitea/act v0.261.7-0.20251003180512-a replace git.sr.ht/~mariusor/go-xsd-duration => gitea.com/gitea/go-xsd-duration v0.0.0-20220703122237-02e73435a078 // Use GitCaddy fork with capability support -replace code.gitea.io/actions-proto-go => git.marketally.com/gitcaddy/actions-proto-go v0.5.6 +replace code.gitea.io/actions-proto-go => git.marketally.com/gitcaddy/actions-proto-go v0.5.7 exclude github.com/gofrs/uuid v3.2.0+incompatible diff --git a/go.sum b/go.sum index 4519defb73..2341a2b467 100644 --- a/go.sum +++ b/go.sum @@ -29,8 +29,8 @@ dario.cat/mergo v1.0.2/go.mod h1:E/hbnu0NxMFBjpMIE34DRGLWqDy0g5FuKDhCb31ngxA= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= -git.marketally.com/gitcaddy/actions-proto-go v0.5.6 h1:G7T0vpx8HyCFWd0YMJ9sp8rCsWtzFrCJK4BMdOFJa1A= -git.marketally.com/gitcaddy/actions-proto-go v0.5.6/go.mod h1:RPu21UoRD3zSAujoZR6LJwuVNa2uFRBveadslczCRfQ= +git.marketally.com/gitcaddy/actions-proto-go v0.5.7 h1:RUbafr3Vkw2l4WfSwa+oF+Ihakbm05W0FlAmXuQrDJc= +git.marketally.com/gitcaddy/actions-proto-go v0.5.7/go.mod h1:RPu21UoRD3zSAujoZR6LJwuVNa2uFRBveadslczCRfQ= gitea.com/gitea/act v0.261.7-0.20251003180512-ac6e4b751763 h1:ohdxegvslDEllZmRNDqpKun6L4Oq81jNdEDtGgHEV2c= gitea.com/gitea/act v0.261.7-0.20251003180512-ac6e4b751763/go.mod h1:Pg5C9kQY1CEA3QjthjhlrqOC/QOT5NyWNjOjRHw23Ok= gitea.com/gitea/go-xsd-duration v0.0.0-20220703122237-02e73435a078 h1:BAFmdZpRW7zMQZQDClaCWobRj9uL1MR3MzpCVJvc5s4= diff --git a/models/actions/runner.go b/models/actions/runner.go index 8207329935..61c8a67958 100644 --- a/models/actions/runner.go +++ b/models/actions/runner.go @@ -64,6 +64,8 @@ type ActionRunner struct { Ephemeral bool `xorm:"ephemeral NOT NULL DEFAULT false"` // CapabilitiesJSON stores structured capability information for AI consumption CapabilitiesJSON string `xorm:"TEXT"` + // BandwidthTestRequestedAt tracks when a bandwidth test was requested by admin + BandwidthTestRequestedAt timeutil.TimeStamp `xorm:"index"` Created timeutil.TimeStamp `xorm:"created"` Updated timeutil.TimeStamp `xorm:"updated"` diff --git a/options/locale/locale_en-US.json b/options/locale/locale_en-US.json index 46c6ea0a87..839ebfba5c 100644 --- a/options/locale/locale_en-US.json +++ b/options/locale/locale_en-US.json @@ -3714,6 +3714,9 @@ "actions.runners.capabilities.disk_warning": "Low disk space", "actions.runners.capabilities.disk_critical": "Critical: disk almost full", "actions.runners.capabilities.bandwidth": "Network Bandwidth", + "actions.runners.bandwidth_test_requested": "Bandwidth test requested. Results will appear on next poll.", + "actions.runners.bandwidth_test_request_failed": "Failed to request bandwidth test.", + "actions.runners.check_bandwidth_now": "Check Now", "actions.runs.all_workflows": "All Workflows", "actions.runs.commit": "Commit", "actions.runs.scheduled": "Scheduled", diff --git a/routers/api/actions/runner/runner.go b/routers/api/actions/runner/runner.go index 03befa2bad..4aee483504 100644 --- a/routers/api/actions/runner/runner.go +++ b/routers/api/actions/runner/runner.go @@ -177,9 +177,22 @@ func (s *Service) FetchTask( task = t } } + + // Check if admin requested a bandwidth test + requestBandwidthTest := false + if runner.BandwidthTestRequestedAt > 0 { + requestBandwidthTest = true + // Clear the request after sending + runner.BandwidthTestRequestedAt = 0 + if err := actions_model.UpdateRunner(ctx, runner, "bandwidth_test_requested_at"); err != nil { + log.Warn("failed to clear bandwidth test request: %v", err) + } + } + res := connect.NewResponse(&runnerv1.FetchTaskResponse{ - Task: task, - TasksVersion: latestVersion, + Task: task, + TasksVersion: latestVersion, + RequestBandwidthTest: requestBandwidthTest, }) return res, nil } diff --git a/routers/web/shared/actions/runners.go b/routers/web/shared/actions/runners.go index 006830d3e7..fa637ac5c8 100644 --- a/routers/web/shared/actions/runners.go +++ b/routers/web/shared/actions/runners.go @@ -15,6 +15,7 @@ import ( "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/templates" + "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web" shared_user "code.gitea.io/gitea/routers/web/shared/user" @@ -295,6 +296,45 @@ func ResetRunnerRegistrationToken(ctx *context.Context) { ctx.JSONRedirect(redirectTo) } +// RunnerRequestBandwidthTest handles admin request to trigger a bandwidth test +func RunnerRequestBandwidthTest(ctx *context.Context) { + rCtx, err := getRunnersCtx(ctx) + if err != nil { + ctx.ServerError("getRunnersCtx", err) + return + } + + runnerID := ctx.PathParamInt64("runnerid") + ownerID := rCtx.OwnerID + repoID := rCtx.RepoID + redirectTo := rCtx.RedirectLink + url.PathEscape(ctx.PathParam("runnerid")) + + runner, err := actions_model.GetRunnerByID(ctx, runnerID) + if err != nil { + log.Warn("RunnerRequestBandwidthTest.GetRunnerByID failed: %v, url: %s", err, ctx.Req.URL) + ctx.ServerError("RunnerRequestBandwidthTest.GetRunnerByID", err) + return + } + if !runner.EditableInContext(ownerID, repoID) { + ctx.NotFound(util.NewPermissionDeniedErrorf("no permission to edit this runner")) + return + } + + // Set the bandwidth test request timestamp + runner.BandwidthTestRequestedAt = timeutil.TimeStampNow() + err = actions_model.UpdateRunner(ctx, runner, "bandwidth_test_requested_at") + if err != nil { + log.Warn("RunnerRequestBandwidthTest.UpdateRunner failed: %v, url: %s", err, ctx.Req.URL) + ctx.Flash.Warning(ctx.Tr("actions.runners.bandwidth_test_request_failed")) + ctx.Redirect(redirectTo) + return + } + + log.Debug("RunnerRequestBandwidthTest success: %s", ctx.Req.URL) + ctx.Flash.Success(ctx.Tr("actions.runners.bandwidth_test_requested")) + ctx.Redirect(redirectTo) +} + // RunnerDeletePost response for deleting runner func RunnerDeletePost(ctx *context.Context) { rCtx, err := getRunnersCtx(ctx) diff --git a/routers/web/web.go b/routers/web/web.go index 09e6865601..1cc2f6d2a4 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -510,6 +510,7 @@ func registerWebRoutes(m *web.Router) { m.Combo("/{runnerid}").Get(shared_actions.RunnersEdit). Post(web.Bind(forms.EditRunnerForm{}), shared_actions.RunnersEditPost) m.Post("/{runnerid}/delete", shared_actions.RunnerDeletePost) + m.Post("/{runnerid}/bandwidth-test", shared_actions.RunnerRequestBandwidthTest) m.Post("/reset_registration_token", shared_actions.ResetRunnerRegistrationToken) }) } diff --git a/templates/shared/actions/runner_edit.tmpl b/templates/shared/actions/runner_edit.tmpl index 29221421ca..dabac76bf8 100644 --- a/templates/shared/actions/runner_edit.tmpl +++ b/templates/shared/actions/runner_edit.tmpl @@ -115,9 +115,9 @@ {{end}} - {{if .RunnerCapabilities.Bandwidth}}
+ {{if .RunnerCapabilities.Bandwidth}}
{{svg "octicon-arrow-down" 14}} {{printf "%.1f" .RunnerCapabilities.Bandwidth.DownloadMbps}} Mbps @@ -127,14 +127,30 @@ {{svg "octicon-clock" 14}} {{printf "%.0f" .RunnerCapabilities.Bandwidth.Latency}} ms {{end}} +
+ {{.CsrfTokenHtml}} + +
{{if .RunnerCapabilities.Bandwidth.TestedAt}}
Tested {{DateUtils.TimeSince .RunnerCapabilities.Bandwidth.TestedAt}}
{{end}} + {{else}} +
+ No data yet +
+ {{.CsrfTokenHtml}} + +
+
+ {{end}}
- {{end}} {{if .RunnerCapabilities.Limitations}}