From 4daaa4f0eaf050e850589d0dfd00729fcd93b634 Mon Sep 17 00:00:00 2001 From: Dimitris Gkanatsios Date: Mon, 25 Nov 2024 15:59:05 -0800 Subject: [PATCH] adding GSDK metrics --- cmd/nodeagent/main.go | 1 + cmd/nodeagent/nodeagentmanager.go | 23 +++++++++++++++++++++++ cmd/nodeagent/types.go | 8 ++++++++ 3 files changed, 32 insertions(+) diff --git a/cmd/nodeagent/main.go b/cmd/nodeagent/main.go index 7587c396..65812ddc 100644 --- a/cmd/nodeagent/main.go +++ b/cmd/nodeagent/main.go @@ -31,6 +31,7 @@ func main() { n := NewNodeAgentManager(dynamicClient, nodeName, logEveryHeartbeat, ignoreHealthFromHeartbeat, time.Now, true) log.Debug("Starting HTTP server") http.HandleFunc("/v1/sessionHosts/", n.heartbeatHandler) + http.HandleFunc("/v1/metrics/", n.metricsHandler) http.HandleFunc("/healthz", healthzHandler) http.Handle("/metrics", promhttp.Handler()) diff --git a/cmd/nodeagent/nodeagentmanager.go b/cmd/nodeagent/nodeagentmanager.go index d5922566..8ce4eb80 100644 --- a/cmd/nodeagent/nodeagentmanager.go +++ b/cmd/nodeagent/nodeagentmanager.go @@ -315,6 +315,29 @@ func (n *NodeAgentManager) gameServerDeleted(objUnstructured interface{}) { n.gameServerMap.Delete(gameServerName) } +var gsdkMetricsLogged = false + +// v1/metrics/{sessionHostId}/gsdkinfo +func (n *NodeAgentManager) metricsHandler(w http.ResponseWriter, r *http.Request) { + re := regexp.MustCompile(`.*/v1/metrics\/(.*?)(/gsdkinfo|$)`) + match := re.FindStringSubmatch(r.RequestURI) + + gameServerName := match[1] + + var gi GsdkVersionInfo + err := json.NewDecoder(r.Body).Decode(&gi) + if err != nil { + badRequest(w, err, "cannot deserialize json") + return + } + if !gsdkMetricsLogged { + log.Info("GSDK metrics received from gameserver %s, GSDK flavor and version: %s-%s", gameServerName, gi.Flavor, gi.Version) + gsdkMetricsLogged = true + } + + w.WriteHeader(http.StatusOK) +} + // heartbeatHandler is the http handler handling heartbeats from the GameServer Pods running on this Node // it responds by sending instructions/signal for the next operation // on Thundernetes, the only operation that NodeAgent can signal to the GameServer is that the GameServer has been allocated (its state has transitioned to Active) diff --git a/cmd/nodeagent/types.go b/cmd/nodeagent/types.go index d09592c4..aac160bb 100644 --- a/cmd/nodeagent/types.go +++ b/cmd/nodeagent/types.go @@ -78,6 +78,14 @@ var ( ) ) +// GsdkVersionInfo contains details about the GSDK version of the game server +type GsdkVersionInfo struct { + // Flavor is the engine of GSDK (Unreal/Unity/C++ etc.) + Flavor string `json:"Flavor"` + // Version is the version of GSDK + Version string `json:"Version"` +} + // HeartbeatRequest contains data for the heartbeat request coming from the GSDK running alongside GameServer type HeartbeatRequest struct { // CurrentGameState is the current state of the game server