From dd77ac50c40df1a63e3674cd2d33625946f19413 Mon Sep 17 00:00:00 2001 From: Harjot Gill Date: Wed, 7 Sep 2022 21:27:45 -0700 Subject: [PATCH] fix logger (#370) --- Makefile | 3 +- .../config/aperture-agent/config-swagger.yaml | 34 +------------------ docs/gen/config/aperture-agent/swagger.md | 32 +---------------- .../aperture-controller/config-swagger.yaml | 34 +------------------ .../gen/config/aperture-controller/swagger.md | 32 +---------------- .../crd/bases/fluxninja.com_agents.yaml | 25 +++----------- .../crd/bases/fluxninja.com_controllers.yaml | 25 +++----------- pkg/config/log.go | 11 ++---- pkg/config/zz_generated.deepcopy.go | 1 - .../apps/aperture-agent/mixins.libsonnet | 1 - .../apps/aperture-controller/mixins.libsonnet | 1 - 11 files changed, 17 insertions(+), 182 deletions(-) diff --git a/Makefile b/Makefile index 86b6d25866..219212e82f 100644 --- a/Makefile +++ b/Makefile @@ -141,7 +141,8 @@ operator-manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole .PHONY: operator-generate operator-generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. - $(CONTROLLER_GEN) object:headerFile="operator/hack/boilerplate.go.txt" paths="./..." + $(CONTROLLER_GEN) object:headerFile="operator/hack/boilerplate.go.txt" paths="./pkg/..." + $(CONTROLLER_GEN) object:headerFile="operator/hack/boilerplate.go.txt" paths="./operator/..." .PHONY: operator-fmt operator-fmt: ## Run go fmt against code. diff --git a/docs/gen/config/aperture-agent/config-swagger.yaml b/docs/gen/config/aperture-agent/config-swagger.yaml index b121c6fa60..7e41573fba 100644 --- a/docs/gen/config/aperture-agent/config-swagger.yaml +++ b/docs/gen/config/aperture-agent/config-swagger.yaml @@ -570,17 +570,6 @@ definitions: x-go-package: github.com/fluxninja/aperture/pkg/net/listener LogConfig: properties: - compress: - description: Compress - type: boolean - x-go-default: "false" - x-go-name: Compress - file: - description: Output file for logs. Keywords allowed - ["stderr", "default"]. - "default" maps to `/var/log/fluxninja/.log` - type: string - x-go-default: stderr - x-go-name: File level: description: Log level type: string @@ -588,27 +577,6 @@ definitions: x-go-name: LogLevel x-go-validate: oneof=debug DEBUG info INFO warn WARN error ERROR fatal FATAL panic PANIC trace TRACE disabled DISABLED - max_age: - description: Max age in days for log files - format: int64 - type: integer - x-go-default: "7" - x-go-name: MaxAge - x-go-validate: gte=0 - max_backups: - description: Max log file backups - format: int64 - type: integer - x-go-default: "3" - x-go-name: MaxBackups - x-go-validate: gte=0 - max_size: - description: Log file max size in MB - format: int64 - type: integer - x-go-default: "50" - x-go-name: MaxSize - x-go-validate: gte=0 non_blocking: description: Use non-blocking log writer (can lose logs at high throughput) type: boolean @@ -621,7 +589,7 @@ definitions: x-go-default: "false" x-go-name: PrettyConsole writers: - description: Additional log writers + description: Log writers items: $ref: '#/definitions/LogWriterConfig' type: array diff --git a/docs/gen/config/aperture-agent/swagger.md b/docs/gen/config/aperture-agent/swagger.md index cb926eb101..d7a15de013 100644 --- a/docs/gen/config/aperture-agent/swagger.md +++ b/docs/gen/config/aperture-agent/swagger.md @@ -1189,41 +1189,11 @@ LogConfig holds configuration for a logger and log writers. #### Properties
-
compress
-
- -(bool, default: `false`) Compress - -
-
file
-
- -(string, default: `stderr`) Output file for logs. Keywords allowed - ["stderr", "default"]. "default" maps to `/var/log/fluxninja/.log` - -
level
(string, `oneof=debug DEBUG info INFO warn WARN error ERROR fatal FATAL panic PANIC trace TRACE disabled DISABLED`, default: `info`) Log level -
-
max_age
-
- -(int64, `gte=0`, default: `7`) Max age in days for log files - -
-
max_backups
-
- -(int64, `gte=0`, default: `3`) Max log file backups - -
-
max_size
-
- -(int64, `gte=0`, default: `50`) Log file max size in MB -
non_blocking
@@ -1240,7 +1210,7 @@ LogConfig holds configuration for a logger and log writers.
writers
-([[]LogWriterConfig](#log-writer-config), `omitempty,dive,omitempty`) Additional log writers +([[]LogWriterConfig](#log-writer-config), `omitempty,dive,omitempty`) Log writers
diff --git a/docs/gen/config/aperture-controller/config-swagger.yaml b/docs/gen/config/aperture-controller/config-swagger.yaml index 3d860912c2..daa5e730c7 100644 --- a/docs/gen/config/aperture-controller/config-swagger.yaml +++ b/docs/gen/config/aperture-controller/config-swagger.yaml @@ -505,17 +505,6 @@ definitions: x-go-package: github.com/fluxninja/aperture/pkg/net/listener LogConfig: properties: - compress: - description: Compress - type: boolean - x-go-default: "false" - x-go-name: Compress - file: - description: Output file for logs. Keywords allowed - ["stderr", "default"]. - "default" maps to `/var/log/fluxninja/.log` - type: string - x-go-default: stderr - x-go-name: File level: description: Log level type: string @@ -523,27 +512,6 @@ definitions: x-go-name: LogLevel x-go-validate: oneof=debug DEBUG info INFO warn WARN error ERROR fatal FATAL panic PANIC trace TRACE disabled DISABLED - max_age: - description: Max age in days for log files - format: int64 - type: integer - x-go-default: "7" - x-go-name: MaxAge - x-go-validate: gte=0 - max_backups: - description: Max log file backups - format: int64 - type: integer - x-go-default: "3" - x-go-name: MaxBackups - x-go-validate: gte=0 - max_size: - description: Log file max size in MB - format: int64 - type: integer - x-go-default: "50" - x-go-name: MaxSize - x-go-validate: gte=0 non_blocking: description: Use non-blocking log writer (can lose logs at high throughput) type: boolean @@ -556,7 +524,7 @@ definitions: x-go-default: "false" x-go-name: PrettyConsole writers: - description: Additional log writers + description: Log writers items: $ref: '#/definitions/LogWriterConfig' type: array diff --git a/docs/gen/config/aperture-controller/swagger.md b/docs/gen/config/aperture-controller/swagger.md index 863142ea00..3fbd3881ab 100644 --- a/docs/gen/config/aperture-controller/swagger.md +++ b/docs/gen/config/aperture-controller/swagger.md @@ -1034,41 +1034,11 @@ LogConfig holds configuration for a logger and log writers. #### Properties
-
compress
-
- -(bool, default: `false`) Compress - -
-
file
-
- -(string, default: `stderr`) Output file for logs. Keywords allowed - ["stderr", "default"]. "default" maps to `/var/log/fluxninja/.log` - -
level
(string, `oneof=debug DEBUG info INFO warn WARN error ERROR fatal FATAL panic PANIC trace TRACE disabled DISABLED`, default: `info`) Log level -
-
max_age
-
- -(int64, `gte=0`, default: `7`) Max age in days for log files - -
-
max_backups
-
- -(int64, `gte=0`, default: `3`) Max log file backups - -
-
max_size
-
- -(int64, `gte=0`, default: `50`) Log file max size in MB -
non_blocking
@@ -1085,7 +1055,7 @@ LogConfig holds configuration for a logger and log writers.
writers
-([[]LogWriterConfig](#log-writer-config), `omitempty,dive,omitempty`) Additional log writers +([[]LogWriterConfig](#log-writer-config), `omitempty,dive,omitempty`) Log writers
diff --git a/operator/config/crd/bases/fluxninja.com_agents.yaml b/operator/config/crd/bases/fluxninja.com_agents.yaml index 1a7c0d67b9..a572002874 100644 --- a/operator/config/crd/bases/fluxninja.com_agents.yaml +++ b/operator/config/crd/bases/fluxninja.com_agents.yaml @@ -1201,25 +1201,9 @@ spec: log: description: Log configuration. properties: - compress: - description: Compress - type: boolean - file: - description: Output file for logs. Keywords allowed - ["stderr", - "default"]. "default" maps to `/var/log/fluxninja/.log` - type: string level: description: Log level type: string - max_age: - description: Max age in days for log files - type: integer - max_backups: - description: Max log file backups - type: integer - max_size: - description: Log file max size in MB - type: integer non_blocking: description: Use non-blocking log writer (can lose logs at high throughput) @@ -1331,8 +1315,8 @@ spec: type: string type: array plugins_path: - description: Path to plugins directory. This can be set via - command line arguments as well. + description: Path to plugins directory. "default" points to + `/var/lib/aperture//plugins`. type: string type: object profilers: @@ -1344,9 +1328,8 @@ spec: is enabled as CPU profile will always be running. type: boolean profiles_path: - description: Path to save performance profiles. This can be - set via command line arguments as well. E.g. default path - for aperture-agent is /var/log/aperture/aperture-agent/profiles. + description: Path to save performance profiles. "default" + path is `/var/log/aperture//profiles`. type: string register_http_routes: description: Register routes. Profile types profile, symbol diff --git a/operator/config/crd/bases/fluxninja.com_controllers.yaml b/operator/config/crd/bases/fluxninja.com_controllers.yaml index 07ebbe383e..6443ec9350 100644 --- a/operator/config/crd/bases/fluxninja.com_controllers.yaml +++ b/operator/config/crd/bases/fluxninja.com_controllers.yaml @@ -1096,25 +1096,9 @@ spec: log: description: Log configuration. properties: - compress: - description: Compress - type: boolean - file: - description: Output file for logs. Keywords allowed - ["stderr", - "default"]. "default" maps to `/var/log/fluxninja/.log` - type: string level: description: Log level type: string - max_age: - description: Max age in days for log files - type: integer - max_backups: - description: Max log file backups - type: integer - max_size: - description: Log file max size in MB - type: integer non_blocking: description: Use non-blocking log writer (can lose logs at high throughput) @@ -1217,8 +1201,8 @@ spec: type: string type: array plugins_path: - description: Path to plugins directory. This can be set via - command line arguments as well. + description: Path to plugins directory. "default" points to + `/var/lib/aperture//plugins`. type: string type: object policies: @@ -1250,9 +1234,8 @@ spec: is enabled as CPU profile will always be running. type: boolean profiles_path: - description: Path to save performance profiles. This can be - set via command line arguments as well. E.g. default path - for aperture-agent is /var/log/aperture/aperture-agent/profiles. + description: Path to save performance profiles. "default" + path is `/var/log/aperture//profiles`. type: string register_http_routes: description: Register routes. Profile types profile, symbol diff --git a/pkg/config/log.go b/pkg/config/log.go index aa15518668..657ec1e9b6 100644 --- a/pkg/config/log.go +++ b/pkg/config/log.go @@ -53,12 +53,9 @@ type LogConfig struct { // Log level LogLevel string `json:"level" validate:"oneof=debug DEBUG info INFO warn WARN error ERROR fatal FATAL panic PANIC trace TRACE disabled DISABLED" default:"info"` - // Additional log writers + // Log writers Writers []LogWriterConfig `json:"writers" validate:"omitempty,dive,omitempty"` - // Base LogWriterConfig - LogWriterConfig `json:",inline"` - // Use non-blocking log writer (can lose logs at high throughput) NonBlocking bool `json:"non_blocking" default:"true"` @@ -122,7 +119,7 @@ func (constructor LoggerConstructor) provideLogger(w []io.Writer, log.Panic().Err(err).Msg("Unable to deserialize log configuration!") } logger, writers := NewLogger(config) - // append additional writers provided via Fx + // append writers provided via Fx writers = append(writers, w...) lifecycle.Append(fx.Hook{ @@ -152,7 +149,7 @@ func NewLogger(config LogConfig) (log.Logger, []io.Writer) { // append file writers for _, writerConfig := range config.Writers { var writer io.Writer - if config.File != "" { + if writerConfig.File != "" { switch writerConfig.File { case stdErrFile: writer = os.Stderr @@ -188,7 +185,5 @@ func NewLogger(config LogConfig) (log.Logger, []io.Writer) { logger := log.NewLogger(multi, config.NonBlocking, strings.ToLower(config.LogLevel)) - logger.Info().Msg("Configured logger") - return logger, writers } diff --git a/pkg/config/zz_generated.deepcopy.go b/pkg/config/zz_generated.deepcopy.go index eca3105591..6ef1d1bec7 100644 --- a/pkg/config/zz_generated.deepcopy.go +++ b/pkg/config/zz_generated.deepcopy.go @@ -31,7 +31,6 @@ func (in *LogConfig) DeepCopyInto(out *LogConfig) { *out = make([]LogWriterConfig, len(*in)) copy(*out, *in) } - out.LogWriterConfig = in.LogWriterConfig } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LogConfig. diff --git a/playground/tanka/apps/aperture-agent/mixins.libsonnet b/playground/tanka/apps/aperture-agent/mixins.libsonnet index 21b1869cff..6e828bc9c7 100644 --- a/playground/tanka/apps/aperture-agent/mixins.libsonnet +++ b/playground/tanka/apps/aperture-agent/mixins.libsonnet @@ -24,7 +24,6 @@ local apertureAgentMixin = pretty_console: true, non_blocking: true, level: 'debug', - file: 'default', }, etcd+: { endpoints: ['http://controller-etcd.aperture-controller.svc.cluster.local:2379'], diff --git a/playground/tanka/apps/aperture-controller/mixins.libsonnet b/playground/tanka/apps/aperture-controller/mixins.libsonnet index 35a076411f..739a377cda 100644 --- a/playground/tanka/apps/aperture-controller/mixins.libsonnet +++ b/playground/tanka/apps/aperture-controller/mixins.libsonnet @@ -24,7 +24,6 @@ local apertureControllerMixin = pretty_console: true, non_blocking: true, level: 'debug', - file: 'default', }, etcd+: { endpoints: ['http://controller-etcd.aperture-controller.svc.cluster.local:2379'],