diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index b18f82c01ca..70d9d8958b3 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -32,8 +32,10 @@ https://github.com/elastic/beats/compare/v5.0.0-beta1...master[Check the HEAD di *Affecting all Beats* - Make sure Beats sent always float values when they are defined as float by sending 5.00000 instead of 5. {pull}2627[2627] - - Fix ignoring all fields from drop_fields in case the first field is unknown. {pull}2685[2685] +- Fix dynamic configuration int/uint to float type conversation. {pull}2698[2698] +- Fix primitive types conversation if values are read from environment variables. {pull}2698[2698] + *Metricbeat* diff --git a/glide.yaml b/glide.yaml index 706cdcb5574..9475e06b6b3 100644 --- a/glide.yaml +++ b/glide.yaml @@ -75,7 +75,7 @@ import: - package: github.com/dustin/go-humanize version: 499693e27ee0d14ffab67c31ad065fdb3d34ea75 - package: github.com/elastic/go-ucfg - version: v0.3.6 + version: v0.3.7 - package: github.com/armon/go-socks5 version: 3a873e99f5400ad7706e464e905ffcc94b3ff247 - package: github.com/pkg/errors diff --git a/vendor/github.com/elastic/go-ucfg/CHANGELOG.md b/vendor/github.com/elastic/go-ucfg/CHANGELOG.md index d7e45eb422e..1d5c8942987 100644 --- a/vendor/github.com/elastic/go-ucfg/CHANGELOG.md +++ b/vendor/github.com/elastic/go-ucfg/CHANGELOG.md @@ -14,6 +14,13 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Fixed +## [0.3.7] + +### Fixed +- Fix int/uint to float type conversation. #68 +- Fix primitive type unpacking for variables expanded from environment variables + or strings read/created by config file parsers. #67 + ## [0.3.6] ### Fixed @@ -111,7 +118,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Introduced CHANGELOG.md for documenting changes to ucfg. -[Unreleased]: https://github.com/elastic/go-ucfg/compare/v0.3.6...HEAD +[Unreleased]: https://github.com/elastic/go-ucfg/compare/v0.3.7...HEAD +[0.3.7]: https://github.com/elastic/go-ucfg/compare/v0.3.6...v0.3.7 [0.3.6]: https://github.com/elastic/go-ucfg/compare/v0.3.5...v0.3.6 [0.3.5]: https://github.com/elastic/go-ucfg/compare/v0.3.4...v0.3.5 [0.3.4]: https://github.com/elastic/go-ucfg/compare/v0.3.3...v0.3.4 diff --git a/vendor/github.com/elastic/go-ucfg/README.md b/vendor/github.com/elastic/go-ucfg/README.md index 7a5c962820a..446a179703b 100644 --- a/vendor/github.com/elastic/go-ucfg/README.md +++ b/vendor/github.com/elastic/go-ucfg/README.md @@ -58,7 +58,7 @@ ucfg allows to automatically validate fields and set defaults for fields in case ``` // Defines struct to read config from type ExampleConfig struct { - Counter string `config:"username" validate:"min=0, max=9"` + Counter string `config:"counter" validate:"min=0, max=9"` } // Defines default config option @@ -66,11 +66,20 @@ var ( defaultConfig = ExampleConfig{ Counter: 4, } -} +) func main() { + appConfig := defaultConfig // copy default config so it's not overwritten config, err := yaml.NewConfigWithFile(path, ucfg.PathSep(".")) - config.Unpack(defaultConfig) + if err != nil { + fmt.Fprintln(err) + os.Exit(1) + } + err = config.Unpack(&appConfig) + if err != nil { + fmt.Fprintln(err) + os.Exit(1) + } } ``` diff --git a/vendor/github.com/elastic/go-ucfg/reify.go b/vendor/github.com/elastic/go-ucfg/reify.go index bc2fc2aeca2..65a4a44e0a1 100644 --- a/vendor/github.com/elastic/go-ucfg/reify.go +++ b/vendor/github.com/elastic/go-ucfg/reify.go @@ -521,6 +521,13 @@ func doReifyPrimitive( } return v, nil + case isFloat(kind): + v, err := reifyFloat(opts, val, baseType) + if err != nil { + return v, err + } + return v, nil + case kind == reflect.Bool: v, err := reifyBool(opts, val, baseType) if err != nil { @@ -624,6 +631,23 @@ func reifyUint( return reflect.ValueOf(u).Convert(t), nil } +func reifyFloat( + opts fieldOptions, + val value, + t reflect.Type, +) (reflect.Value, Error) { + f, err := val.toFloat(opts.opts) + if err != nil { + return reflect.Value{}, raiseConversion(opts.opts, val, err, "float") + } + + tmp := reflect.Zero(t) + if tmp.OverflowFloat(f) { + return reflect.Value{}, raiseConversion(opts.opts, val, ErrOverflow, "float") + } + return reflect.ValueOf(f).Convert(t), nil +} + func reifyBool( opts fieldOptions, val value, diff --git a/vendor/github.com/elastic/go-ucfg/types.go b/vendor/github.com/elastic/go-ucfg/types.go index 4df7621554d..dd96a811f32 100644 --- a/vendor/github.com/elastic/go-ucfg/types.go +++ b/vendor/github.com/elastic/go-ucfg/types.go @@ -195,6 +195,7 @@ func (c *cfgBool) typ(*options) (typeInfo, error) { return typeInfo{"bo func (c *cfgInt) cpy(ctx context) value { return newInt(ctx, c.meta(), c.i) } func (c *cfgInt) toInt(*options) (int64, error) { return c.i, nil } +func (c *cfgInt) toFloat(*options) (float64, error) { return float64(c.i), nil } func (c *cfgInt) reflect(*options) (reflect.Value, error) { return reflect.ValueOf(c.i), nil } func (c *cfgInt) reify(*options) (interface{}, error) { return c.i, nil } func (c *cfgInt) toString(*options) (string, error) { return fmt.Sprintf("%d", c.i), nil } @@ -212,6 +213,7 @@ func (c *cfgUint) reify(*options) (interface{}, error) { return c.u, nil } func (c *cfgUint) toString(*options) (string, error) { return fmt.Sprintf("%d", c.u), nil } func (c *cfgUint) typ(*options) (typeInfo, error) { return typeInfo{"uint", tUint64}, nil } func (c *cfgUint) toUint(*options) (uint64, error) { return c.u, nil } +func (c *cfgUint) toFloat(*options) (float64, error) { return float64(c.u), nil } func (c *cfgUint) toInt(*options) (int64, error) { if c.u > math.MaxInt64 { return 0, ErrOverflow @@ -243,13 +245,17 @@ func (c *cfgFloat) toInt(*options) (int64, error) { return int64(c.f), nil } -func (c *cfgString) cpy(ctx context) value { return newString(ctx, c.meta(), c.s) } -func (c *cfgString) toString(*options) (string, error) { return c.s, nil } +func (c *cfgString) cpy(ctx context) value { return newString(ctx, c.meta(), c.s) } func (c *cfgString) reflect(*options) (reflect.Value, error) { return reflect.ValueOf(c.s), nil } func (c *cfgString) reify(*options) (interface{}, error) { return c.s, nil } func (c *cfgString) typ(*options) (typeInfo, error) { return typeInfo{"string", tString}, nil } +func (c *cfgString) toBool(*options) (bool, error) { return strconv.ParseBool(c.s) } +func (c *cfgString) toString(*options) (string, error) { return c.s, nil } +func (c *cfgString) toInt(*options) (int64, error) { return strconv.ParseInt(c.s, 0, 64) } +func (c *cfgString) toUint(*options) (uint64, error) { return strconv.ParseUint(c.s, 0, 64) } +func (c *cfgString) toFloat(*options) (float64, error) { return strconv.ParseFloat(c.s, 64) } func (c cfgSub) Context() context { return c.c.ctx } func (cfgSub) toBool(*options) (bool, error) { return false, ErrTypeMismatch } diff --git a/vendor/github.com/elastic/go-ucfg/util.go b/vendor/github.com/elastic/go-ucfg/util.go index e826160082e..cb80d83d78b 100644 --- a/vendor/github.com/elastic/go-ucfg/util.go +++ b/vendor/github.com/elastic/go-ucfg/util.go @@ -123,6 +123,15 @@ func isUint(k reflect.Kind) bool { } } +func isFloat(k reflect.Kind) bool { + switch k { + case reflect.Float32, reflect.Float64: + return true + default: + return false + } +} + func implementsUnpacker(v reflect.Value) (reflect.Value, bool) { for { if v.Type().Implements(tUnpacker) {