diff --git a/CHANGELOG.md b/CHANGELOG.md index 568a486..f428b19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Releases +## Release v0.0.9 + +* Implemented new config parameter --logLevel +* Dependencies updated + ## Release v0.0.8 * Fixed golang version in github actions pipeline diff --git a/README.md b/README.md index 5eb07a3..997982a 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,6 @@ go tool pprof http://127.0.0.1:8080/debug/pprof/goroutine # terminal 2, for mq-to-db-02 inside the docker-compose-file go tool pprof http://127.0.0.1:8081/debug/pprof/goroutine - # once you are into tool pprof, execute the command web (pprof) web ``` diff --git a/cmd/mq-to-db/main.go b/cmd/mq-to-db/main.go index 65243fc..65f5ea9 100644 --- a/cmd/mq-to-db/main.go +++ b/cmd/mq-to-db/main.go @@ -82,9 +82,12 @@ func init() { // package initializer flag.BoolVar(&conf.Server.KeepAlivesEnabled, "server.keepAlivesEnabled", true, "Server KeepAlivesEnabled") flag.BoolVar(&conf.Server.Debug, "debug", false, "debug") flag.BoolVar(&conf.Server.Profile, "profile", false, "Enable program profile") - flag.StringVar(&conf.Server.LogFormat, "logFormat", "text", "Log Format [text|json] ") + flag.StringVar(&conf.Server.LogFormat, "logFormat", "text", "Log Format [text|json]") + flag.StringVar(&conf.Server.LogLevel, "logLevel", "info", "Log Level [debug|info|warning|panic|fatal]") + // Application conf flags flag.StringVar(&conf.Application.ConfigFile, "configFile", "config", "Configuration file") + // Application version flags showVersion := flag.Bool("version", false, "Show application version") showVersionInfo := flag.Bool("versionInfo", false, "Show application version information") @@ -118,12 +121,26 @@ func init() { // package initializer log.SetFormatter(&logrus.TextFormatter{DisableColors: false, DisableTimestamp: false, FullTimestamp: true}) } - if conf.Server.Debug { + switch conf.Server.LogLevel { + case "debug": log.SetLevel(logrus.DebugLevel) - } else { + case "info": + log.SetLevel(logrus.InfoLevel) + case "warning": + log.SetLevel(logrus.WarnLevel) + case "panic": + log.SetLevel(logrus.PanicLevel) + case "fatal": + log.SetLevel(logrus.FatalLevel) + default: log.SetLevel(logrus.InfoLevel) } + // if --debug, force debug log level no matter what value is in logLevel + if conf.Server.Debug { + log.SetLevel(logrus.DebugLevel) + } + log.Info("Application initialized") } @@ -652,7 +669,7 @@ func HomePage(w http.ResponseWriter, r *http.Request) { - +

If you want to know more about Metrics and Exporters go to https://prometheus.io

diff --git a/config-sample.yaml b/config-sample.yaml index 9dea9bc..924e214 100644 --- a/config-sample.yaml +++ b/config-sample.yaml @@ -1,7 +1,7 @@ --- dispatcher: consumerConcurrency: 4 # Number of go routines consuming messages from Queue - storageWorkers: 40 # Number of go routines sending messages to storage + storageWorkers: 40 # Number of go routines sending messages to storage consumer: kind: rabbitmq diff --git a/docker-compose.yaml b/docker-compose.yaml index 86ae5f5..2b9c1bc 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -100,8 +100,10 @@ services: environment: SERVER_ADDRESS: 0.0.0.0 # means all the ips into the container SERVER_PORT: 8080 + #LOGLEVEL: fatal # as a env var command: - --profile + - --logLevel=info # as a container arg #- --debug ports: - 8080:8080 @@ -130,8 +132,10 @@ services: environment: SERVER_ADDRESS: 0.0.0.0 # means all the ips into the container SERVER_PORT: 8081 + #LOGLEVEL: fatal # as a env var command: - --profile + - --logLevel=info # as a container arg #- --debug ports: - 8081:8081 diff --git a/docker-compose/mq-to-db/config.yaml b/docker-compose/mq-to-db/config.yaml index 91356e9..326206f 100644 --- a/docker-compose/mq-to-db/config.yaml +++ b/docker-compose/mq-to-db/config.yaml @@ -19,7 +19,7 @@ consumer: exclusive: false autoACK: false PrefetchCount: 500 - PrefetchSize: 0 + PrefetchSize: 0 args: x-message-ttl: 180000 x-dead-letter-exchange: retry.exchange diff --git a/docs/config.md b/docs/config.md index 7ee05e3..47987c6 100644 --- a/docs/config.md +++ b/docs/config.md @@ -8,7 +8,7 @@ The configuration file could be `named as you want`, by default if you don't spe This could be located in any place, but by default when service start this find the configuration file in the following location: 1. `./config.yaml` Next to the service binary `mq-to-db` -2. `/etc/mq-to-db/config.yaml` Into the standard `Linux` configuration filesystem +2. `/etc/mq-to-db/config.yaml` Into the standard `Linux` configuration File System 3. `$HOME/config.yaml` Into the `user home` which is executing the service binary `mq-to-db` __NOTE:__ Remember that thanks to the parameter `--configFile` you can tell to the service which configuration file you want to use, for example: @@ -44,7 +44,7 @@ consumer: exclusive: false autoACK: false PrefetchCount: 1500 - PrefetchSize: 0 + PrefetchSize: 0 args: # Optional x-message-ttl: 180000 x-dead-letter-exchange: retry.exchange diff --git a/go.mod b/go.mod index 025d65a..fc0e922 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,12 @@ module github.com/christiangda/mq-to-db go 1.16 require ( - github.com/lib/pq v1.10.0 + github.com/lib/pq v1.10.1 github.com/prometheus/client_golang v1.10.0 github.com/sirupsen/logrus v1.8.1 github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.7.1 github.com/streadway/amqp v1.0.0 - golang.org/x/sys v0.0.0-20210415045647-66c3f260301c // indirect + golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744 // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b ) diff --git a/go.sum b/go.sum index dda3898..2013de3 100644 --- a/go.sum +++ b/go.sum @@ -192,6 +192,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/lib/pq v1.10.0 h1:Zx5DJFEYQXio93kgXnQ09fXNiUKsqv4OUEu2UtGcB1E= github.com/lib/pq v1.10.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/lib/pq v1.10.1 h1:6VXZrLU0jHBYyAqrSPa+MgPfnSvTPuMgK+k0o5kVFWo= +github.com/lib/pq v1.10.1/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM= github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4= github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= @@ -439,6 +441,8 @@ golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210415045647-66c3f260301c h1:6L+uOeS3OQt/f4eFHXZcTxeZrGCuz+CLElgEBjbcTA4= golang.org/x/sys v0.0.0-20210415045647-66c3f260301c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744 h1:yhBbb4IRs2HS9PPlAg6DMC6mUOKexJBNsLf4Z+6En1Q= +golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= diff --git a/internal/config/config.go b/internal/config/config.go index 3d67cc8..9fd0af5 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -30,6 +30,7 @@ type Config struct { ShutdownTimeout time.Duration `json:"shutdownTimeout" yaml:"shutdownTimeout"` KeepAlivesEnabled bool `json:"keepAlivesEnabled" yaml:"keepAlivesEnabled"` LogFormat string `json:"logFormat" yaml:"logFormat"` + LogLevel string `json:"logLevel" yaml:"logLevel"` Debug bool `json:"debug" yaml:"debug"` Profile bool `json:"profile" yaml:"profile"` }