toxiproxy icon indicating copy to clipboard operation
toxiproxy copied to clipboard

Populate toxics at startup from a json string

Open worldtiki opened this issue 6 years ago • 14 comments

Ability to provide a configuration at startup.

My use case is the following: I'm running a Kuberneters cluster with several applications/containers deployed. I would like to use Toxiproxy as a sidecar to some of these applications to be able to perform failure testing.

Currently we have two existing options to populate proxies, one from a json file and by making an http request. Neither option is very friendly when using Toxiproxy on containerized environments as they either require a post start script to run the http populate request or mounting a volume with the json config file.

With this change we can provide a json string (at startup) as such: docker run -it shopify/toxiproxy:git -configJson '[{"name": "redis","listen": "0.0.0.0:9092","upstream": "redis:6379"}]'

worldtiki avatar Apr 15 '18 15:04 worldtiki

Hey @worldtiki. Are you attempting to run Toxiproxy as a side car in a production Kubernetes cluster? If so, I would suggest extreme caution. Toxiproxy was not designed for production use and I have never heard of anyone running it in production environments.

Thanks for opening a PR. I don't have time to review this right now but will look at it later in the week.

jpittis avatar Apr 16 '18 02:04 jpittis

Hi @jpittis. Thanks for the feedback. This would be used in a staging/test environment, not in a production one.

worldtiki avatar Apr 16 '18 07:04 worldtiki

Did you find an alternative solution @worldtiki? If you did, would you mind briefly mentioning what it was?

jpittis avatar Apr 19 '18 21:04 jpittis

Hi Jake!

Yes and no. I managed to use Kubernetes config maps feature to pass the config file to Toxiproxy. Given that this would have been a breaking change (with the renaming of the config flags) and that there is (at least for kube) a workaround I decided to close the pr.

I did however got stuck again as the initial population seems to be populating proxies but ignoring the list of toxics. I don't know if this is expected behaviour or if I'm just doing something wrong (I never worked with Go before so I'm having a bit of a struggle to debug this)

worldtiki avatar Apr 20 '18 08:04 worldtiki

The correct behaviour is that initial population ignores toxics. There's an open issue. https://github.com/Shopify/toxiproxy/issues/79

jpittis avatar Apr 20 '18 15:04 jpittis

@worldtiki, Any chance to revive that? I like what you have done on your fork.

jpambrun avatar May 31 '18 14:05 jpambrun

However, I just noticed that the ability to update toxics through the api seems to be broken on your branch.

jpambrun avatar May 31 '18 14:05 jpambrun

Yeah, sorry about that @jpambrun :( I needed some extra features so I kinda butchered the project in that branch.

I'll reopen this pr (didn't know it could be of use for others). Regarding the initial population of toxics, it would be nice if someone else could give it a go, as my knowledge of go is very basic :s

worldtiki avatar May 31 '18 21:05 worldtiki

@jpambrun @worldtiki If you still want to use ToxiProxy with k8s, I come up with a solution that does not require code changes in ToxiProxy Here a story on Medium that details the approach http://bit.ly/2EAXRYk

Hope it helps!

marqub avatar Dec 18 '18 18:12 marqub

I would replace ability to load config via ENV variable instead. Currently I am not fully convinced to change the arguments.

ENV is good, that it is easy to use in kubernetes and docker compose. It could be stored in .env file.

miry avatar Nov 12 '21 16:11 miry

I would replace ability to load config via ENV variable instead. Currently I am not fully convinced to change the arguments.

ENV is good, that it is easy to use in kubernetes and docker compose. It could be stored in .env file.

Fair enough.

But just to confirm. This env var would be use to specify the name/path of a config file and not to explicitly pass the configs themselves right?

worldtiki avatar Nov 12 '21 17:11 worldtiki

@worldtiki I tried to find other command lines that uses ENV as full config or for complex one. I failed to find a good examples (kubectl, opentelemtry-collector, grafana, nginx). Learned about best practices in https://12factor.net/ and https://clig.dev/ also suggested to have simple ENVs.

If you can suggest some example command line, it would be helpful.

Max that we can do assign SINGLE ENV to SINGLE Flag. Similar to TOML or what provides current frameworks Viper or https://github.com/urfave/cli/.

As workaround for docker we can use entrypoint.sh that would generate config file base on ENVs.

Example: https://devopsian.net/notes/docker-nginx-template-env-vars/ or use http://mustache.github.io/mustache.5.html

P.S: During learning about config structure. I feel I need extract parse config out of models. I am going to change config structure to remove arrays of proxies with dictionary. So it would be easy to create new entries. Also support more other formats.

miry avatar Nov 12 '21 18:11 miry

Also thought to use flag --proxy and to specify attributes with "upastream=local:2,downstream=local,name=oops,enabled=true"

Also i think it is not unix way.

miry avatar Nov 12 '21 18:11 miry

@dianadevasia By renaming master -> main I think you unintentionally closed lots of PRs including this one, see: https://github.com/Shopify/toxiproxy/pulls?q=is%3Apr+is%3Aclosed+sort%3Aupdated-desc

(I think using the rename feature of GitHub would have prevented this.)

jonatan-ivanov avatar Apr 20 '23 22:04 jonatan-ivanov