aboutsummaryrefslogtreecommitdiffstats
path: root/dashboard/app/api.go
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2024-01-09 16:27:55 +0100
committerAleksandr Nogikh <nogikh@google.com>2024-01-09 17:48:04 +0000
commitb438bd66d6f95113d52f25c25bfef0e963c8ce8d (patch)
treeaffa3733771acfc752397dc89a1c6e712d4d622c /dashboard/app/api.go
parent83b32fe8f20dc1e910866fa110b0d872df283f03 (diff)
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.
Diffstat (limited to 'dashboard/app/api.go')
-rw-r--r--dashboard/app/api.go29
1 files changed, 29 insertions, 0 deletions
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
+}