hce-api-template

This project is maintained by uditgaurav

API Template For Automation

Welcome to HCE’s GraphQL API template documentation

This contains the API templates to perform a chaos experiment in an automated way.

Table Of Content

  1. API to Launch Chaos Experiment
  2. API to Monitor Chaos Experiment
  3. API to Validate Resilience Score

Pre-requisites

Derive Tunables

Looking for details on ACCESS_KEY and ACCESS_ID?

You will get this screen:

settings-image

Looking for details on PROJECT_ID and WORKFLOW_ID?

For Project ID:

Checkout this screen:

projectid-img

For Workflow ID:

workflow-id-img

It will give you the workflow id for the target workflow.

API to Launch Chaos Experiment

This contains the API to trigger the Chaos Experiment.

Tunables

The above tunables are mandatory to provide. You need to replace it in the given API call.

Non-Interactive Mode:

./hce-api generate --api launch-experiment --hce-endpoint=<HCE-ENDPOINT> \
--project-id <PROJECT-ID> --workflow-id <WORKFLOW-ID> \
--access-key <ACCESS-KEY> --access-id <ACCESS-ID> --file-name <FILE-NAME>

Example:

./hce-api generate --api launch-experiment --hce-endpoint=http://ae1a8f465611b4c07bbbc2e7d669f533-1139615104.us-east-2.elb.amazonaws.com:9091/ --project-id abceb5f4-4268-4467-9818-ad6e3b6bfd78 --workflow-id f4581780-efaf-4155-956e-6c379f24394b --access-key nEdGNDDrTFHyCnl --access-id adminNCWQu --file-name hce-api.sh

The default value for --file-name is hce-api.sh, all other variables are mandatory.

Interactive Mode:

$ ./hce-api


Provide the index number to create a file with the API command from the given options.
For Example to create an API that launches an experiment give 1 as input.

[1] API to Launch Chaos Experiment
[2] API to Monitor Chaos Experiment
[3] API to Validate Resilience Score
	
		
Select from the given options: 1
Provide the HCE endpoint: http://ae1a8f465611b4c07bbbc2e7d669f533-1139615104.us-east-2.elb.amazonaws.com:9091/
Provide the Project ID: abceb5f4-4268-4467-9818-ad6e3b6bfd78
Provide the Workflow ID: f4581780-efaf-4155-956e-6c379f24394b
Provide the HCE Access Key: nEdGNDDrTFHyCnl
Provide the HCE Access ID: adminNCWQu
Provide the File Name for API [Default is hce-api.sh]: hce-api.sh

Output:

The file containing the API command is created successfully

API to Monitor Chaos Experiment

This contains the API to monitor the Chaos Experiment that is this API will help us to wait for the workflow completion.

Tunables

Non-Interactive Mode:

./hce-api generate --api monitor-experiment --hce-endpoint=<HCE-ENDPOINT> \
--project-id <PROJECT-ID> --workflow-id <WORKFLOW-ID> \
--access-key <ACCESS-KEY> --access-id <ACCESS-ID> --file-name <FILE-NAME>

Example:

./hce-api generate --api monitor-experiment --hce-endpoint=http://ae1a8f465611b4c07bbbc2e7d669f533-1139615104.us-east-2.elb.amazonaws.com:9091/ --project-id abceb5f4-4268-4467-9818-ad6e3b6bfd78 --workflow-id f4581780-efaf-4155-956e-6c379f24394b --access-key nEdGNDDrTFHyCnl --access-id adminNCWQu --file-name hce-api.sh

The default value for --file-name is hce-api.sh, all other variables are mandatory.

Interactive Mode:

$ ./hce-api


Provide the index number to create a file with the API command from the given options.
For Example to create an API that launches an experiment give 1 as input.

[1] API to Launch Chaos Experiment
[2] API to Monitor Chaos Experiment
[3] API to Validate Resilience Score
	
		
Select from the given options: 2
Provide the HCE endpoint: http://ae1a8f465611b4c07bbbc2e7d669f533-1139615104.us-east-2.elb.amazonaws.com:9091/
Provide the Project ID: abceb5f4-4268-4467-9818-ad6e3b6bfd78
Provide the Workflow ID: f4581780-efaf-4155-956e-6c379f24394b
Provide the HCE Access Key: nEdGNDDrTFHyCnl
Provide the HCE Access ID: adminNCWQu
Provide the File Name for API [Default is hce-api.sh]: hce-api.sh

Output:

The file containing the API command is created successfully

A sample bash script to monitor Chaos Experiment

#!/bin/bash

set -e

# Tunables provide your values
DELAY=2
RETRY=150
fileName="hce-api.sh"

# Script execution logic
START=0
for (( i=$START; i<=$RETRY; i++ )); do
    echo
    res=$(sh $fileName)
    echo
    if [ "$res" == "Succeeded" ]; then
        echo "Experiment completed, CurrentState: $res"
        exit 0
    fi
    sleep $DELAY
    echo "Waiting for experiment completion... CurrentState: $res, retries left: $(($RETRY-$i))"
done

echo "[Error]: Timeout the workflows is not completed with DELAY: $DELAY and RETRY: $RETRY, CurrentState: $res"

exit 1

API to Validate Resilience Score

This contains the API to get the resilience score for a workflow run and validate against the expected probe success percentage.

Tunables

Non-Interactive Mode:

./hce-api generate --api validate-resilience-score --hce-endpoint=<HCE-ENDPOINT> \
--project-id <PROJECT-ID> --workflow-id <WORKFLOW-ID> \
--access-key <ACCESS-KEY> --access-id <ACCESS-ID> --file-name <FILE-NAME>

Example:

./hce-api generate --api validate-resilience-score --hce-endpoint=http://ae1a8f465611b4c07bbbc2e7d669f533-1139615104.us-east-2.elb.amazonaws.com:9091/ --project-id abceb5f4-4268-4467-9818-ad6e3b6bfd78 --workflow-id f4581780-efaf-4155-956e-6c379f24394b --access-key nEdGNDDrTFHyCnl --access-id adminNCWQu --file-name hce-api.sh

The default value for --file-name is hce-api.sh, all other variables are mandatory.

Interactive Mode:

$ ./hce-api


Provide the index number to create a file with the API command from the given options.
For Example to create an API that launches an experiment give 1 as input.

[1] API to Launch Chaos Experiment
[2] API to Monitor Chaos Experiment
[3] API to Validate Resilience Score
	
		
Select from the given options: 2
Provide the HCE endpoint: http://ae1a8f465611b4c07bbbc2e7d669f533-1139615104.us-east-2.elb.amazonaws.com:9091/
Provide the Project ID: abceb5f4-4268-4467-9818-ad6e3b6bfd78
Provide the Workflow ID: f4581780-efaf-4155-956e-6c379f24394b
Provide the HCE Access Key: nEdGNDDrTFHyCnl
Provide the HCE Access ID: adminNCWQu
Provide the File Name for API [Default is hce-api.sh]: hce-api.sh

Output:

The file containing the API command is created successfully

A sample bash script to validate the resiliency score

#!/bin/bash

set -e

# Tunables provide your values
expectedProbeSuccessPercentage=100
fileName="hce-api.sh"

# Script execution logic
res=$(bash $fileName)
res=$(echo "$res" | tr -d '"')
echo
if [ "$res" != "$expectedProbeSuccessPercentage" ]; then
    echo "The probe success percentage is: $res, expected probe success percentage: $expectedProbeSuccessPercentage"
    exit 1
fi

echo "The probe success percentage is equal to the expected probe success percentage"
exit 0