fix(inputs.mock): Plugin not aligned with documentation (#13997)

This commit is contained in:
Thomas Casteleyn 2023-09-26 15:29:17 +02:00 committed by GitHub
parent f58c9555dd
commit 3b00b1da95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 42 deletions

View File

@ -29,26 +29,25 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
# "key" = "value"
## One or more mock data fields *must* be defined.
##
## [[inputs.mock.constant]]
## name = "constant"
## value = value_of_any_type
## [[inputs.mock.random]]
## name = "rand"
## min = 1.0
## max = 6.0
## [[inputs.mock.sine_wave]]
## name = "wave"
## amplitude = 1.0
## period = 0.5
## [[inputs.mock.step]]
## name = "plus_one"
## start = 0.0
## step = 1.0
## [[inputs.mock.stock]]
## name = "abc"
## price = 50.00
## volatility = 0.2
# [[inputs.mock.constant]]
# name = "constant"
# value = value_of_any_type
# [[inputs.mock.random]]
# name = "rand"
# min = 1.0
# max = 6.0
# [[inputs.mock.sine_wave]]
# name = "wave"
# amplitude = 1.0
# period = 0.5
# [[inputs.mock.step]]
# name = "plus_one"
# start = 0.0
# step = 1.0
# [[inputs.mock.stock]]
# name = "abc"
# price = 50.00
# volatility = 0.2
```
The mock plugin only requires that:

View File

@ -49,8 +49,11 @@ type step struct {
latest float64
Name string `toml:"name"`
Start float64 `toml:"min"`
Step float64 `toml:"max"`
Start float64 `toml:"start"`
Step float64 `toml:"step"`
Min float64 `toml:"min" deprecated:"1.28.2;use 'start' instead"`
Max float64 `toml:"max" deprecated:"1.28.2;use 'step' instead"`
}
type stock struct {
@ -67,6 +70,17 @@ func (*Mock) SampleConfig() string {
func (m *Mock) Init() error {
m.rand = rand.New(rand.NewSource(time.Now().UnixNano())) //nolint:gosec // G404: not security critical
// backward compatibility
for _, step := range m.Step {
if step.Min != 0 && step.Start == 0 {
step.Start = step.Min
}
if step.Max != 0 && step.Step == 0 {
step.Step = step.Max
}
}
return nil
}

View File

@ -8,23 +8,22 @@
# "key" = "value"
## One or more mock data fields *must* be defined.
##
## [[inputs.mock.constant]]
## name = "constant"
## value = value_of_any_type
## [[inputs.mock.random]]
## name = "rand"
## min = 1.0
## max = 6.0
## [[inputs.mock.sine_wave]]
## name = "wave"
## amplitude = 1.0
## period = 0.5
## [[inputs.mock.step]]
## name = "plus_one"
## start = 0.0
## step = 1.0
## [[inputs.mock.stock]]
## name = "abc"
## price = 50.00
## volatility = 0.2
# [[inputs.mock.constant]]
# name = "constant"
# value = value_of_any_type
# [[inputs.mock.random]]
# name = "rand"
# min = 1.0
# max = 6.0
# [[inputs.mock.sine_wave]]
# name = "wave"
# amplitude = 1.0
# period = 0.5
# [[inputs.mock.step]]
# name = "plus_one"
# start = 0.0
# step = 1.0
# [[inputs.mock.stock]]
# name = "abc"
# price = 50.00
# volatility = 0.2