Signaling to Krkn

Signal to stop/start/pause krkn

This functionality allows a user to be able to pause or stop the Krkn run at any time no matter the number of iterations or daemon_mode set in the config.

If publish_kraken_status is set to True in the config, Krkn will start up a connection to a url at a certain port to decide if it should continue running.

By default, Krkn binds the signal server to 0.0.0.0:8081. From the local host, clients should connect to http://127.0.0.1:8081.

An example use case for this feature would be coordinating Krkn runs based on the status of the service installation or load on the cluster.

States

There are 3 states in the Krkn status:

PAUSE: When the Krkn signal is ‘PAUSE’, this will pause the Krkn test and wait for the wait_duration until the signal returns to RUN.

STOP: When the Krkn signal is ‘STOP’, end the Krkn run and print out report.

RUN: When the Krkn signal is ‘RUN’, continue Krkn run based on iterations.

API Reference

When publish_kraken_status is enabled, Krkn runs an HTTP server at the configured signal_address and port (default http://0.0.0.0:8081).

EndpointMethodDescription
/GETReturns the current signal status (RUN, PAUSE, or STOP)
/STOPPOSTSets status to STOP — terminates the run
/PAUSEPOSTSets status to PAUSE — pauses between scenarios
/RUNPOSTSets status to RUN — resumes execution

Check Status

curl http://127.0.0.1:8081/
# Returns: RUN

The response is a plain text string: RUN, PAUSE, or STOP.

Configuration

In the config you need to set these parameters to tell Krkn which port to post the Krkn run status to. As well if you want to publish and stop running based on the Krkn status or not. The signal is set to RUN by default, meaning it will continue to run the scenarios. It can set to PAUSE for Krkn to act as listener and wait until set to RUN before injecting chaos.

    port: 8081
    publish_kraken_status: True
    signal_state: RUN
    signal_address: 0.0.0.0

Setting Signal

You can reset the Krkn status during Krkn execution with a set_stop_signal.py script with the following contents:

import http.client as cli

conn = cli.HTTPConnection("127.0.0.1", "<port>")

conn.request("POST", "/STOP", {})

# conn.request('POST', '/PAUSE', {})

# conn.request('POST', '/RUN', {})

response = conn.getresponse()
print(response.read().decode())

Make sure to set the correct port number in your set_stop_signal script.

Url Examples

To stop run:

curl -X POST http://127.0.0.1:8081/STOP

To pause run:

curl -X POST http://127.0.0.1:8081/PAUSE

To start running again:

curl -X POST http://127.0.0.1:8081/RUN