Skip to content

Commit

Permalink
better naming, thanks Javier
Browse files Browse the repository at this point in the history
  • Loading branch information
dgkanatsios committed Jul 8, 2022
1 parent dbb745c commit bafbef2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions cmd/nodeagent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func main() {
port := getNumericEnv("AGENT_PORT", 56001)
nodeName := getEnv("NODE_NAME", true)
logEveryHeartbeat := getBooleanEnv("LOG_EVERY_HEARTBEAT", false)
ignoreGameServerHealth := getBooleanEnv("IGNORE_GAME_SERVER_HEALTH", false)
ignoreHealthFromHeartbeat := getBooleanEnv("IGNORE_HEALTH_FROM_HEARTBEAT", false)

setLogLevel()

Expand All @@ -28,7 +28,7 @@ func main() {
log.Fatal(err)
}

n := NewNodeAgentManager(dynamicClient, nodeName, logEveryHeartbeat, ignoreGameServerHealth, time.Now)
n := NewNodeAgentManager(dynamicClient, nodeName, logEveryHeartbeat, ignoreHealthFromHeartbeat, time.Now)
log.Debug("Starting HTTP server")
http.HandleFunc("/v1/sessionHosts/", n.heartbeatHandler)
http.HandleFunc("/healthz", healthzHandler)
Expand Down
36 changes: 18 additions & 18 deletions cmd/nodeagent/nodeagentmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,26 @@ const (
// The game server process tells the NodeAgent about its state (if it's Initializing or StandingBy)
// and NodeAgent tells the game server if it has been allocated (its state having been converted to Active)
type NodeAgentManager struct {
gameServerMap *sync.Map // we use a sync map instead of a regular map since this will be updated by multiple goroutines
dynamicClient dynamic.Interface
watchStopper chan struct{}
nodeName string
logEveryHeartbeat bool
ignoreGameServerHealth bool // health state in heartbeat always comes Healthy
nowFunc func() time.Time
heartbeatTimeout int64 // timeouts for not receiving a heartbeat in milliseconds
firstHeartbeatTimeout int64 // the first heartbeat gets a longer window considering initialization time
gameServerMap *sync.Map // we use a sync map instead of a regular map since this will be updated by multiple goroutines
dynamicClient dynamic.Interface
watchStopper chan struct{}
nodeName string
logEveryHeartbeat bool
ignoreHealthFromHeartbeat bool // health state in heartbeat always comes Healthy. This is to handle GSDK clients that may send invalid heartbeat
nowFunc func() time.Time
heartbeatTimeout int64 // timeouts for not receiving a heartbeat in milliseconds
firstHeartbeatTimeout int64 // the first heartbeat gets a longer window considering initialization time
}

func NewNodeAgentManager(dynamicClient dynamic.Interface, nodeName string, logEveryHeartbeat bool, ignoreGameServerHealth bool, now func() time.Time) *NodeAgentManager {
func NewNodeAgentManager(dynamicClient dynamic.Interface, nodeName string, logEveryHeartbeat bool, ignoreHealthFromHeartbeat bool, now func() time.Time) *NodeAgentManager {
n := &NodeAgentManager{
dynamicClient: dynamicClient,
watchStopper: make(chan struct{}),
gameServerMap: &sync.Map{},
nodeName: nodeName,
logEveryHeartbeat: logEveryHeartbeat,
ignoreGameServerHealth: ignoreGameServerHealth,
nowFunc: now,
dynamicClient: dynamicClient,
watchStopper: make(chan struct{}),
gameServerMap: &sync.Map{},
nodeName: nodeName,
logEveryHeartbeat: logEveryHeartbeat,
ignoreHealthFromHeartbeat: ignoreHealthFromHeartbeat,
nowFunc: now,
}
n.runWatch()
n.runHeartbeatTimeCheckerLoop()
Expand Down Expand Up @@ -337,7 +337,7 @@ func (n *NodeAgentManager) heartbeatHandler(w http.ResponseWriter, r *http.Reque
logger.Infof("heartbeat received from sessionHostId %s, data %s", gameServerName, heartbeatString)
}

if n.ignoreGameServerHealth {
if n.ignoreHealthFromHeartbeat {
hb.CurrentGameHealth = string(mpsv1alpha1.GameServerHealthy)
}

Expand Down

0 comments on commit bafbef2

Please sign in to comment.