Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a toxic for an existent proxy gives an exception #15

Open
joaoasrosa opened this issue Oct 21, 2019 · 7 comments
Open

Creating a toxic for an existent proxy gives an exception #15

joaoasrosa opened this issue Oct 21, 2019 · 7 comments

Comments

@joaoasrosa
Copy link

Issue
I'm trying to add an experiment to the catalogue. The idea is to use toxiproxy, and proxy the calls to a mysql database. With that, I can control the type of faults that would be injected,
The environment is on AWS: toxiproxy in a ubuntu machine, and mysql in a rds instance. The app is .net core (not relevant) and exposes a REST API.

The experiment verifies the steady-state (one of the API endpoints) and then creates a toxic. The proxy is already created, due to the fact that the app needs to connect to it.
However, when trying to create the toxic, there is an error:

[2019-10-21 09:47:38 ERROR] [toxiproxyapi:68] Unable to create toxic for proxy: mysql

Digging into that, I used postman to post the same payload to the endpoint. The payload generated by the chaostollokit extensions:

[2019-10-21 09:47:38 INFO] [actions:39] Creating toxy mysql-latency for proxy mysql with type: latency as a downstream with toxicity 1.0 and attributes {'latency': '1234', 'jitter': '89'}

Extracting the full payload (on my environment added a line to output the json), looks like this:

[2019-10-21 09:47:38 DEBUG] [actions:46] json format for toxy creation: {'name': 'mysql-latency', 'type': 'latency', 'stream': 'downstream', 'toxicity': 1.0, 'attributes': {'latency': '1234', 'jitter': '89'}}

Using the same payload on postman, I get the full error:

{"error":"bad request body: json: cannot unmarshal string into Go struct field LatencyToxic.latency of type int64","status":400}

Although the attributes are of type int (from what I got in the code), when parsed to json transforms into string. Toxiproxy is picky with the types.

Environment

  • Toxiproxy
    • Version: 2.1.4
    • OS: Ubuntu
  • Chaostoolkit
    • Version 1.3.0
    • OS: Cataliana 10.15
@dimzak
Copy link
Contributor

dimzak commented Oct 21, 2019

Hi @joaoasrosa!
Can you try the same experiment without the single quotes in latency and maybe in jitter too like:

{
  latency:1234, 
  jitter:89
}

If issue still persists, can you also add here the method used to create above toxic?

@joaoasrosa
Copy link
Author

The snippet of the experiment looks like:

"method": [
        {
            "name": "create_latency_toxic",
            "provider": {
                "arguments": {
                    "for_proxy": "${toxiproxy_proxy_name}",
                    "toxic_name": "${toxiproxy_proxy_name}-latency",
                    "latency": "${toxiproxy_toxic_latency}",
                    "jitter": "${toxiproxy_toxic_jitter}"
                },
                "func": "create_latency_toxic",
                "module": "chaostoxi.toxic.actions",
                "type": "python"
            },
            "type": "action",
            "pauses": {
                "after": 1
            }
        },

The parameters came from the environment variables. I will do an experiment with hardcoded values to check the result.

@joaoasrosa
Copy link
Author

Using hardcore parameters in the method:

"method": [
        {
            "name": "create_latency_toxic",
            "provider": {
                "arguments": {
                    "for_proxy": "${toxiproxy_proxy_name}",
                    "toxic_name": "${toxiproxy_proxy_name}-latency",
                    "latency": 1200,
                    "jitter": 100
                },
                "func": "create_latency_toxic",
                "module": "chaostoxi.toxic.actions",
                "type": "python"
            },
            "type": "action",
            "pauses": {
                "after": 1
            }
        },

The toxic is created, and the chaos experiment contiue the execution.

@Lawouach
Copy link
Contributor

Unfortunately, one of the limitation of parametrization is that it will always render as a string a variable. Maybe this be considereda bug in the toolkit?

@joaoasrosa
Copy link
Author

I'm happy to follow that path. An interesting observation from the code (I'm not a Python expert):

def create_latency_toxic(for_proxy: str, toxic_name: str, latency: int,
                         jitter: int = 0,
                         configuration: Configuration = None) -> Dict[str, Any]:
    """
    Add a delay to all data going through the proxy using a downstream
    with a toxicity of 100%.
    """
    attributes = {
        "latency": latency,
        "jitter": jitter
    }
    return create_toxic(for_proxy=for_proxy, toxic_name=toxic_name,
                        toxic_type='latency', attributes=attributes,
                        configuration=configuration)

The function parameters are defined as int. From that, it's a dictionary of string, Any.

@dimzak
Copy link
Contributor

dimzak commented Oct 22, 2019

@Lawouach do you think this issue should be addressed in chaostoolkit repo as it might bite other extensions too?

@Lawouach
Copy link
Contributor

Yes, definitely!

Here it is :) chaostoolkit/chaostoolkit-lib#137

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants