[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 <info@laptop>
pull/60/head
Mumble 2 weeks ago committed by GitHub
parent 0da0283fb9
commit f4e423f8c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -269,7 +269,8 @@ func handleSession(w http.ResponseWriter, r *http.Request) {
writeJSON(w, r, resp) writeJSON(w, r, resp)
case "newclear": 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 { if err != nil {
httpError(w, r, fmt.Errorf("failed to read new clear: %s", err), http.StatusInternalServerError) httpError(w, r, fmt.Errorf("failed to read new clear: %s", err), http.StatusInternalServerError)
return return

@ -25,20 +25,29 @@ import (
) )
// /savedata/newclear - return whether a session is a new clear for its seed // /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 { if slot < 0 || slot >= defs.SessionSlotCount {
return false, fmt.Errorf("slot id %d out of range", slot) return false, fmt.Errorf("slot id %d out of range", slot)
} }
session, err := db.ReadSessionSaveData(uuid, slot) session, err := db.ReadSessionSaveData(uuid, slot)
if err != nil { if err != nil {
return false, err return false, 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) completed, err := db.ReadSeedCompleted(uuid, session.Seed)
if err != nil { if err != nil {
return false, fmt.Errorf("failed to read seed completed: %s", err) return false, fmt.Errorf("failed to read seed completed: %s", err)
} }
return !completed, err
} else {
runResultCounter.WithLabelValues("loss", waveIndex, gameMode).Inc()
}
return !completed, nil return !completed, nil
} }

@ -21,4 +21,12 @@ var (
}, },
[]string{"starterKey", "gameMode"}, []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"},
)
) )

@ -74,7 +74,7 @@ func ProcessSessionMetrics(save defs.SessionSaveData, username string) {
gameModeCounter.WithLabelValues(getGameModeKey(save.GameMode)).Inc() gameModeCounter.WithLabelValues(getGameModeKey(save.GameMode)).Inc()
} }
if save.WaveIndex == 1 && save.GameMode != 3 { if save.WaveIndex == 1 {
party := "" party := ""
for i := 0; i < len(save.Party); i++ { for i := 0; i < len(save.Party); i++ {
partyMember, ok := save.Party[i].(map[string]interface{}) partyMember, ok := save.Party[i].(map[string]interface{})

Loading…
Cancel
Save