From f4e423f8c3efa9735e9277a95b0f2fbc8d572ebd Mon Sep 17 00:00:00 2001 From: Mumble <171087428+frutescens@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:08:45 -0800 Subject: [PATCH] [Telemetry] Server Side Code for Run Result Logging (#4) * Revert "Remove Daily from starter tracking" This reverts commit ce4aea88de78696c76046c862cdcae2f5d6d871f. * Server-Side Run Result Logging * Removed unnecessary parameters. * Fixed up endpoint to not rely on present-in-session variables * I'm forgetful. * Fixed up logging format. * Changed somethign. * Updated endpoint variable --------- Co-authored-by: frutescens --- api/endpoints.go | 3 ++- api/savedata/newclear.go | 19 ++++++++++++++----- api/savedata/prometheus.go | 8 ++++++++ api/savedata/update.go | 2 +- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/api/endpoints.go b/api/endpoints.go index 57263ca..bae3195 100644 --- a/api/endpoints.go +++ b/api/endpoints.go @@ -269,7 +269,8 @@ func handleSession(w http.ResponseWriter, r *http.Request) { writeJSON(w, r, resp) case "newclear": - resp, err := savedata.NewClear(uuid, slot) + result, err := strconv.ParseBool(r.URL.Query().Get("isVictory")) + resp, err := savedata.NewClear(uuid, slot, result) if err != nil { httpError(w, r, fmt.Errorf("failed to read new clear: %s", err), http.StatusInternalServerError) return diff --git a/api/savedata/newclear.go b/api/savedata/newclear.go index 0c221c2..af3af4f 100644 --- a/api/savedata/newclear.go +++ b/api/savedata/newclear.go @@ -25,19 +25,28 @@ import ( ) // /savedata/newclear - return whether a session is a new clear for its seed -func NewClear(uuid []byte, slot int) (bool, error) { +func NewClear(uuid []byte, slot int, result bool) (bool, error) { if slot < 0 || slot >= defs.SessionSlotCount { return false, fmt.Errorf("slot id %d out of range", slot) } session, err := db.ReadSessionSaveData(uuid, slot) + if err != nil { return false, err } - - completed, err := db.ReadSeedCompleted(uuid, session.Seed) - if err != nil { - return false, fmt.Errorf("failed to read seed completed: %s", err) + gameMode := getGameModeKey(session.GameMode) + waveIndex := fmt.Sprintf("%d", session.WaveIndex) + completed := true + if result { + runResultCounter.WithLabelValues("victory", waveIndex, gameMode).Inc() + completed, err := db.ReadSeedCompleted(uuid, session.Seed) + if err != nil { + return false, fmt.Errorf("failed to read seed completed: %s", err) + } + return !completed, err + } else { + runResultCounter.WithLabelValues("loss", waveIndex, gameMode).Inc() } return !completed, nil diff --git a/api/savedata/prometheus.go b/api/savedata/prometheus.go index 06ee199..eaae15d 100644 --- a/api/savedata/prometheus.go +++ b/api/savedata/prometheus.go @@ -21,4 +21,12 @@ var ( }, []string{"starterKey", "gameMode"}, ) + + runResultCounter = promauto.NewCounterVec( + prometheus.CounterOpts{ + Name: "rogueserver_run_result_count", + Help: "The total number of victories and losses logged", + }, + []string{"result", "waveIndex", "gameMode"}, + ) ) diff --git a/api/savedata/update.go b/api/savedata/update.go index f14b813..b989318 100644 --- a/api/savedata/update.go +++ b/api/savedata/update.go @@ -74,7 +74,7 @@ func ProcessSessionMetrics(save defs.SessionSaveData, username string) { gameModeCounter.WithLabelValues(getGameModeKey(save.GameMode)).Inc() } - if save.WaveIndex == 1 && save.GameMode != 3 { + if save.WaveIndex == 1 { party := "" for i := 0; i < len(save.Party); i++ { partyMember, ok := save.Party[i].(map[string]interface{})