Skip to content

Commit

Permalink
Add Sidecar log level through GS specification
Browse files Browse the repository at this point in the history
Add ability to specify logrus log level in yaml configuration and
apply this log level on creating the GameServer.
  • Loading branch information
aLekSer committed Aug 21, 2019
1 parent 7ef4ef6 commit 0402062
Show file tree
Hide file tree
Showing 5 changed files with 872 additions and 972 deletions.
11 changes: 11 additions & 0 deletions install/helm/agones/templates/crds/_gameserverspecvalidation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ properties:
type: integer
minimum: 1
maximum: 65535
loglevel:
type: string
enum:
- panic
- fatal
- error
- warn
- warning
- info
- debug
- trace
scheduling:
type: string
enum:
Expand Down
33 changes: 33 additions & 0 deletions install/yaml/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,17 @@ spec:
type: integer
minimum: 1
maximum: 65535
loglevel:
type: string
enum:
- panic
- fatal
- error
- warn
- warning
- info
- debug
- trace
scheduling:
type: string
enum:
Expand Down Expand Up @@ -594,6 +605,17 @@ spec:
type: integer
minimum: 1
maximum: 65535
loglevel:
type: string
enum:
- panic
- fatal
- error
- warn
- warning
- info
- debug
- trace
scheduling:
type: string
enum:
Expand Down Expand Up @@ -860,6 +882,17 @@ spec:
type: integer
minimum: 1
maximum: 65535
loglevel:
type: string
enum:
- panic
- fatal
- error
- warn
- warning
- info
- debug
- trace
scheduling:
type: string
enum:
Expand Down
12 changes: 11 additions & 1 deletion pkg/apis/agones/v1/gameserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ type GameServerSpec struct {
Health Health `json:"health,omitempty"`
// Scheduling strategy. Defaults to "Packed".
Scheduling apis.SchedulingStrategy `json:"scheduling,omitempty"`
// LogLevel specifies the log level for gameserver sidecar.
LogLevel string `json:"loglevel,omitempty"`
// Template describes the Pod that will be created for the GameServer
Template corev1.PodTemplateSpec `json:"template"`
}
Expand Down Expand Up @@ -213,9 +215,17 @@ func (gss *GameServerSpec) ApplyDefaults() {
gss.applyPortDefaults()
gss.applyHealthDefaults()
gss.applySchedulingDefaults()
gss.applyLogLevelDefaults()
}

// applyContainerDefaults applues the container defaults
// applyLogLevelDefaults applies the log level default - "info"
func (gss *GameServerSpec) applyLogLevelDefaults() {
if gss.LogLevel == "" {
gss.LogLevel = "info"
}
}

// applyContainerDefaults applies the container defaults
func (gss *GameServerSpec) applyContainerDefaults() {
if len(gss.Template.Spec.Containers) == 1 {
gss.Container = gss.Template.Spec.Containers[0].Name
Expand Down
24 changes: 19 additions & 5 deletions pkg/sdkserver/sdkserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ var _ sdk.SDKServer = &SDKServer{}
// nolint: maligned
type SDKServer struct {
logger *logrus.Entry
logLevel string
gameServerName string
namespace string
informerFactory externalversions.SharedInformerFactory
Expand Down Expand Up @@ -165,7 +166,7 @@ func NewSDKServer(gameServerName, namespace string, kubeClient kubernetes.Interf
logfields.GameServerKey,
strings.Join([]string{agones.GroupName, s.namespace, s.gameServerName}, "."))

s.logger.Info("created GameServer sidecar")
s.logger.Info("Created GameServer sidecar")

return s, nil
}
Expand All @@ -192,8 +193,21 @@ func (s *SDKServer) Run(stop <-chan struct{}) error {
}

// grab configuration details
if gs.Spec.LogLevel == "" {
s.logLevel = "info"
} else {
s.logLevel = gs.Spec.LogLevel
}
s.logger.WithField("logLevel", s.logLevel).Info("Setting LogLevel configuration")
level, err := logrus.ParseLevel(s.logLevel)
if err == nil {
s.logger.Logger.SetLevel(level)
} else {
s.logger.WithError(err)
}

s.health = gs.Spec.Health
s.logger.WithField("health", s.health).Info("setting health configuration")
s.logger.WithField("health", s.health).Info("Setting health configuration")
s.healthTimeout = time.Duration(gs.Spec.Health.PeriodSeconds) * time.Second
s.initHealthLastUpdated(time.Duration(gs.Spec.Health.InitialDelaySeconds) * time.Second)

Expand All @@ -214,7 +228,7 @@ func (s *SDKServer) Run(stop <-chan struct{}) error {
go func() {
if err := s.server.ListenAndServe(); err != nil {
if err == http.ErrServerClosed {
s.logger.WithError(err).Info("health check: http server closed")
s.logger.WithError(err).Info("Health check: http server closed")
} else {
err = errors.Wrap(err, "Could not listen on :8080")
runtime.HandleError(s.logger.WithError(err), err)
Expand Down Expand Up @@ -319,7 +333,7 @@ func (s *SDKServer) gameServer() (*agonesv1.GameServer, error) {
// updateLabels updates the labels on this GameServer to the ones persisted in SDKServer,
// i.e. SDKServer.gsLabels, with the prefix of "agones.dev/sdk-"
func (s *SDKServer) updateLabels() error {
s.logger.WithField("labels", s.gsLabels).Info("updating label")
s.logger.WithField("labels", s.gsLabels).Info("Updating label")
gs, err := s.gameServer()
if err != nil {
return err
Expand Down Expand Up @@ -534,7 +548,7 @@ func (s *SDKServer) sendGameServerUpdate(gs *agonesv1.GameServer) {
func (s *SDKServer) runHealth() {
s.checkHealth()
if !s.healthy() {
s.logger.WithField("gameServerName", s.gameServerName).Info("has failed health check")
s.logger.WithField("gameServerName", s.gameServerName).Info("GameServer has failed health check")
s.enqueueState(agonesv1.GameServerStateUnhealthy)
}
}
Expand Down
Loading

0 comments on commit 0402062

Please sign in to comment.