Schedule
stages
Commentary
added in 0.6.0
Executes generators in a sequence (instead of the normal round-robin behavior), where each step in the sequence is called a stage.
At a minimum, each stage must name which generators will run. You specify those generators by supplying a name
attribute on the generator definition itself. 1
The generators in each stage will only begin running after the previous stage's generators have all terminated. You can terminate with a generator with maxEvents
, maxMs
, or a stateMachine
with a transition that has no further states.
In addition to being able to name what generators should run in each stage, you can also specify overrides so that a generator will behave differently in two different stages. 2
Examples
Defining stages
Set a name
on each generator you want to schedule. In this example, that's simply a
and b
.
Then, under the stages
key of schedule
, name the generators to run. Notice in the output how a
runs to completion, and then b
takes over.
{
"generators": [
{
"name": "a",
"topic": "generatorA",
"value": {
"_gen": "oneOf",
"choices": [
1,
2,
3
]
},
"localConfigs": {
"maxEvents": 3
}
},
{
"name": "b",
"topic": "generatorB",
"value": {
"_gen": "boolean"
},
"localConfigs": {
"maxEvents": 2
}
}
],
"schedule": {
"stages": [
{
"generators": [
"a"
]
},
{
"generators": [
"b"
]
}
]
},
"connections": {
"kafka": {
"kind": "kafka",
"producerConfigs": {
"bootstrap.servers": "localhost:9092",
"key.serializer": "io.shadowtraffic.kafka.serdes.JsonSerializer",
"value.serializer": "io.shadowtraffic.kafka.serdes.JsonSerializer"
}
}
}
}
[
2,
1,
2,
true,
false
]
Overriding generators
Use the overrides
key in a stage to change the behavior of a generator when that stage executes. This is useful if you want to quickly seed some data by setting throttleMs
to 0
, and then generate it more sporadically later on.
overrides
must be a map of generator name to object. The contents of override will be merged into the base generator definition.
In this example, generator a
is overriden to produce only 5
events, and b
only 4
.
{
"generators": [
{
"name": "a",
"topic": "generatorA",
"value": {
"_gen": "oneOf",
"choices": [
1,
2,
3
]
}
},
{
"name": "b",
"topic": "generatorB",
"value": {
"_gen": "boolean"
}
}
],
"schedule": {
"stages": [
{
"generators": [
"a"
],
"overrides": {
"a": {
"localConfigs": {
"maxEvents": 5
}
}
}
},
{
"generators": [
"b"
],
"overrides": {
"b": {
"localConfigs": {
"maxEvents": 4
}
}
}
}
]
},
"connections": {
"kafka": {
"kind": "kafka",
"producerConfigs": {
"bootstrap.servers": "localhost:9092",
"key.serializer": "io.shadowtraffic.kafka.serdes.JsonSerializer",
"value.serializer": "io.shadowtraffic.kafka.serdes.JsonSerializer"
}
}
}
}
[
3,
2,
1,
1,
3,
true,
false,
false,
true
]
Specification
JSON schema
{
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"properties": {
"generators": {
"type": "array",
"minItems": 1,
"items": {
"type": "string"
}
},
"overrides": {
"type": "object",
"additionalProperties": {
"type": "object"
}
}
},
"required": [
"generators"
]
}
}