{"id":17954102,"url":"https://github.com/uditgaurav/hce-api-template","last_synced_at":"2025-07-12T19:35:42.396Z","repository":{"id":65312150,"uuid":"522156197","full_name":"uditgaurav/hce-api-template","owner":"uditgaurav","description":null,"archived":false,"fork":false,"pushed_at":"2023-09-05T07:06:04.000Z","size":4359,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-09T05:21:08.524Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uditgaurav.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-07T08:23:44.000Z","updated_at":"2023-01-31T20:10:08.000Z","dependencies_parsed_at":"2024-06-20T21:51:12.862Z","dependency_job_id":"27a50c56-84ec-4d96-b71f-60b4193c9ba5","html_url":"https://github.com/uditgaurav/hce-api-template","commit_stats":{"total_commits":106,"total_committers":3,"mean_commits":"35.333333333333336","dds":0.07547169811320753,"last_synced_commit":"4d52f949940af3c5e12da8eed9a287c03c6238e7"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uditgaurav%2Fhce-api-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uditgaurav%2Fhce-api-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uditgaurav%2Fhce-api-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uditgaurav%2Fhce-api-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uditgaurav","download_url":"https://codeload.github.com/uditgaurav/hce-api-template/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247037374,"owners_count":20873146,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-29T10:10:04.138Z","updated_at":"2025-04-03T16:33:44.100Z","avatar_url":"https://github.com/uditgaurav.png","language":"Go","readme":"# API Template For Automation\n\nWelcome to HCE's GraphQL API template documentation\n\nThis contains the API templates to perform a chaos experiment in an automated way.\n\n## Table Of Content\n\n1. [API to Launch Chaos Experiment](https://uditgaurav.github.io/hce-api-template//#api-to-launch-chaos-experiment)\n2. [API to Monitor Chaos Experiment](https://uditgaurav.github.io/hce-api-template//#api-to-monitor-chaos-experiment)\n3. [API to Validate Resilience Score](https://uditgaurav.github.io/hce-api-template//#api-to-validate-resilience-score)\n\n## Pre-requisites\n\n- **Installed HCE**: You should have an HCE installed from where you can prepare and run experiments from API calls.\n\n- **Prepare Workflow**: We can run a workflow using APIs in any automated pipeline but for that, we need to pre-create a workflow with the right tunables and attributes from HCE. This step will involve:\n  - Select the right set of experiments you want to include in the workflow\n  - Provide desired tunables in the experiment. At any point in time, you can change the tunables and save it - this won't impact the overall API calls, infact this is correct method to update the tunables of the pre-created experiment for new runs.\n\n- **Install 'jq'**: Make sure you have `jq` installed in your system if not, please install it as it is used in some APIs to filter path.\n\n- **Derive Tunables**: To derive tunables for preparing API commands [check here](https://uditgaurav.github.io/hce-api-template//#derive-tunables).\n\n- **Download 'hce-api' binary**: \n  - Follow the below-mentioned steps to install 'hce-api' binary. It will be used to prepare the API commands based on the provided tunables.\n\n  - Download `hce-api` binary using this command, and replace `\u003cOS\u003e` and `\u003cACRH\u003e` placeholder with your operating system (supports `linux` and `darwin`) and system arch (supports `amd64` and `arm64`).\n\n    ```bash\n    wget https://github.com/uditgaurav/hce-api-template/releases/download/0.1.0/hce-api-\u003cOS\u003e-\u003cARCH\u003e -O hce-api\n    chmod +x hce-api\n    ```\n\n    If you have don't have `wget` then you can also use `curl` command:\n\n    ```bash\n    curl -L https://github.com/uditgaurav/hce-api-template/releases/download/0.1.0/hce-api-\u003cOS\u003e-\u003cARCH\u003e -o hce-api\n    chmod +x hce-api\n    ```\n\n## Derive Tunables\n\n- Derive the tunables for API calls. Login to your HCE dashboard.\n\n### Looking for details on ACCESS_KEY and ACCESS_ID?\n\n- On the HCE dashboard click on \"Settings\" and switch to the \"Access Key\" tab.\n\nYou will get this screen:\n\n![settings-image](https://user-images.githubusercontent.com/35391335/212264846-3ea0401c-5ab7-4da5-bdb6-8559e1cb9712.png)\n\n- Click on \"Create Access Key\" if you have lost the older one\n\n### Looking for details on PROJECT_ID and WORKFLOW_ID?\n\nFor Project ID:\n\n- On the HCE dashboard click on \"Project\" (as shown in point-1 on the image) and copy the \"Project ID\". You can also get the project ID from the HCE URL at this place.\n\nCheckout this screen:\n\n![projectid-img](https://user-images.githubusercontent.com/35391335/212269753-9023352a-cf21-49df-9097-de4c23ae3766.png)\n\nFor Workflow ID:\n\n- Click on \"three dots\" on the workflow and Navigate to the \"View Manifest\" option. You will get a screen like this:\n\n![workflow-id-img](https://user-images.githubusercontent.com/35391335/212271135-b1e7999e-4c12-409c-80a0-0978610aacbb.png)\n\nIt will give you the workflow id for the target workflow.\n\n## API to Launch Chaos Experiment\n\nThis contains the API to trigger the Chaos Experiment.\n\n### Tunables \n- `ACCESS_KEY`\n- `ACCESS_ID`\n- `PROJECT_ID`\n- `WORKFLOW_ID`\n- `HCE_ENDPOINT`\n\nThe above tunables are mandatory to provide. You need to replace it in the given API call.\n\n- Before getting started checkout the [pre-requisite](https://uditgaurav.github.io/hce-api-template//#pre-requisite) section and follow the steps to download `hce-api` binary.\n\n**Non-Interactive Mode:**\n\n- Provide the values in the flags given below to get the API command in a file.\n\n```bash\n./hce-api generate --api launch-experiment --hce-endpoint=\u003cHCE-ENDPOINT\u003e \\\n--project-id \u003cPROJECT-ID\u003e --workflow-id \u003cWORKFLOW-ID\u003e \\\n--access-key \u003cACCESS-KEY\u003e --access-id \u003cACCESS-ID\u003e --file-name \u003cFILE-NAME\u003e\n```\n\nExample:\n\n```bash\n./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\n```\n\nThe default value for `--file-name` is `hce-api.sh`, all other variables are mandatory.\n\n**Interactive Mode:**\n\n- Run the downloaded `hce-api` binary as shown below. It will not trigger the chaos but will prepare the launch command in a file:\n\n\n```bash\n$ ./hce-api\n\n\nProvide the index number to create a file with the API command from the given options.\nFor Example to create an API that launches an experiment give 1 as input.\n\n[1] API to Launch Chaos Experiment\n[2] API to Monitor Chaos Experiment\n[3] API to Validate Resilience Score\n\t\n\t\t\nSelect from the given options: 1\nProvide the HCE endpoint: http://ae1a8f465611b4c07bbbc2e7d669f533-1139615104.us-east-2.elb.amazonaws.com:9091/\nProvide the Project ID: abceb5f4-4268-4467-9818-ad6e3b6bfd78\nProvide the Workflow ID: f4581780-efaf-4155-956e-6c379f24394b\nProvide the HCE Access Key: nEdGNDDrTFHyCnl\nProvide the HCE Access ID: adminNCWQu\nProvide the File Name for API [Default is hce-api.sh]: hce-api.sh\n```\n\nOutput:\n\n```bash\nThe file containing the API command is created successfully\n```\n\n- Check out the file `hce-api.sh` and get the launch command. To run the API execute `bash hce-api.sh` (replace file name for custom names).\n\n## API to Monitor Chaos Experiment\n\nThis contains the API to monitor the Chaos Experiment that is this API will help us to wait for the workflow completion.\n\n### Tunables \n\n- `ACCESS_KEY`\n- `ACCESS_ID`\n- `PROJECT_ID`\n- `WORKFLOW_ID`\n- `HCE_ENDPOINT`\n\n- Before getting started checkout the [pre-requisite](https://uditgaurav.github.io/hce-api-template//#pre-requisite) section and follow the steps to download `hce-api` binary.\n\n**Non-Interactive Mode:**\n\n- Provide the values in the flags given below to get the API command in a file.\n\n```bash\n./hce-api generate --api monitor-experiment --hce-endpoint=\u003cHCE-ENDPOINT\u003e \\\n--project-id \u003cPROJECT-ID\u003e --workflow-id \u003cWORKFLOW-ID\u003e \\\n--access-key \u003cACCESS-KEY\u003e --access-id \u003cACCESS-ID\u003e --file-name \u003cFILE-NAME\u003e\n```\n\nExample:\n\n```bash\n./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\n```\n\nThe default value for `--file-name` is `hce-api.sh`, all other variables are mandatory. \n\n**Interactive Mode:**\n\n- Run the downloaded `hce-api` binary as shown below. It will not trigger the command but will prepare the monitor command in a given file:\n\n\n```bash\n$ ./hce-api\n\n\nProvide the index number to create a file with the API command from the given options.\nFor Example to create an API that launches an experiment give 1 as input.\n\n[1] API to Launch Chaos Experiment\n[2] API to Monitor Chaos Experiment\n[3] API to Validate Resilience Score\n\t\n\t\t\nSelect from the given options: 2\nProvide the HCE endpoint: http://ae1a8f465611b4c07bbbc2e7d669f533-1139615104.us-east-2.elb.amazonaws.com:9091/\nProvide the Project ID: abceb5f4-4268-4467-9818-ad6e3b6bfd78\nProvide the Workflow ID: f4581780-efaf-4155-956e-6c379f24394b\nProvide the HCE Access Key: nEdGNDDrTFHyCnl\nProvide the HCE Access ID: adminNCWQu\nProvide the File Name for API [Default is hce-api.sh]: hce-api.sh\n```\n\nOutput:\n\n```bash\nThe file containing the API command is created successfully\n```\n\n- Check out the file `hce-api.sh` and get the chaos monitor command. To run the API run `bash hce-api.sh` (replace file name for custom names).\n\n#### A sample bash script to monitor Chaos Experiment\n\n- In this sample script we will wait for the workflow completion with a delay of 2 seconds and 150 retries, you can adjust these values based on total chaos duration.\n\n```bash\n#!/bin/bash\n\nset -e\n\n# Tunables provide your values\nDELAY=2\nRETRY=150\nfileName=\"hce-api.sh\"\n\n# Script execution logic\nSTART=0\nfor (( i=$START; i\u003c=$RETRY; i++ )); do\n    echo\n    res=$(sh $fileName)\n    echo\n    if [ \"$res\" == \"Succeeded\" ]; then\n        echo \"Experiment completed, CurrentState: $res\"\n        exit 0\n    fi\n    sleep $DELAY\n    echo \"Waiting for experiment completion... CurrentState: $res, retries left: $(($RETRY-$i))\"\ndone\n\necho \"[Error]: Timeout the workflows is not completed with DELAY: $DELAY and RETRY: $RETRY, CurrentState: $res\"\n\nexit 1\n```\n\n## API to Validate Resilience Score\n\nThis contains the API to get the resilience score for a workflow run and validate against the expected probe success percentage.\n\n### Tunables \n\n- `ACCESS_KEY`\n- `ACCESS_ID`\n- `PROJECT_ID`\n- `WORKFLOW_ID`\n- `HCE_ENDPOINT`\n\n- Before getting started checkout the [pre-requisite](https://uditgaurav.github.io/hce-api-template//#pre-requisite) section and follow the steps to download `hce-api` binary.\n\n**Non-Interactive Mode:**\n\n- Provide the values in the flags given below to get the API command in a file.\n\n```bash\n./hce-api generate --api validate-resilience-score --hce-endpoint=\u003cHCE-ENDPOINT\u003e \\\n--project-id \u003cPROJECT-ID\u003e --workflow-id \u003cWORKFLOW-ID\u003e \\\n--access-key \u003cACCESS-KEY\u003e --access-id \u003cACCESS-ID\u003e --file-name \u003cFILE-NAME\u003e\n```\n\nExample:\n\n```bash\n./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\n```\n\nThe default value for `--file-name` is `hce-api.sh`, all other variables are mandatory.\n\n**Interactive Mode:**\n\n- Run the downloaded `hce-api` binary as shown below. It will not trigger the command but will prepare the monitor command in a given file:\n\n```bash\n$ ./hce-api\n\n\nProvide the index number to create a file with the API command from the given options.\nFor Example to create an API that launches an experiment give 1 as input.\n\n[1] API to Launch Chaos Experiment\n[2] API to Monitor Chaos Experiment\n[3] API to Validate Resilience Score\n\t\n\t\t\nSelect from the given options: 2\nProvide the HCE endpoint: http://ae1a8f465611b4c07bbbc2e7d669f533-1139615104.us-east-2.elb.amazonaws.com:9091/\nProvide the Project ID: abceb5f4-4268-4467-9818-ad6e3b6bfd78\nProvide the Workflow ID: f4581780-efaf-4155-956e-6c379f24394b\nProvide the HCE Access Key: nEdGNDDrTFHyCnl\nProvide the HCE Access ID: adminNCWQu\nProvide the File Name for API [Default is hce-api.sh]: hce-api.sh\n```\n\nOutput:\n\n```bash\nThe file containing the API command is created successfully\n```\n\n- Check out the file `hce-api.sh` and get the validate-resilience-score command. To run the API run `bash hce-api.sh` (replace file name for custom names).\n\n#### A sample bash script to validate the resiliency score\n\n- In this sample script you will get the probe success percentage for the last workflow run, you can make use of it to compare it with the expected probe success percentage.\n\n```bash\n#!/bin/bash\n\nset -e\n\n# Tunables provide your values\nexpectedProbeSuccessPercentage=100\nfileName=\"hce-api.sh\"\n\n# Script execution logic\nres=$(bash $fileName)\nres=$(echo \"$res\" | tr -d '\"')\necho\nif [ \"$res\" != \"$expectedProbeSuccessPercentage\" ]; then\n    echo \"The probe success percentage is: $res, expected probe success percentage: $expectedProbeSuccessPercentage\"\n    exit 1\nfi\n\necho \"The probe success percentage is equal to the expected probe success percentage\"\nexit 0\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuditgaurav%2Fhce-api-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuditgaurav%2Fhce-api-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuditgaurav%2Fhce-api-template/lists"}