Skip to content

cURL Examples

Prerequisites

You need to install:

  • curl to make HTTP calls,
  • jq a JSON command line processor.

Endpoints

Depending on the type of installation of Kraken, each endpoint is accessible at a different URL.

You can set environment variable to set them. The values depends on the environment you are running Kraken on:

Development

export KEYCLOAK_URL=http://kraken-local/auth
export BACKEND_URL=http://localhost:8080

Docker

export KEYCLOAK_URL=hhttp://kraken-local/auth
export BACKEND_URL=http://kraken-local/api

Kubernetes

export KEYCLOAK_URL=hhttp://cluster-ip/auth
export STORAGE_URL=http://cluster-ip/api

Authentication

Before making actual calls to Kraken's REST APIs you need to get an access token from KeyCloak.

Start by exporting your current credentials in environment variables:

export KRAKEN_LOGIN=login
export KRAKEN_PASSWORD=password

Note

In case you need to create an account, the login/register page is available at: $KEYCLOAK_URL/realms/kraken/login-actions/authenticate?client_id=account.

Then request an access token and save it to a file named token. This file will be reused to authenticate the current user for next REST API calls.

curl -s -X POST -H "Content-Type: application/x-www-form-urlencoded" \
        -d "username=$KRAKEN_LOGIN&password=$KRAKEN_PASSWORD&grant_type=password" \
        -d "client_id=kraken-web" \
        "$KEYCLOAK_URL/realms/kraken/protocol/openid-connect/token" \
        | jq -r '.access_token' > token

Warning

Your access token has a short lifespan. You may need to request another one if you start to get 401 errors from the servers.

Note

You can open the created token file to get your JWT token and copy it at https://jwt.io/ to see what information it stores.

Storage API

List Files

The following cURL command list all files managed by the Kraken Storage backend for:

  • the given user (defined by the token),
  • the given application (ApplicationId header)
curl -H "ApplicationId: gatling" \
     -H "Authorization: Bearer $(cat token)" \
     -X GET "$BACKEND_URL/files/list" \
     | jq

The response is a JSON array for storage nodes:

[
  {
    "path": "gatling",
    "type": "DIRECTORY",
    "depth": 0,
    "length": 4096,
    "lastModified": 1588841200119
  },
  {
    "path": "gatling/lib",
    "type": "DIRECTORY",
    "depth": 1,
    "length": 4096,
    "lastModified": 1588841200111
  },
  {
    "path": "gatling/lib/README.md",
    "type": "FILE",
    "depth": 2,
    "length": 28,
    "lastModified": 1588841200111
  },
  {
    "path": "gatling/README.md",
    "type": "FILE",
    "depth": 1,
    "length": 1255,
    "lastModified": 1588841200111
  },
  ...
]

Runtime API

List hosts

The following cURL command lists available hosts for the current user.

curl -H "ApplicationId: gatling" \
     -H "Authorization: Bearer $(cat token)" \
     -X GET "$BACKEND_URL/host/list" \
     | jq

This command returns a list of hosts. If you are running Kraken on Docker, only one local host is available:

[
  {
    "id": "local",
    "name": "local",
    "capacity": {
      "cpu": "-",
      "memory": "-"
    },
    "allocatable": {
      "cpu": "-",
      "memory": "-"
    },
    "addresses": [],
    "owner": {
      "userId": "eb274740-db1e-4c6c-8050-3f0e3073d487",
      "applicationId": "gatling",
      "roles": [
        "USER"
      ],
      "type": "USER"
    }
  }
]

Start a Task

Running a Load Test

The following cURL command starts a new load test.

curl -d '{"description": "description", "taskType": "GATLING_RUN", "hostIds": ["local"], "entries": [{"scope": "", "from": "USER", "key": "KRAKEN_GATLING_SIMULATION_NAME", "value": "computerdatabase.BasicSimulation"}, {"scope": "", "from": "USER", "key": "FOO", "value": "BAR"}]}' \
        -H "Content-Type: application/json" \
        -H "ApplicationId: gatling" \
        -H "Authorization: Bearer $(cat token)" \
        -X POST "$BACKEND_URL/task"

Note

The taskType field of the JSON sent to the server defines the type of task. You will use GATLING_DEBUG to debug a simulation script and GATLING_RECORD to convert a HAR file into a Gatling simulation.

The entries argument lets you specify environment variables for your script execution. Each entry has the following fields:

  • scope: the host ID or an empty string for a global entry,
  • from: always USER,
  • key: the environment variable key,
  • value: the environment variable value.

When running a load test, the KRAKEN_GATLING_SIMULATION_NAME is mandatory and must be set to the simulation package.class.

Debugging a Simutation

It's the same as running a load test, simply set the taskType to GATLING_RUN.

Note

Debugging can only be ran using a single host.

Warning

You should also configure your script to run only one iteration .inject(atOnceUsers(1) or it might generate too many debug entries.

Recording a HAR

Here you need to set the taskType to GATLING_RECORD but also specify other entries:

  • KRAKEN_GATLING_SIMULATION_PACKAGE_NAME: The generated simulation package,
  • KRAKEN_GATLING_SIMULATION_CLASS_NAME: The generated simulation Class,
  • KRAKEN_GATLING_HAR_PATH_REMOTE: The path of the HTTP archive in the storage backend.

Note

Recording can only be ran using a single host.