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" # "key" = "value"
## One or more mock data fields *must* be defined. ## One or more mock data fields *must* be defined.
## # [[inputs.mock.constant]]
## [[inputs.mock.constant]] # name = "constant"
## name = "constant" # value = value_of_any_type
## value = value_of_any_type # [[inputs.mock.random]]
## [[inputs.mock.random]] # name = "rand"
## name = "rand" # min = 1.0
## min = 1.0 # max = 6.0
## max = 6.0 # [[inputs.mock.sine_wave]]
## [[inputs.mock.sine_wave]] # name = "wave"
## name = "wave" # amplitude = 1.0
## amplitude = 1.0 # period = 0.5
## period = 0.5 # [[inputs.mock.step]]
## [[inputs.mock.step]] # name = "plus_one"
## name = "plus_one" # start = 0.0
## start = 0.0 # step = 1.0
## step = 1.0 # [[inputs.mock.stock]]
## [[inputs.mock.stock]] # name = "abc"
## name = "abc" # price = 50.00
## price = 50.00 # volatility = 0.2
## volatility = 0.2
``` ```
The mock plugin only requires that: The mock plugin only requires that:

View File

@ -49,8 +49,11 @@ type step struct {
latest float64 latest float64
Name string `toml:"name"` Name string `toml:"name"`
Start float64 `toml:"min"` Start float64 `toml:"start"`
Step float64 `toml:"max"` 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 { type stock struct {
@ -67,6 +70,17 @@ func (*Mock) SampleConfig() string {
func (m *Mock) Init() error { func (m *Mock) Init() error {
m.rand = rand.New(rand.NewSource(time.Now().UnixNano())) //nolint:gosec // G404: not security critical 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 return nil
} }

View File

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