Integers are being quoted in resulting JSON structure when passed in via the environment, resulting in Type Cast Errors in downstream systems
See original GitHub issueDescribe the bug
[2021-11-24 18:37:32 ERROR] => failed: chaoslib.exceptions.ActivityFailed: Turbulence atttack failed: {
"error": "Unmarshalling task type 'Stress': json: cannot unmarshal string into Go struct field StressOptions.NumCPUWorkers of type int"
}
Is occurring in the downstream Turbulence/Stress system call behind the ChaosTK driver, this appears to be a result of the quoting scheme that chaostk/python are using for inputs passed in via the environment.
consider the following configuration definition fragment:
configuration: {
"cpu_workers": {
"type": "env",
"key": "STRESS_CPU_NUM_WORKERS",
"default": 2
}
...
}
When no environment variable for STRESS_CPU_NUM_WORKERS is set in the environment, then the “default” value of 2 is not quoted in the resulting JSON body (correct integer handling), and we can see this in the log when the attack works properly:
[2021-11-24 18:14:40 DEBUG] [actions:30] Posting `{'Tasks': [{'Type': 'Stress', 'NumCPUWorkers': 2 ...
but as soon as I export STRESS_CPU_NUM_WORKERS=3 and re-run the experiment, I see this in the log (and the attacks fails with the very first error message described in this bug report at the top):
[2021-11-24 18:15:58 DEBUG] [actions:30] Posting `{'Tasks': [{'Type': 'Stress', 'NumCPUWorkers': '3' ...
which quotes the integer with single quotes, and that breaks the integer parsing by GO in the downstream Stress/Turbulence binary.
I have also tried this with no success either:
chaos run --no-verify-tls --var cpu_workers=3 experiments/turbulence/stress_cpu_random_job.json
How do I pass an Integer in via environment variable and have it quoted correctly in the JSON passed to Turbulence? (which would be no quoting at all for integers)
Runtime versions Please run:
# python3 --version
Python 3.6.9
# chaos info core
NAME VERSION
CLI 1.10.1
Core library 1.23.0
# chaos info extensions
NAME VERSION LICENSE DESCRIPTION
chaostoolkit-cloud-foundry 0.7.1 Apache License Version 2.0 Cloud Foundry
chaostoolkit-turbulence 0.1.0 UNKNOWN Chaos Toolkit Turbulence support
To Reproduce
Define a configuration variable for a simple integer as shown above, and have it be passed along in the resulting JSON payload without quotes (proper integer handling).
Expected behavior
Integers in JSON have no quotes, so I would expect an integer value to not have quotes in the resulting JSON body
Additional context
This only seems to be a problem when the downstream system expects strict typing adherence in the JSON body.
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (3 by maintainers)
Top GitHub Comments
It Werkz!! 😄
Two Thumbs Up and a Tonne of Thanks Folks!! 🙏
Keep up the Great Work. 😎
Wow, that was a quick response AND a new feature ready for us to test in a debug build - I ♥️ you folks!
I can confirm that YES, this does solve our issues. A quick re-cap I added the following to all INT types in the experiment definition:
and then set some INT values to be passed in via the environment:
and I can see in the chaostoolkit.log file that the JSON payload destined for the Turbulence API server is properly formed with respect to integer handling:
Well done and a quick turn around - many many thanks!
Any idea how soon this might show up in the mainline releases??