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
platform: "android",
appVersion: "v1.0.0", // Application version
error: "error",
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.
platform: "android",
appVersion: "v1.0.0",
error: "error",
stack: "stacktrace"
}
+6
View File
@@ -9,6 +9,12 @@ type App interface {
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 {
// Extension is called for any calls to /{appID}/
// Alternatively, use Backend.HandleFunc for more customizability
+8 -2
View File
@@ -15,6 +15,7 @@ type ArchivedCrash struct {
type IndividualCrash struct {
Platform string `json:"platform" bson:"platform"`
AppVersion string `json:"appVersion" bson:"appVersion"`
Error string `json:"error" bson:"error"`
Stack string `json:"stack" bson:"stack"`
Count int `json:"count" bson:"count"`
@@ -43,10 +44,15 @@ func (b *Backend) reportCrash(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
var crash IndividualCrash
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")
return
}
if filter, ok := ap.(CrashFilterApp); ok {
if !filter.AddCrash(crash) {
return
}
}
tab := ap.CrashTable()
if tab == nil {
log.Printf("key %v has crash permission, but app does not have a crash table", hdr.Key.AppID)
@@ -60,9 +66,9 @@ func (b *Backend) reportCrash(w http.ResponseWriter, r *http.Request) {
ReturnError(w, http.StatusInternalServerError, "internal", "Server error")
return
}
}
w.WriteHeader(http.StatusCreated)
}
}
func (b *Backend) deleteCrash(w http.ResponseWriter, r *http.Request) {
hdr, err := b.VerifyHeader(w, r, "management", false)
+1 -1
View File
@@ -2,7 +2,7 @@ package db
/*
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
use properly for generics without manually writing out the Index command. I could probably do this, but
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("POST /author", out.addAuthorInfo)
mux.HandleFunc("POST /author/{authorID}", out.updateAuthorInfo)
//TODO
return out
}