Skip to content

Commit

Permalink
adding GSDK metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitris Gkanatsios committed Nov 26, 2024
1 parent 6453367 commit 4daaa4f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/nodeagent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
23 changes: 23 additions & 0 deletions cmd/nodeagent/nodeagentmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions cmd/nodeagent/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4daaa4f

Please sign in to comment.