Added crash filtering

Added version field to individual crash
This commit is contained in:
Caleb Gardner
2024-07-09 20:39:26 -05:00
parent a77d55924d
commit e43409923c
5 changed files with 21 additions and 8 deletions
+2
View File
@@ -61,6 +61,7 @@ Users are stored per backend and not per app.
{ {
count: 1, // We do not store duplicates. If a duplicate does occur count: 1, // We do not store duplicates. If a duplicate does occur
platform: "android", platform: "android",
appVersion: "v1.0.0", // Application version
error: "error", error: "error",
stack: "stacktrace" stack: "stacktrace"
} }
@@ -279,6 +280,7 @@ Request Body:
{ {
id: "UUID", // This is an ignored value, but it is highly recommended to include it to prevent reporting the same crash multiple times. id: "UUID", // This is an ignored value, but it is highly recommended to include it to prevent reporting the same crash multiple times.
platform: "android", platform: "android",
appVersion: "v1.0.0",
error: "error", error: "error",
stack: "stacktrace" stack: "stacktrace"
} }
+6
View File
@@ -9,6 +9,12 @@ type App interface {
CrashTable() CrashTable CrashTable() CrashTable
} }
// Allows for an App to filter crashes before they get added to the DB, such as making sure the crash is from the correct version.
type CrashFilterApp interface {
App
AddCrash(IndividualCrash) bool
}
type ExtendedApp interface { type ExtendedApp interface {
// Extension is called for any calls to /{appID}/ // Extension is called for any calls to /{appID}/
// Alternatively, use Backend.HandleFunc for more customizability // Alternatively, use Backend.HandleFunc for more customizability
+12 -6
View File
@@ -14,10 +14,11 @@ type ArchivedCrash struct {
} }
type IndividualCrash struct { type IndividualCrash struct {
Platform string `json:"platform" bson:"platform"` Platform string `json:"platform" bson:"platform"`
Error string `json:"error" bson:"error"` AppVersion string `json:"appVersion" bson:"appVersion"`
Stack string `json:"stack" bson:"stack"` Error string `json:"error" bson:"error"`
Count int `json:"count" bson:"count"` Stack string `json:"stack" bson:"stack"`
Count int `json:"count" bson:"count"`
} }
type CrashReport struct { type CrashReport struct {
@@ -43,10 +44,15 @@ func (b *Backend) reportCrash(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close() defer r.Body.Close()
var crash IndividualCrash var crash IndividualCrash
err = json.NewDecoder(r.Body).Decode(&crash) err = json.NewDecoder(r.Body).Decode(&crash)
if err != nil || crash.Platform == "" || crash.Error == "" || crash.Stack == "" { if err != nil || crash.Platform == "" || crash.AppVersion == "" || crash.Error == "" || crash.Stack == "" {
ReturnError(w, http.StatusBadRequest, "invalidBody", "Bad request") ReturnError(w, http.StatusBadRequest, "invalidBody", "Bad request")
return return
} }
if filter, ok := ap.(CrashFilterApp); ok {
if !filter.AddCrash(crash) {
return
}
}
tab := ap.CrashTable() tab := ap.CrashTable()
if tab == nil { if tab == nil {
log.Printf("key %v has crash permission, but app does not have a crash table", hdr.Key.AppID) log.Printf("key %v has crash permission, but app does not have a crash table", hdr.Key.AppID)
@@ -60,8 +66,8 @@ func (b *Backend) reportCrash(w http.ResponseWriter, r *http.Request) {
ReturnError(w, http.StatusInternalServerError, "internal", "Server error") ReturnError(w, http.StatusInternalServerError, "internal", "Server error")
return return
} }
w.WriteHeader(http.StatusCreated)
} }
w.WriteHeader(http.StatusCreated)
} }
func (b *Backend) deleteCrash(w http.ResponseWriter, r *http.Request) { func (b *Backend) deleteCrash(w http.ResponseWriter, r *http.Request) {
+1 -1
View File
@@ -2,7 +2,7 @@ package db
/* /*
TODO TODO
Currently there isn't a clean way to implement this (as far as I can tell). Currently there isn't a easy and clean way to implement this (as far as I can tell).
valkey-go relies on an internal library for it's command builder, which makes it impossible to valkey-go relies on an internal library for it's command builder, which makes it impossible to
use properly for generics without manually writing out the Index command. I could probably do this, but use properly for generics without manually writing out the Index command. I could probably do this, but
it's a pain. it's a pain.
-1
View File
@@ -33,7 +33,6 @@ func NewBlogApp(b *backend.Backend, db *mongo.Database, mux *http.ServeMux) *Blo
mux.HandleFunc("GET /author/{authorID}", out.reqAuthorInfo) mux.HandleFunc("GET /author/{authorID}", out.reqAuthorInfo)
mux.HandleFunc("POST /author", out.addAuthorInfo) mux.HandleFunc("POST /author", out.addAuthorInfo)
mux.HandleFunc("POST /author/{authorID}", out.updateAuthorInfo) mux.HandleFunc("POST /author/{authorID}", out.updateAuthorInfo)
//TODO
return out return out
} }