Skip to main content

Chaos Toolkit Extension for Istio Fault Injection

Project description

Chaos Toolkit Extension for Istio Fault Injection

Build Python versions

This project is a collection of actions and probes, gathered as an extension to the Chaos Toolkit.

Install

This package requires Python 3.8+

To be used from your experiment, this package must be installed in the Python environment where chaostoolkit already lives.

$ pip install -U chaostoolkit-istio

Usage

Below is an example of using this extension to inject a delay of 5 seconds to a specific user.

Note this example can be applied against the bookinfo Istio sample application.

To run it, simple set the KUBERNETES_CONTEXT environment variable to the target cluster and ensure your local kubeconfig is properly populated for that context. Set also the PRODUCT_PAGE_SERVICE_BASE_URL to the address of the Istio gateway.

For instance:

$ export PRODUCT_PAGE_SERVICE_BASE_URL=$(kubectl get po -l istio=ingressgateway -n istio-system -o 'jsonpath={.items[0].status.hostIP}'):$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')
{
    "title": "Network latency does not impact our users",
    "description": "Using Istio fault injection capability, let's explore how latency impacts a single user",
    "configuration": {
        "product_page_url": {
            "type": "env",
            "key": "PRODUCT_PAGE_SERVICE_BASE_URL"
        }
    },
    "secrets": {
        "istio": {
            "KUBERNETES_CONTEXT": {
                "type": "env",
                "key": "KUBERNETES_CONTEXT"
            }
        }
    },
    "steady-state-hypothesis": {
        "title": "Our service should respond under 1 second",
        "probes": [
            {
                "type": "probe",
                "name": "sign-in-as-jason",
                "tolerance": 0,
                "provider": {
                    "type": "process",
                    "path": "curl",
                    "arguments": "-v -X POST -d 'username=jason&passwd=' -c /tmp/cookie.txt --silent ${product_page_url}/login"
                }
            },
            {
                "type": "probe",
                "name": "fetch-productpage-for-jason-in-due-time",
                "tolerance": 0,
                "provider": {
                    "type": "process",
                    "path": "curl",
                    "arguments": "-v --connect-timeout 1 --max-time 1 -b /tmp/cookie.txt --silent ${product_page_url}/productpage"
                }
            }
        ]
    },
    "method": [
        {
            "type": "action",
            "name": "inject-fault-for-jason-only",
            "provider": {
                "type": "python",
                "module": "chaosistio.fault.actions",
                "func": "add_delay_fault",
                "secrets": ["istio"],
                "arguments": {
                    "virtual_service_name": "reviews",
                    "fixed_delay": "5s",
                    "percentage": {
                        "value":  100.0
                    },
                    "routes": [
                        {
                            "destination": {
                                "host": "reviews",
                                "subset": "v2"
                            }
                        }
                    ]
                }
            },
            "pauses": {
                "after": 2
            }
        }
    ],
    "rollbacks": [
        {
            "type": "action",
            "name": "remove-fault-for-jason-only",
            "provider": {
                "type": "python",
                "module": "chaosistio.fault.actions",
                "func": "remove_delay_fault",
                "secrets": ["istio"],
                "arguments": {
                    "virtual_service_name": "reviews",
                    "routes": [
                        {
                            "destination": {
                                "host": "reviews",
                                "subset": "v2"
                            }
                        }
                    ]
                }
            }
        }
    ]
}

That's it!

Please explore the code to see existing probes and actions.

Configuration

This extension needs you specify how to connect to the Kubernetes cluster. This can be done by setting the KUBERNETES_CONTEXT in the secrets payload.

Contribute

If you wish to contribute more functions to this package, you are more than welcome to do so. Please, fork this project, make your changes following the usual PEP 8 code style, sprinkling with tests and submit a PR for review.

The Chaos Toolkit projects require all contributors must sign a Developer Certificate of Origin on each commit they would like to merge into the master branch of the repository. Please, make sure you can abide by the rules of the DCO before submitting a PR.

Develop

If you wish to develop on this project, make sure to install the development dependencies, using pdm:

$ pdm install --dev

Now, you can edit the files and they will be automatically be seen by your environment, even when running from the chaos command locally.

Test

To run the tests for the project execute the following:

$ pdm run test

Formatting and Linting

We use ruff to both lint and format this repositories code.

Before raising a Pull Request, we recommend you run formatting against your code with:

$ pdm run format

This will automatically format any code that doesn't adhere to the formatting standards.

As some things are not picked up by the formatting, we also recommend you run:

$ pdm run lint

To ensure that any unused import statements/strings that are too long, etc. are also picked up.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chaostoolkit_istio-0.4.1.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

chaostoolkit_istio-0.4.1-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file chaostoolkit_istio-0.4.1.tar.gz.

File metadata

  • Download URL: chaostoolkit_istio-0.4.1.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for chaostoolkit_istio-0.4.1.tar.gz
Algorithm Hash digest
SHA256 d9ae7e1eaa0a264c0a09fbfddd49761ca300a78b7b0dbef82570f0e1ccde3015
MD5 e8ac85978f083cc30150e88bd35f9adf
BLAKE2b-256 2426db8378ebeecf0f3ec7b9c610bed186d198b4d6fac1ee153b6b4a7c3b2523

See more details on using hashes here.

File details

Details for the file chaostoolkit_istio-0.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for chaostoolkit_istio-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 32019990151b94f9636e552798e8dfe7ef5efd7fd4eadd86a7d7c2a2c0046cab
MD5 cc890438840705e7340cd990d8fa880e
BLAKE2b-256 231fa2c92bd7c13d9aa12d5be0a6587919d54ae3b8fbcc2a1135066622799ded

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page