From f51630d01c60a15753a7f8940792ed198bf9802f Mon Sep 17 00:00:00 2001 From: 839 <8398a7@gmail.com> Date: Sat, 31 Oct 2020 00:14:33 +0900 Subject: [PATCH] Add log level setting in allocator --- cmd/allocator/main.go | 12 +++++++++++- cmd/allocator/metrics.go | 6 ++++++ .../helm/agones/templates/service/allocation.yaml | 2 ++ install/helm/agones/values.yaml | 1 + .../en/docs/Installation/Install Agones/helm.md | 1 + 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/cmd/allocator/main.go b/cmd/allocator/main.go index 31ea24d80f..fb15b88a62 100644 --- a/cmd/allocator/main.go +++ b/cmd/allocator/main.go @@ -39,6 +39,7 @@ import ( "agones.dev/agones/pkg/util/signals" "github.com/heptiolabs/healthcheck" "github.com/pkg/errors" + "github.com/sirupsen/logrus" "go.opencensus.io/plugin/ocgrpc" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -66,10 +67,19 @@ const ( func main() { conf := parseEnvFlags() - logger.WithField("version", pkg.Version).WithField("ctlConf", conf). + logger.WithField("version", pkg.Version).WithField("conf", conf). WithField("featureGates", runtime.EncodeFeatures()).WithField("sslPort", sslPort). Info("Starting agones-allocator") + logger.WithField("logLevel", conf.LogLevel).Info("Setting LogLevel configuration") + level, err := logrus.ParseLevel(strings.ToLower(conf.LogLevel)) + if err == nil { + runtime.SetLevel(level) + } else { + logger.WithError(err).Info("Specified wrong Logging.SdkServer. Setting default loglevel - Info") + runtime.SetLevel(logrus.InfoLevel) + } + health, closer := setupMetricsRecorder(conf) defer closer() diff --git a/cmd/allocator/metrics.go b/cmd/allocator/metrics.go index eeb9dcfdb7..5dccb95d16 100644 --- a/cmd/allocator/metrics.go +++ b/cmd/allocator/metrics.go @@ -39,6 +39,7 @@ const ( totalRemoteAllocationTimeoutFlag = "total-remote-allocation-timeout" apiServerSustainedQPSFlag = "api-server-qps" apiServerBurstQPSFlag = "api-server-qps-burst" + logLevelFlag = "log-level" ) func init() { @@ -54,6 +55,7 @@ type config struct { Stackdriver bool GCPProjectID string StackdriverLabels string + LogLevel string totalRemoteAllocationTimeout time.Duration remoteAllocationTimeout time.Duration } @@ -70,6 +72,7 @@ func parseEnvFlags() config { viper.SetDefault(tlsDisabledFlag, false) viper.SetDefault(remoteAllocationTimeoutFlag, 10*time.Second) viper.SetDefault(totalRemoteAllocationTimeoutFlag, 30*time.Second) + viper.SetDefault(logLevelFlag, "Info") pflag.Int32(apiServerSustainedQPSFlag, viper.GetInt32(apiServerSustainedQPSFlag), "Maximum sustained queries per second to send to the API server") pflag.Int32(apiServerBurstQPSFlag, viper.GetInt32(apiServerBurstQPSFlag), "Maximum burst queries per second to send to the API server") @@ -81,6 +84,7 @@ func parseEnvFlags() config { pflag.Bool(tlsDisabledFlag, viper.GetBool(tlsDisabledFlag), "Flag to enable/disable TLS in the allocator.") pflag.Duration(remoteAllocationTimeoutFlag, viper.GetDuration(remoteAllocationTimeoutFlag), "Flag to set remote allocation call timeout.") pflag.Duration(totalRemoteAllocationTimeoutFlag, viper.GetDuration(totalRemoteAllocationTimeoutFlag), "Flag to set total remote allocation timeout including retries.") + pflag.String(logLevelFlag, viper.GetString(logLevelFlag), "Agones Log level") runtime.FeaturesBindFlags() pflag.Parse() @@ -93,6 +97,7 @@ func parseEnvFlags() config { runtime.Must(viper.BindEnv(stackdriverLabels)) runtime.Must(viper.BindEnv(mTLSDisabledFlag)) runtime.Must(viper.BindEnv(tlsDisabledFlag)) + runtime.Must(viper.BindEnv(logLevelFlag)) runtime.Must(viper.BindPFlags(pflag.CommandLine)) runtime.Must(runtime.FeaturesBindEnv()) @@ -107,6 +112,7 @@ func parseEnvFlags() config { StackdriverLabels: viper.GetString(stackdriverLabels), MTLSDisabled: viper.GetBool(mTLSDisabledFlag), TLSDisabled: viper.GetBool(tlsDisabledFlag), + LogLevel: viper.GetString(logLevelFlag), remoteAllocationTimeout: viper.GetDuration(remoteAllocationTimeoutFlag), totalRemoteAllocationTimeout: viper.GetDuration(totalRemoteAllocationTimeoutFlag), } diff --git a/install/helm/agones/templates/service/allocation.yaml b/install/helm/agones/templates/service/allocation.yaml index 400fe2baf7..8b9e82ffa2 100644 --- a/install/helm/agones/templates/service/allocation.yaml +++ b/install/helm/agones/templates/service/allocation.yaml @@ -153,6 +153,8 @@ spec: fieldPath: metadata.namespace - name: CONTAINER_NAME value: "agones-allocator" + - name: LOG_LEVEL + value: {{ .Values.agones.allocator.logLevel | quote }} - name: FEATURE_GATES value: {{ .Values.agones.featureGates | quote }} ports: diff --git a/install/helm/agones/values.yaml b/install/helm/agones/values.yaml index fa5b93a66f..03556f7a4c 100644 --- a/install/helm/agones/values.yaml +++ b/install/helm/agones/values.yaml @@ -110,6 +110,7 @@ agones: install: true apiServerQPS: 400 apiServerQPSBurst: 500 + logLevel: info annotations: {} healthCheck: initialDelaySeconds: 3 diff --git a/site/content/en/docs/Installation/Install Agones/helm.md b/site/content/en/docs/Installation/Install Agones/helm.md index 3560e581b4..51f276048c 100644 --- a/site/content/en/docs/Installation/Install Agones/helm.md +++ b/site/content/en/docs/Installation/Install Agones/helm.md @@ -252,6 +252,7 @@ The following tables lists the configurable parameters of the Agones chart and t | `agones.allocator.apiServerQPSBurst` | Maximum burst queries per second that an allocator should be making against API Server | `500` | | `agones.allocator.allocationTimeout` | Remote allocation call timeout. | `10s` | | `agones.allocator.remoteAllocationTimeout` | Total remote allocation timeout including retries. | `30s` | +| `agones.allocator.logLevel` | Agones Allocator Log level. Log only entries with that severity and above | `info` | | `agones.controller.annotations` | [Annotations][annotations] added to the Agones controller pods | `{}` | | `agones.allocator.annotations` | [Annotations][annotations] added to the Agones allocator pods | `{}` | | `agones.ping.annotations` | [Annotations][annotations] added to the Agones ping pods | `{}` |