From b438bd66d6f95113d52f25c25bfef0e963c8ce8d Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Tue, 9 Jan 2024 16:27:55 +0100 Subject: dashboard: introduce an emergency stop mode Add an emergency stop button that can be used by any admin. After it's clicked two times, syzbot stops all reporting and recoding of new bugs. It's assumed that the stop mode is revoked by manually deleting an entry from the database. --- dashboard/app/api.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'dashboard/app/api.go') diff --git a/dashboard/app/api.go b/dashboard/app/api.go index 2dce92d55..6a84c758b 100644 --- a/dashboard/app/api.go +++ b/dashboard/app/api.go @@ -30,6 +30,7 @@ import ( "google.golang.org/appengine/v2" db "google.golang.org/appengine/v2/datastore" "google.golang.org/appengine/v2/log" + "google.golang.org/appengine/v2/user" ) func initAPIHandlers() { @@ -363,6 +364,10 @@ func addCommitInfoToBugImpl(c context.Context, bug *Bug, com dashapi.Commit) (bo } func apiJobPoll(c context.Context, r *http.Request, payload []byte) (interface{}, error) { + if stop, err := emergentlyStopped(c); err != nil || stop { + // The bot's operation was aborted. Don't accept new crash reports. + return &dashapi.JobPollResp{}, err + } req := new(dashapi.JobPollReq) if err := json.Unmarshal(payload, req); err != nil { return nil, fmt.Errorf("failed to unmarshal request: %w", err) @@ -699,6 +704,10 @@ const ( ) func apiReportCrash(c context.Context, ns string, r *http.Request, payload []byte) (interface{}, error) { + if stop, err := emergentlyStopped(c); err != nil || stop { + // The bot's operation was aborted. Don't accept new crash reports. + return &dashapi.ReportCrashResp{}, err + } req := new(dashapi.Crash) if err := json.Unmarshal(payload, req); err != nil { return nil, fmt.Errorf("failed to unmarshal request: %w", err) @@ -1632,3 +1641,23 @@ func apiSaveDiscussion(c context.Context, r *http.Request, payload []byte) (inte } return nil, mergeDiscussion(c, d) } + +func emergentlyStopped(c context.Context) (bool, error) { + keys, err := db.NewQuery("EmergencyStop"). + Limit(1). + KeysOnly(). + GetAll(c, nil) + if err != nil { + return false, err + } + return len(keys) > 0, nil +} + +func recordEmergencyStop(c context.Context) error { + key := db.NewKey(c, "EmergencyStop", "all", 0, nil) + _, err := db.Put(c, key, &EmergencyStop{ + Time: timeNow(c), + User: user.Current(c).Email, + }) + return err +} -- cgit mrf-deployment