From 4cc43f84b9e75334c74bbcfb36e687510fd9f2d5 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Thu, 14 Jan 2021 17:08:01 +0300 Subject: 1.9.2 release milestone --- .rr.yaml | 4 +- CHANGELOG.md | 250 ++++++++++++++++++++++++++++++----------------------------- 2 files changed, 129 insertions(+), 125 deletions(-) diff --git a/.rr.yaml b/.rr.yaml index 7fa191a2..ba122089 100644 --- a/.rr.yaml +++ b/.rr.yaml @@ -42,9 +42,9 @@ http: # http host to listen. address: 0.0.0.0:8080 # override http error code for the application errors (default 500) - appErrorCode: 505 + appErrorCode: 500 # override http error code for the internal RR errors (default 500) - internalErrorCode: 505 + internalErrorCode: 500 ssl: # custom https port (default 443) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28063ba5..74833eaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,26 +1,30 @@ -CHANGELOG -========= +# CHANGELOG + +## v1.9.2 (14.01.2021) + +- Distinguish app errors and errors from the RR in the `HTTP` service. [Request](https://github.com/spiral/roadrunner/issues/471), [Doc](https://roadrunner.dev/docs/beep-beep-http-error-codes) +- CI update (golangci to version 1.35) + +## v1.9.1 (21.12.2020) -v1.9.1 (21.12.2020) ----------- - Add `rr --version` flag support (thanks @tarampampam) - Update `reload` plugin, remove unnecessary goroutines and locks. - Add objectives to the metrics summary. - Automated releases build. -v1.9.0 (02.12.2020) -------------------- +## v1.9.0 (02.12.2020) + - Update PHP minimal supported version to 7.3 - Support PHP 8.0 - Update Ubuntu version in GHA to 20.04 - Update Golang version in the RR Dockerfile to 1.15.5 -v1.8.4 (21.10.2020) -------------------- +## v1.8.4 (21.10.2020) + - Update Goridge go dep to 2.4.6 -v1.8.3 (02.09.2020) -------------------- +## v1.8.3 (02.09.2020) + - Fix superfluous response.WriteHeader issue. - Proper handle of `broken pipe` error on Linux and Windows. - PCI DSS compliant upgrade (thanks @antonydevanchi). @@ -28,12 +32,12 @@ v1.8.3 (02.09.2020) - Add Request and Response headers to static files (thanks @siad007). - Add user_namespaces check when running RR worker from a particular user. -v1.8.2 (06.06.2020) -------------------- +## v1.8.2 (06.06.2020) + - Bugfix release -v1.8.1 (23.05.2020) -------------------- +## v1.8.1 (23.05.2020) + - Update goridge version to 2.4.4 - Fix code warnings from phpstan - Improve RPC @@ -43,14 +47,14 @@ v1.8.1 (23.05.2020) - Add support for the Root CA via the `rootCa` .rr.yaml option - See the full milestone here: [link](https://github.com/spiral/roadrunner/milestone/11?closed=1) -v1.8.0 (05.05.2020) -------------------- +## v1.8.0 (05.05.2020) + - Update goridge version to 2.4.0 - Update PHP version to the 7.2 (currently minimum supported) - See the full milestone here: [link](https://github.com/spiral/roadrunner/milestone/10?closed=1) -v1.7.1 (22.04.2020) -------------------- +## v1.7.1 (22.04.2020) + - Syscall usage optimized. Now the data is packing and sending via 1 (or 2 in some cases) send_socket calls, instead of 2-3 (by @vvval) - Unix sockets in Windows (AF_UNIX) now supported. - Systemd unit file now in the root of the repository. Feel free to read the [docs](https://roadrunner.dev/docs/beep-beep-systemd) about running RR as daemon on Linux based systems. @@ -60,18 +64,18 @@ v1.7.1 (22.04.2020) - Deprecated Zend dependency replaced with Laminas-diactoros. - See the full log: [Milestone](https://github.com/spiral/roadrunner/milestone/9?closed=1) -v1.7.0 (23.03.2020) -------------------- +## v1.7.0 (23.03.2020) + - Replaced std encoding/json package with the https://github.com/json-iterator/go -v1.6.4 (14.03.2020) -------------------- +## v1.6.4 (14.03.2020) + - Fixed bug with RR getting unreasonable without config - Fixed bug with local paths in panic messages - Fixed NPE bug with empty `http` config and enabled `gzip` plugin -v1.6.3 (10.03.2020) -------------------- +## v1.6.3 (10.03.2020) + - Fixed bug with UB when the plugin is failing during start - Better signals handling - Rotate ports in tests @@ -80,25 +84,25 @@ v1.6.3 (10.03.2020) - macOS temporarily removed from CI - Added curl dependency to download rr (@dkarlovi) -v1.6.2 (23.02.2020) -------------------- +## v1.6.2 (23.02.2020) + - added reload module to handle file changes -v1.6.1 (17.02.2020) -------------------- +## v1.6.1 (17.02.2020) + - When you run ./rr server -d (debug mode), also pprof server will be launched on :6061 port (this is default golang port for pprof) with the default endpoints (see: https://golang.org/pkg/net/http/pprof/) - Added LDFLAGS "-s" to build.sh --> https://spiralscout.com/blog/golang-software-testing-tips -v1.6.0 (11.02.2020) -------------------- +## v1.6.0 (11.02.2020) + - Moved to GitHub Actions, thanks to @tarampampam - New GZIP handler, thanks to @wppd - Tests stabilization and fix REQUEST_URI for requests through FastCGI, thanks to @marliotto - Golang modules update and new RPC method to register metrics from the application, thanks to @48d90782 - Deadlock on timer update in error buffer [bugfix], thanks to @camohob -v1.5.3 (23.12.2019) -------------------- +## v1.5.3 (23.12.2019) + - metric and RPC ports are rotated in tests to avoid false positive - massive test and source cleanup (more error handlers) by @ValeryPiashchynski - "Server closed" error has been suppressed @@ -107,42 +111,42 @@ v1.5.3 (23.12.2019) - bump the minimum TLS version to TLS 1.2 - added `Strict-Transport-Security` header for TLS requests -v1.5.2 (05.12.2019) -------------------- +## v1.5.2 (05.12.2019) + - added support for symfony/console 5.0 by @coxa - added support for HTTP2 trailers by @filakhtov -v1.5.1 (22.10.2019) -------------------- +## v1.5.1 (22.10.2019) + - bugfix: do not halt stop sequence in case of service error -v1.5.0 (12.10.2019) -------------------- +## v1.5.0 (12.10.2019) + - initial code style fixes by @ScullWM - added health service for better integration with Kubernetes by @awprice - added support for payloads in GET methods by @moeinpaki - dropped support of PHP 7.0 version (you can still use new server binary) -v1.4.8 (06.09.2019) -------------------- -- bugfix in proxy IP resolution by @spudro228 +## v1.4.8 (06.09.2019) + +- bugfix in proxy IP resolution by @spudro228 - `rr get` can now skip binary download if version did not change by @drefixs - bugfix in `rr init-config` and with linux binary download by @Hunternnm - `$_SERVER['REQUEST_URI']` is now being set -v1.4.7 (29.07.2019) -------------------- +## v1.4.7 (29.07.2019) + - added support for H2C over TCP by @Alex-Bond -v1.4.6 (01.07.2019) -------------------- +## v1.4.6 (01.07.2019) + - Worker is not final (to allow mocking) - MatricsInterface added -v1.4.5 (27.06.2019) -------------------- +## v1.4.5 (27.06.2019) + - added metrics server with Prometheus backend - ability to push metrics from the application - expose http service metrics @@ -150,38 +154,38 @@ v1.4.5 (27.06.2019) - expose generic golang metrics - HttpClient and Worker marked final -v1.4.4 (25.06.2019) -------------------- +## v1.4.4 (25.06.2019) + - added "headers" service with the ability to specify request, response and CORS headers by @ovr - added FastCGI support for HTTP service by @ovr - added ability to include multiple config files using `include` directive in the configuration -v1.4.3 (03.06.2019) -------------------- -- fixed dependency with Zend Diactoros by @dkuhnert +## v1.4.3 (03.06.2019) + +- fixed dependency with Zend Diactoros by @dkuhnert - minor refactoring of error reporting by @lda -v1.4.2 (22.05.2019) -------------------- +## v1.4.2 (22.05.2019) + - bugfix: incorrect RPC method for stop command - bugfix: incorrect archive extension in /vendor/bin/rr get on linux machines -v1.4.1 (15.05.2019) -------------------- +## v1.4.1 (15.05.2019) + - constrain service renamed to "limit" to equalize the definition with sample config -v1.4.0 (05.05.2019) -------------------- +## v1.4.0 (05.05.2019) + - launch of official website https://roadrunner.dev/ -- ENV variables in configs (automatic RR_ mapping and manual definition using "${ENV_NAME}" value) +- ENV variables in configs (automatic RR\_ mapping and manual definition using "${ENV_NAME}" value) - the ability to safely remove the worker from the pool in runtime - minor performance improvements -- `real ip` resolution using X-Real-Ip and X-Forwarded-For (+cidr verification) +- `real ip` resolution using X-Real-Ip and X-Forwarded-For (+cidr verification) - automatic worker lifecycle manager (controller, see [sample config](https://github.com/spiral/roadrunner/blob/master/.rr.yaml)) - - maxMemory (graceful stop) - - ttl (graceful stop) - - idleTTL (graceful stop) - - execTTL (brute, max_execution_time) + - maxMemory (graceful stop) + - ttl (graceful stop) + - idleTTL (graceful stop) + - execTTL (brute, max_execution_time) - the ability to stop rr using `rr stop` - `maxRequest` option has been deprecated in favor of `maxRequestSize` - `/vendor/bin/rr get` to download rr server binary (symfony/console) by @Alex-Bond @@ -190,45 +194,45 @@ v1.4.0 (05.05.2019) - PSR-12 - strict_types=1 added to all php files -v1.3.7 (21.03.2019) -------------------- -- bugfix: Request field ordering with same names #136 +## v1.3.7 (21.03.2019) + +- bugfix: Request field ordering with same names #136 + +## v1.3.6 (21.03.2019) -v1.3.6 (21.03.2019) -------------------- - bugfix: pool did not wait for slow workers to complete while running concurrent load with http:reset command being invoked -v1.3.5 (14.02.2019) -------------------- +## v1.3.5 (14.02.2019) + - new console flag `l` to define log formatting - * **color|default** - colorized output - * **plain** - disable all colorization - * **json** - output as json + - **color|default** - colorized output + - **plain** - disable all colorization + - **json** - output as json - new console flag `w` to specify work dir - added ability to work without config file when at least one `overwrite` option has been specified - pool config now sets `numWorkers` equal to number of cores by default (this section can be omitted now) -v1.3.4 (02.02.2019) -------------------- +## v1.3.4 (02.02.2019) + - bugfix: invalid content type detection for urlencoded form requests with custom encoding by @Alex-Bond -v1.3.3 (31.01.2019) -------------------- +## v1.3.3 (31.01.2019) + - added HttpClient for faster integrations with non PSR-7 frameworks by @Alex-Bond -v1.3.2 (11.01.2019) -------------------- -- `_SERVER` now exposes headers with HTTP_ prefix (fixing Lravel integration) by @Alex-Bond -- fixed bug causing body payload not being received for custom HTTP methods by @Alex-Bond +## v1.3.2 (11.01.2019) + +- `_SERVER` now exposes headers with HTTP\_ prefix (fixing Lravel integration) by @Alex-Bond +- fixed bug causing body payload not being received for custom HTTP methods by @Alex-Bond + +## v1.3.1 (11.01.2019) -v1.3.1 (11.01.2019) -------------------- - fixed bug causing static_pool crash when multiple reset requests received at the same time - added `always` directive to static service config to always service files of specific extension -- added `vendor/bin/rr-build` command to easier compile custom RoadRunner builds +- added `vendor/bin/rr-build` command to easier compile custom RoadRunner builds + +## v1.3.0 (05.01.2019) -v1.3.0 (05.01.2019) -------------------- - added support for zend/diactros 1.0 and 2.0 - removed `http-interop/http-factory-diactoros` - added `strict_types=1` @@ -243,45 +247,45 @@ v1.3.0 (05.01.2019) - more tests - new travis configuration -v1.2.8 (26.12.2018) -------------------- +## v1.2.8 (26.12.2018) + - bugfix #76 error_log redirect has been disabled after `http:reset` command -v1.2.7 (20.12.2018) -------------------- +## v1.2.7 (20.12.2018) + - #67 bugfix, invalid protocol version while using HTTP/2 with new http-interop by @bognerf - #66 added HTTP_USER_AGENT value and tests for it - typo fix in static service by @Alex-Bond - added PHP 7.3 to travis - less ambiguous error when invalid data found in a pipe(`invalid prefix (checksum)` => `invalid data found in the buffer (possible echo)`) -v1.2.6 (18.10.2018) -------------------- +## v1.2.6 (18.10.2018) + - bugfix: ignored `stopping` value during http server shutdown - debug log now split message into individual lines -v1.2.5 (13.10.2018) ------- +## v1.2.5 (13.10.2018) + - decoupled from Zend Diactoros via PSR-17 factory (by @1ma) - `Verbose` flag for cli renamed to `verbose` (by @ruudk) - bugfix: HTTP protocol version mismatch on PHP end -v1.2.4 (30.09.2018) ------- +## v1.2.4 (30.09.2018) + - minor performance improvements (reduced number of syscalls) - worker factory connection is now exposed to PHP using RR_RELAY env - HTTPS support - HTTP/2 and HTTP/2 Support - Removed `disable` flag of static service -v1.2.3 (29.09.2018) ------- +## v1.2.3 (29.09.2018) + - reduced verbosity - worker list has been extracted from http service and now available for other rr based services - built using Go 1.11 -v1.2.2 (23.09.2018) ------- +## v1.2.2 (23.09.2018) + - new project directory structure - introduces DefaultsConfig, allows to keep config files smaller - better worker pool destruction while working with long running processes @@ -289,17 +293,17 @@ v1.2.2 (23.09.2018) - `Spiral\RoadRunner\Exceptions\RoadRunnerException` is marked as deprecated in favor of `Spiral\RoadRunner\Exception\RoadRunnerException` - improved test coverage -v1.2.1 (21.09.2018) ------- +## v1.2.1 (21.09.2018) + - added RR_HTTP env variable to php processes run under http service - bugfix: ignored `--config` option - added shorthand for config `-c` - rr now changes working dir to the config location (allows relating paths for php scripts) -v1.2.0 (10.09.2018) -------- +## v1.2.0 (10.09.2018) + - added an ability to request `*logrus.Logger`, `logrus.StdLogger`, `logrus.FieldLogger` dependency -in container + in container - added ability to set env values using `env.Environment` - `env.Provider` renamed to `env.Environment` - rr does not throw a warning when service config is missing, instead debug level is used @@ -311,16 +315,16 @@ in container - env service construction has been simplified in order to unify it with other services - more tests -v1.1.1 (26.07.2018) -------- +## v1.1.1 (26.07.2018) + - added support for custom env variables - added env service - added env provider to provide ability to define env variables from any source - container can resolve values by interface now -v1.1.0 (08.07.2018) -------- -- bugfix: Wrong values for $_SERVER['REQUEST_TIME'] and $_SERVER['REQUEST_TIME_FLOAT'] +## v1.1.0 (08.07.2018) + +- bugfix: Wrong values for $\_SERVER['REQUEST_TIME'] and $\_SERVER['REQUEST_TIME_FLOAT'] - rr now resolves remoteAddr (IP-address) - improvements in the error buffer - support for custom configs and dependency injection for services @@ -329,31 +333,31 @@ v1.1.0 (08.07.2018) - config pre-processing now allows seconds for http service timeouts - support for non-serving services -v1.0.5 (30.06.2018) -------- +## v1.0.5 (30.06.2018) + - docker compatible logging (forcing TTY output for logrus) -v1.0.4 (25.06.2018) -------- +## v1.0.4 (25.06.2018) + - changes in server shutdown sequence -v1.0.3 (23.06.2018) -------- +## v1.0.3 (23.06.2018) + - rr would provide error log from workers in realtime now - even better service shutdown - safer unix socket allocation - minor CS -v1.0.2 (19.06.2018) -------- +## v1.0.2 (19.06.2018) + - more validations for user configs -v1.0.1 (15.06.2018) -------- +## v1.0.1 (15.06.2018) + - Makefile added -v1.0.0 (14.06.2018) ------- +## v1.0.0 (14.06.2018) + - higher performance - worker.State.Updated() has been removed in order to improve overall performance - staticPool can automatically replace workers killed from outside -- cgit v1.2.3 From aff4d2c7a92ae014988b27b27069b15a971b6c36 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Fri, 15 Jan 2021 00:29:23 +0300 Subject: Viper doesn't support `yaml` structure tags, it uses mapstructure instead --- .rr.yaml | 50 +++++------ pkg/pool/config.go | 20 ++--- pkg/pool/static_pool.go | 2 +- plugins/http/config.go | 8 +- plugins/http/handler.go | 2 +- plugins/http/plugin.go | 18 ++-- plugins/kv/boltdb/config.go | 2 +- plugins/logger/config.go | 12 +-- plugins/redis/config.go | 42 ++++----- plugins/server/config.go | 188 ++++++++++++++++++++-------------------- plugins/server/plugin.go | 2 +- tests/plugins/config/plugin1.go | 40 ++++----- 12 files changed, 190 insertions(+), 196 deletions(-) diff --git a/.rr.yaml b/.rr.yaml index 18087c2d..bedfca7c 100755 --- a/.rr.yaml +++ b/.rr.yaml @@ -13,23 +13,23 @@ server: logs: mode: development - level: error + level: debug http: address: 127.0.0.1:44933 max_request_size: 1024 - middleware: ["gzip", "headers"] + middleware: [ "gzip", "headers" ] uploads: - forbid: [".php", ".exe", ".bat"] + forbid: [ ".php", ".exe", ".bat" ] trusted_subnets: [ - "10.0.0.0/8", - "127.0.0.0/8", - "172.16.0.0/12", - "192.168.0.0/16", - "::1/128", - "fc00::/7", - "fe80::/10", + "10.0.0.0/8", + "127.0.0.0/8", + "172.16.0.0/12", + "192.168.0.0/16", + "::1/128", + "fc00::/7", + "fe80::/10", ] pool: num_workers: 6 @@ -38,21 +38,21 @@ http: destroy_timeout: 60s supervisor: # WatchTick defines how often to check the state of worker (seconds) - watch_tick: 10 + watch_tick: 1 # TTL defines maximum time worker is allowed to live (seconds) - ttl: 10 + ttl: 0 # IdleTTL defines maximum duration worker can spend in idle mode. Disabled when 0 (seconds) - idle_ttl: 10 + idle_ttl: 100 # ExecTTL defines maximum lifetime per job (seconds) exec_ttl: 10 # MaxWorkerMemory limits memory per worker (MB) max_worker_memory: 100 - ssl: - port: 8892 - redirect: false - cert: fixtures/server.crt - key: fixtures/server.key + # ssl: + # port: 8892 + # redirect: false + # cert: fixtures/server.crt + # key: fixtures/server.key # rootCa: root.crt fcgi: address: tcp://0.0.0.0:7921 @@ -68,7 +68,7 @@ redis: # cluster-specific applications locally. # if the number of addrs is 1 and master_name is empty, a single-node redis Client will be returned - # if the number of Addrs is two or more, a ClusterClient will be returned + # if the number of addrs is two or more, a ClusterClient will be returned addrs: - "localhost:6379" # if a MasterName is passed a sentinel-backed FailoverClient will be returned @@ -120,8 +120,8 @@ metrics: app_metric: type: histogram help: "Custom application metric" - labels: ["type"] - buckets: [0.1, 0.2, 0.3, 1.0] + labels: [ "type" ] + buckets: [ 0.1, 0.2, 0.3, 1.0 ] # objectives defines the quantile rank estimates with their respective # absolute error [ for summary only ] objectives: @@ -132,16 +132,16 @@ reload: # sync interval interval: 1s # global patterns to sync - patterns: [".go"] + patterns: [ ".go" ] # list of included for sync services services: http: # recursive search for file patterns to add recursive: true # ignored folders - ignore: ["vendor"] + ignore: [ "vendor" ] # service specific file pattens to sync - patterns: [".php", ".go", ".md"] + patterns: [ ".php", ".go", ".md" ] # directories to sync. If recursive is set to true, # recursive sync will be applied only to the directories in `dirs` section - dirs: ["."] + dirs: [ "." ] diff --git a/pkg/pool/config.go b/pkg/pool/config.go index acdd3d6f..e3e2d3cd 100644 --- a/pkg/pool/config.go +++ b/pkg/pool/config.go @@ -12,23 +12,23 @@ type Config struct { // NumWorkers defines how many sub-processes can be run at once. This value // might be doubled by Swapper while hot-swap. Defaults to number of CPU cores. - NumWorkers int64 `yaml:"num_workers"` + NumWorkers int64 `mapstructure:"num_workers"` // MaxJobs defines how many executions is allowed for the worker until // it's destruction. set 1 to create new process for each new task, 0 to let // worker handle as many tasks as it can. - MaxJobs int64 `yaml:"max_jobs"` + MaxJobs int64 `mapstructure:"max_jobs"` // AllocateTimeout defines for how long pool will be waiting for a worker to // be freed to handle the task. Defaults to 60s. - AllocateTimeout time.Duration `yaml:"allocate_timeout"` + AllocateTimeout time.Duration `mapstructure:"allocate_timeout"` // DestroyTimeout defines for how long pool should be waiting for worker to // properly destroy, if timeout reached worker will be killed. Defaults to 60s. - DestroyTimeout time.Duration `yaml:"destroy_timeout"` + DestroyTimeout time.Duration `mapstructure:"destroy_timeout"` // Supervision config to limit worker and pool memory usage. - Supervisor *SupervisorConfig `yaml:"supervisor"` + Supervisor *SupervisorConfig `mapstructure:"supervisor"` } // InitDefaults enables default config values. @@ -52,19 +52,19 @@ func (cfg *Config) InitDefaults() { type SupervisorConfig struct { // WatchTick defines how often to check the state of worker. - WatchTick uint64 `yaml:"watch_tick"` + WatchTick uint64 `mapstructure:"watch_tick"` // TTL defines maximum time worker is allowed to live. - TTL uint64 `yaml:"ttl"` + TTL uint64 `mapstructure:"ttl"` // IdleTTL defines maximum duration worker can spend in idle mode. Disabled when 0. - IdleTTL uint64 `yaml:"idle_ttl"` + IdleTTL uint64 `mapstructure:"idle_ttl"` // ExecTTL defines maximum lifetime per job. - ExecTTL uint64 `yaml:"exec_ttl"` + ExecTTL uint64 `mapstructure:"exec_ttl"` // MaxWorkerMemory limits memory per worker. - MaxWorkerMemory uint64 `yaml:"max_worker_memory"` + MaxWorkerMemory uint64 `mapstructure:"max_worker_memory"` } // InitDefaults enables default config values. diff --git a/pkg/pool/static_pool.go b/pkg/pool/static_pool.go index bb53e121..7cac7b4d 100755 --- a/pkg/pool/static_pool.go +++ b/pkg/pool/static_pool.go @@ -54,7 +54,7 @@ type StaticPool struct { // Initialize creates new worker pool and task multiplexer. StaticPool will initiate with one worker. func Initialize(ctx context.Context, cmd Command, factory worker.Factory, cfg Config, options ...Options) (pool.Pool, error) { - const op = errors.Op("Initialize") + const op = errors.Op("static pool initialize") if factory == nil { return nil, errors.E(op, errors.Str("no factory initialized")) } diff --git a/plugins/http/config.go b/plugins/http/config.go index abde8917..e272e550 100644 --- a/plugins/http/config.go +++ b/plugins/http/config.go @@ -49,16 +49,16 @@ type Config struct { HTTP2 *HTTP2Config // MaxRequestSize specified max size for payload body in megabytes, set 0 to unlimited. - MaxRequestSize uint64 `yaml:"max_request_size"` + MaxRequestSize uint64 `mapstructure:"max_request_size"` // TrustedSubnets declare IP subnets which are allowed to set ip using X-Real-Ip and X-Forwarded-For - TrustedSubnets []string `yaml:"trusted_subnets"` + TrustedSubnets []string `mapstructure:"trusted_subnets"` // Uploads configures uploads configuration. Uploads *UploadsConfig // Pool configures worker pool. - Pool *poolImpl.Config + Pool *poolImpl.Config `mapstructure:"pool"` // Env is environment variables passed to the http pool Env map[string]string @@ -85,7 +85,7 @@ type HTTP2Config struct { H2C bool // MaxConcurrentStreams defaults to 128. - MaxConcurrentStreams uint32 `yaml:"max_concurrent_streams"` + MaxConcurrentStreams uint32 `mapstructure:"max_concurrent_streams"` } // InitDefaults sets default values for HTTP/2 configuration. diff --git a/plugins/http/handler.go b/plugins/http/handler.go index 9c40cdfc..1c7f79e3 100644 --- a/plugins/http/handler.go +++ b/plugins/http/handler.go @@ -24,7 +24,7 @@ const ( ) // MB is 1024 bytes -const MB = 1024 * 1024 +const MB uint64 = 1024 * 1024 // ErrorEvent represents singular http error event. type ErrorEvent struct { diff --git a/plugins/http/plugin.go b/plugins/http/plugin.go index e6aba78b..70e91cbe 100644 --- a/plugins/http/plugin.go +++ b/plugins/http/plugin.go @@ -48,11 +48,11 @@ type middleware map[string]Middleware type Plugin struct { sync.RWMutex - configurer config.Configurer - server server.Server - log logger.Logger + // plugins + server server.Server + log logger.Logger - cfg *Config + cfg *Config `mapstructure:"http"` // middlewares to chain mdwr middleware @@ -71,7 +71,7 @@ type Plugin struct { // Init must return configure svc and return true if svc hasStatus enabled. Must return error in case of // misconfiguration. Services must not be used without proper configuration pushed first. func (s *Plugin) Init(cfg config.Configurer, log logger.Logger, server server.Server) error { - const op = errors.Op("http Init") + const op = errors.Op("http plugin init") err := cfg.UnmarshalKey(PluginName, &s.cfg) if err != nil { return errors.E(op, err) @@ -82,7 +82,6 @@ func (s *Plugin) Init(cfg config.Configurer, log logger.Logger, server server.Se return errors.E(op, err) } - s.configurer = cfg s.log = log s.mdwr = make(map[string]Middleware) @@ -286,12 +285,7 @@ func (s *Plugin) Reset() error { s.pool.Destroy(context.Background()) s.pool = nil - // re-read the config - err := s.configurer.UnmarshalKey(PluginName, &s.cfg) - if err != nil { - return errors.E(op, err) - } - + var err error s.pool, err = s.server.NewWorkerPool(context.Background(), poolImpl.Config{ Debug: s.cfg.Pool.Debug, NumWorkers: s.cfg.Pool.NumWorkers, diff --git a/plugins/kv/boltdb/config.go b/plugins/kv/boltdb/config.go index b2e1e636..ea0e3375 100644 --- a/plugins/kv/boltdb/config.go +++ b/plugins/kv/boltdb/config.go @@ -11,7 +11,7 @@ type Config struct { // db file permissions Permissions int // timeout - Interval uint `yaml:"interval"` + Interval uint `mapstructure:"interval"` } // InitDefaults initializes default values for the boltdb diff --git a/plugins/logger/config.go b/plugins/logger/config.go index f7a5742c..8cc88d02 100644 --- a/plugins/logger/config.go +++ b/plugins/logger/config.go @@ -10,26 +10,26 @@ import ( // ChannelConfig configures loggers per channel. type ChannelConfig struct { // Dedicated channels per logger. By default logger allocated via named logger. - Channels map[string]Config `json:"channels" yaml:"channels"` + Channels map[string]Config `json:"channels" mapstructure:"channels"` } type Config struct { // Mode configures logger based on some default template (development, production, off). - Mode string `json:"mode" yaml:"mode"` + Mode string `json:"mode" mapstructure:"mode"` // Level is the minimum enabled logging level. Note that this is a dynamic // level, so calling ChannelConfig.Level.SetLevel will atomically change the log // level of all loggers descended from this config. - Level string `json:"level" yaml:"level"` + Level string `json:"level" mapstructure:"level"` // Encoding sets the logger's encoding. Valid values are "json" and // "console", as well as any third-party encodings registered via // RegisterEncoder. - Encoding string `json:"encoding" yaml:"encoding"` + Encoding string `json:"encoding" mapstructure:"encoding"` // Output is a list of URLs or file paths to write logging output to. // See Open for details. - Output []string `json:"output" yaml:"output"` + Output []string `json:"output" mapstructure:"output"` // ErrorOutput is a list of URLs to write internal logger errors to. // The default is standard error. @@ -37,7 +37,7 @@ type Config struct { // Note that this setting only affects internal errors; for sample code that // sends error-level logs to a different location from info- and debug-level // logs, see the package-level AdvancedConfiguration example. - ErrorOutput []string `json:"errorOutput" yaml:"errorOutput"` + ErrorOutput []string `json:"errorOutput" mapstructure:"errorOutput"` } // ZapConfig converts config into Zap configuration. diff --git a/plugins/redis/config.go b/plugins/redis/config.go index ebcefed1..58766293 100644 --- a/plugins/redis/config.go +++ b/plugins/redis/config.go @@ -3,27 +3,27 @@ package redis import "time" type Config struct { - Addrs []string `yaml:"addrs"` - DB int `yaml:"db"` - Username string `yaml:"username"` - Password string `yaml:"password"` - MasterName string `yaml:"master_name"` - SentinelPassword string `yaml:"sentinel_password"` - RouteByLatency bool `yaml:"route_by_latency"` - RouteRandomly bool `yaml:"route_randomly"` - MaxRetries int `yaml:"max_retries"` - DialTimeout time.Duration `yaml:"dial_timeout"` - MinRetryBackoff time.Duration `yaml:"min_retry_backoff"` - MaxRetryBackoff time.Duration `yaml:"max_retry_backoff"` - PoolSize int `yaml:"pool_size"` - MinIdleConns int `yaml:"min_idle_conns"` - MaxConnAge time.Duration `yaml:"max_conn_age"` - ReadTimeout time.Duration `yaml:"read_timeout"` - WriteTimeout time.Duration `yaml:"write_timeout"` - PoolTimeout time.Duration `yaml:"pool_timeout"` - IdleTimeout time.Duration `yaml:"idle_timeout"` - IdleCheckFreq time.Duration `yaml:"idle_check_freq"` - ReadOnly bool `yaml:"read_only"` + Addrs []string `mapstructure:"addrs"` + DB int `mapstructure:"db"` + Username string `mapstructure:"username"` + Password string `mapstructure:"password"` + MasterName string `mapstructure:"master_name"` + SentinelPassword string `mapstructure:"sentinel_password"` + RouteByLatency bool `mapstructure:"route_by_latency"` + RouteRandomly bool `mapstructure:"route_randomly"` + MaxRetries int `mapstructure:"max_retries"` + DialTimeout time.Duration `mapstructure:"dial_timeout"` + MinRetryBackoff time.Duration `mapstructure:"min_retry_backoff"` + MaxRetryBackoff time.Duration `mapstructure:"max_retry_backoff"` + PoolSize int `mapstructure:"pool_size"` + MinIdleConns int `mapstructure:"min_idle_conns"` + MaxConnAge time.Duration `mapstructure:"max_conn_age"` + ReadTimeout time.Duration `mapstructure:"read_timeout"` + WriteTimeout time.Duration `mapstructure:"write_timeout"` + PoolTimeout time.Duration `mapstructure:"pool_timeout"` + IdleTimeout time.Duration `mapstructure:"idle_timeout"` + IdleCheckFreq time.Duration `mapstructure:"idle_check_freq"` + ReadOnly bool `mapstructure:"read_only"` } // InitDefaults initializing fill config with default values diff --git a/plugins/server/config.go b/plugins/server/config.go index a990efd3..93b19226 100644 --- a/plugins/server/config.go +++ b/plugins/server/config.go @@ -10,129 +10,129 @@ type Config struct { // Server config section Server struct { // Command to run as application. - Command string `yaml:"command"` + Command string `mapstructure:"command"` // User to run application under. - User string `yaml:"user"` + User string `mapstructure:"user"` // Group to run application under. - Group string `yaml:"group"` + Group string `mapstructure:"group"` // Env represents application environment. - Env Env `yaml:"env"` + Env Env `mapstructure:"env"` // Relay defines connection method and factory to be used to connect to workers: // "pipes", "tcp://:6001", "unix://rr.sock" // This config section must not change on re-configuration. - Relay string `yaml:"relay"` + Relay string `mapstructure:"relay"` // RelayTimeout defines for how long socket factory will be waiting for worker connection. This config section // must not change on re-configuration. Defaults to 60s. - RelayTimeout time.Duration `yaml:"relayTimeout"` - } `yaml:"server"` + RelayTimeout time.Duration `mapstructure:"relayTimeout"` + } `mapstructure:"server"` RPC *struct { - Listen string `yaml:"listen"` - } `yaml:"rpc"` + Listen string `mapstructure:"listen"` + } `mapstructure:"rpc"` Logs *struct { - Mode string `yaml:"mode"` - Level string `yaml:"level"` - } `yaml:"logs"` + Mode string `mapstructure:"mode"` + Level string `mapstructure:"level"` + } `mapstructure:"logs"` HTTP *struct { - Address string `yaml:"address"` - MaxRequestSize int `yaml:"max_request_size"` - Middleware []string `yaml:"middleware"` + Address string `mapstructure:"address"` + MaxRequestSize int `mapstructure:"max_request_size"` + Middleware []string `mapstructure:"middleware"` Uploads struct { - Forbid []string `yaml:"forbid"` - } `yaml:"uploads"` - TrustedSubnets []string `yaml:"trusted_subnets"` + Forbid []string `mapstructure:"forbid"` + } `mapstructure:"uploads"` + TrustedSubnets []string `mapstructure:"trusted_subnets"` Pool struct { - NumWorkers int `yaml:"num_workers"` - MaxJobs int `yaml:"max_jobs"` - AllocateTimeout string `yaml:"allocate_timeout"` - DestroyTimeout string `yaml:"destroy_timeout"` + NumWorkers int `mapstructure:"num_workers"` + MaxJobs int `mapstructure:"max_jobs"` + AllocateTimeout string `mapstructure:"allocate_timeout"` + DestroyTimeout string `mapstructure:"destroy_timeout"` Supervisor struct { - WatchTick int `yaml:"watch_tick"` - TTL int `yaml:"ttl"` - IdleTTL int `yaml:"idle_ttl"` - ExecTTL int `yaml:"exec_ttl"` - MaxWorkerMemory int `yaml:"max_worker_memory"` - } `yaml:"supervisor"` - } `yaml:"pool"` + WatchTick int `mapstructure:"watch_tick"` + TTL int `mapstructure:"ttl"` + IdleTTL int `mapstructure:"idle_ttl"` + ExecTTL int `mapstructure:"exec_ttl"` + MaxWorkerMemory int `mapstructure:"max_worker_memory"` + } `mapstructure:"supervisor"` + } `mapstructure:"pool"` Ssl struct { - Port int `yaml:"port"` - Redirect bool `yaml:"redirect"` - Cert string `yaml:"cert"` - Key string `yaml:"key"` - } `yaml:"ssl"` + Port int `mapstructure:"port"` + Redirect bool `mapstructure:"redirect"` + Cert string `mapstructure:"cert"` + Key string `mapstructure:"key"` + } `mapstructure:"ssl"` Fcgi struct { - Address string `yaml:"address"` - } `yaml:"fcgi"` + Address string `mapstructure:"address"` + } `mapstructure:"fcgi"` HTTP2 struct { - Enabled bool `yaml:"enabled"` - H2C bool `yaml:"h2c"` - MaxConcurrentStreams int `yaml:"max_concurrent_streams"` - } `yaml:"http2"` - } `yaml:"http"` + Enabled bool `mapstructure:"enabled"` + H2C bool `mapstructure:"h2c"` + MaxConcurrentStreams int `mapstructure:"max_concurrent_streams"` + } `mapstructure:"http2"` + } `mapstructure:"http"` Redis *struct { - Addrs []string `yaml:"addrs"` - MasterName string `yaml:"master_name"` - Username string `yaml:"username"` - Password string `yaml:"password"` - DB int `yaml:"db"` - SentinelPassword string `yaml:"sentinel_password"` - RouteByLatency bool `yaml:"route_by_latency"` - RouteRandomly bool `yaml:"route_randomly"` - DialTimeout int `yaml:"dial_timeout"` - MaxRetries int `yaml:"max_retries"` - MinRetryBackoff int `yaml:"min_retry_backoff"` - MaxRetryBackoff int `yaml:"max_retry_backoff"` - PoolSize int `yaml:"pool_size"` - MinIdleConns int `yaml:"min_idle_conns"` - MaxConnAge int `yaml:"max_conn_age"` - ReadTimeout int `yaml:"read_timeout"` - WriteTimeout int `yaml:"write_timeout"` - PoolTimeout int `yaml:"pool_timeout"` - IdleTimeout int `yaml:"idle_timeout"` - IdleCheckFreq int `yaml:"idle_check_freq"` - ReadOnly bool `yaml:"read_only"` - } `yaml:"redis"` + Addrs []string `mapstructure:"addrs"` + MasterName string `mapstructure:"master_name"` + Username string `mapstructure:"username"` + Password string `mapstructure:"password"` + DB int `mapstructure:"db"` + SentinelPassword string `mapstructure:"sentinel_password"` + RouteByLatency bool `mapstructure:"route_by_latency"` + RouteRandomly bool `mapstructure:"route_randomly"` + DialTimeout int `mapstructure:"dial_timeout"` + MaxRetries int `mapstructure:"max_retries"` + MinRetryBackoff int `mapstructure:"min_retry_backoff"` + MaxRetryBackoff int `mapstructure:"max_retry_backoff"` + PoolSize int `mapstructure:"pool_size"` + MinIdleConns int `mapstructure:"min_idle_conns"` + MaxConnAge int `mapstructure:"max_conn_age"` + ReadTimeout int `mapstructure:"read_timeout"` + WriteTimeout int `mapstructure:"write_timeout"` + PoolTimeout int `mapstructure:"pool_timeout"` + IdleTimeout int `mapstructure:"idle_timeout"` + IdleCheckFreq int `mapstructure:"idle_check_freq"` + ReadOnly bool `mapstructure:"read_only"` + } `mapstructure:"redis"` Boltdb *struct { - Dir string `yaml:"dir"` - File string `yaml:"file"` - Bucket string `yaml:"bucket"` - Permissions int `yaml:"permissions"` - TTL int `yaml:"TTL"` - } `yaml:"boltdb"` + Dir string `mapstructure:"dir"` + File string `mapstructure:"file"` + Bucket string `mapstructure:"bucket"` + Permissions int `mapstructure:"permissions"` + TTL int `mapstructure:"TTL"` + } `mapstructure:"boltdb"` Memcached *struct { - Addr []string `yaml:"addr"` - } `yaml:"memcached"` + Addr []string `mapstructure:"addr"` + } `mapstructure:"memcached"` Memory *struct { - Enabled bool `yaml:"enabled"` - Interval int `yaml:"interval"` - } `yaml:"memory"` + Enabled bool `mapstructure:"enabled"` + Interval int `mapstructure:"interval"` + } `mapstructure:"memory"` Metrics *struct { - Address string `yaml:"address"` + Address string `mapstructure:"address"` Collect struct { AppMetric struct { - Type string `yaml:"type"` - Help string `yaml:"help"` - Labels []string `yaml:"labels"` - Buckets []float64 `yaml:"buckets"` + Type string `mapstructure:"type"` + Help string `mapstructure:"help"` + Labels []string `mapstructure:"labels"` + Buckets []float64 `mapstructure:"buckets"` Objectives []struct { - Num2 float64 `yaml:"2,omitempty"` - One4 float64 `yaml:"1.4,omitempty"` - } `yaml:"objectives"` - } `yaml:"app_metric"` - } `yaml:"collect"` - } `yaml:"metrics"` + Num2 float64 `mapstructure:"2,omitempty"` + One4 float64 `mapstructure:"1.4,omitempty"` + } `mapstructure:"objectives"` + } `mapstructure:"app_metric"` + } `mapstructure:"collect"` + } `mapstructure:"metrics"` Reload *struct { - Interval string `yaml:"interval"` - Patterns []string `yaml:"patterns"` + Interval string `mapstructure:"interval"` + Patterns []string `mapstructure:"patterns"` Services struct { HTTP struct { - Recursive bool `yaml:"recursive"` - Ignore []string `yaml:"ignore"` - Patterns []string `yaml:"patterns"` - Dirs []string `yaml:"dirs"` - } `yaml:"http"` - } `yaml:"services"` - } `yaml:"reload"` + Recursive bool `mapstructure:"recursive"` + Ignore []string `mapstructure:"ignore"` + Patterns []string `mapstructure:"patterns"` + Dirs []string `mapstructure:"dirs"` + } `mapstructure:"http"` + } `mapstructure:"services"` + } `mapstructure:"reload"` } // InitDefaults for the server config diff --git a/plugins/server/plugin.go b/plugins/server/plugin.go index 565c80c4..8c39b783 100644 --- a/plugins/server/plugin.go +++ b/plugins/server/plugin.go @@ -40,7 +40,7 @@ type Plugin struct { // Init application provider. func (server *Plugin) Init(cfg config.Configurer, log logger.Logger) error { - const op = errors.Op("Init") + const op = errors.Op("server plugin init") err := cfg.Unmarshal(&server.cfg) if err != nil { return errors.E(op, errors.Init, err) diff --git a/tests/plugins/config/plugin1.go b/tests/plugins/config/plugin1.go index a6c06aec..c77e7aa7 100755 --- a/tests/plugins/config/plugin1.go +++ b/tests/plugins/config/plugin1.go @@ -9,31 +9,31 @@ import ( type AllConfig struct { RPC struct { - Listen string `yaml:"listen"` - } `yaml:"rpc"` + Listen string `mapstructure:"listen"` + } `mapstructure:"rpc"` Reload struct { - Enabled bool `yaml:"enabled"` - Interval string `yaml:"interval"` - Patterns []string `yaml:"patterns"` + Enabled bool `mapstructure:"enabled"` + Interval string `mapstructure:"interval"` + Patterns []string `mapstructure:"patterns"` Services struct { HTTP struct { - Recursive bool `yaml:"recursive"` - Ignore []string `yaml:"ignore"` - Patterns []string `yaml:"patterns"` - Dirs []string `yaml:"dirs"` - } `yaml:"http"` + Recursive bool `mapstructure:"recursive"` + Ignore []string `mapstructure:"ignore"` + Patterns []string `mapstructure:"patterns"` + Dirs []string `mapstructure:"dirs"` + } `mapstructure:"http"` Jobs struct { - Recursive bool `yaml:"recursive"` - Ignore []string `yaml:"ignore"` - Dirs []string `yaml:"dirs"` - } `yaml:"jobs"` + Recursive bool `mapstructure:"recursive"` + Ignore []string `mapstructure:"ignore"` + Dirs []string `mapstructure:"dirs"` + } `mapstructure:"jobs"` RPC struct { - Recursive bool `yaml:"recursive"` - Patterns []string `yaml:"patterns"` - Dirs []string `yaml:"dirs"` - } `yaml:"rpc"` - } `yaml:"services"` - } `yaml:"reload"` + Recursive bool `mapstructure:"recursive"` + Patterns []string `mapstructure:"patterns"` + Dirs []string `mapstructure:"dirs"` + } `mapstructure:"rpc"` + } `mapstructure:"services"` + } `mapstructure:"reload"` } // ReloadConfig is a Reload configuration point. -- cgit v1.2.3