This page documents the structure of the HTTP API used by agents to communicate with the crater server.
The base URL for the Agent API is /agent-api/
.
All the requests to the Agent API are restricted to authenticated clients only.
Each agent should have its own unique API token. To authenticate you need to
provide the Authorization
HTTP header with the right token:
Authorization: CraterToken YOUR-AGENT-TOKEN
If authentication fails the API returns a 403 Unauthorized
status code.
Every valid endpoint of the Agent API returns a JSON payload as response. The payload contains the following keys:
status
: the type of the response; can beunauthorized
,success
,not-found
orinternal-error
(compatibility note: expect more types to be added in the future)result
: the result of the request (only available if the status issuccess
)error
: the error message (only available if the status isinternal-error
)
{
"status": "success",
"result": true
}
{
"status": "internal-error",
"error": "Something happened"
}
While any endpoint can be called at any time, Crater expects a proper agent to behave this way:
GET /config
should be called when the agent starts, and its results should be used as the configuration of the agentPOST /heartbeat
should be called when the agent starts and every minute, regardless of what the agent is doingGET /agent-api/next-experiment
should be called when the agent is waiting for a new experiment; the endpoint returnsnull
when there is no experiment available, so the agent should just call the endpoint again after a few secondsPOST /agent-api/record-progress
should be called as soon as a result is availablePOST /error
should be called only when the agent has encountered an error
All the endpoints return a JSON response with a 200 status code if the request succeded.
This endpoint registers the capabilities of this agent, and returns the generic configuration of this agent, assigned by the crater server. This method should be called at least at the start of the agent, and the response is tied to the API token.
The agent's capabilities must be specified as JSON in the request body. Prior
to the introduction of capabilities, this endpoint was accessed via a GET
instead of a POST
. A GET
to this endpoint will still register an agent, but
the request body will be ignored and a default set of capabilities used instead
(currently ["linux"]
).
Request fields:
capabilities
: an array containing the capabilities possessed by this agent.
{
"capabilities": ["windows", "hard-drive-bigger-than-1TB"]
}
Response fields:
agent-name
: the name assigned by the crater server to this agentcrater-config
: the JSON serialized content of the server'sconfig.toml
{
"status": "success",
"result": {
"agent-name": "crater-1",
"crater-config": {...}
}
}
This endpoint returns the next experiment this agent should run. The first time this method is called the first queued experiment with compatible requirements is assigned to the agent, and its configuration is returned. The same configuration is returned for all the following calls, until the agent sends the full experiment result to the crater server.
Response fields:
name
: the unique name assigned to this experimentcrates
: a list of all the crates part of this experimenttoolchains
: a list of the toolchains used in this experimentmode
: the experiment mode
{
"status": "success",
"result": {
"name": "experiment-1",
"crates": [
{
"Registry": {
"name":"lazy_static",
"version":"0.2.11"
}
},
{
"GitHub": {
"org": "brson",
"name": "hello-rs"
}
}
],
"toolchains": [
{
"Dist": "stable"
},
{
"Dist": "beta"
}
],
"mode": "BuildAndTest"
}
}
If there is no experiment, the result is null
:
{
"status": "success",
"result": null
}
This endpoint uploads the result of a single job run by the agent to the Crater server. The endpoint expects the following data to be provided as the request body, encoded in JSON:
-
experiment-name
: the name of the experiment being run -
results
: a list of job results that should be recorded:crate
: the serialized crate nametoolchain
: the serialized toolchain nameresult
: the result of the experiment (for exampleTestPass
)log
: the base64-encoded output of the job
-
shas
: a list of GitHub repo shas captured during the job; can be empty
For example, this is a valid request data:
{
"experiment-name": "pr-1",
"results": [
{
"crate": {
"GitHub": {
"org": "brson",
"repo": "hello-rs"
}
},
"toolchain": {
"Dist": "stable"
},
"result": "TestPass",
"log": "cGlhZGluYSByb21hZ25vbGE="
}
],
"shas": [
[
{
"org": "brson",
"name": "hello-rs"
},
"f45e5e3289dd46aaec8392134a12c019aca3d117"
]
]
}
The endpoint replies with true
.
{
"status": "success",
"result": true
}
This endpoint tells the Crater server the agent is still alive. The method should be called by the agent every minute, and after some time the method is not called the Crater server will mark the agent as unreachable.
The endpoint replies with true
.
{
"status": "success",
"result": true
}
This endpoint tells the Crater server the agent has encountered an error. The endpoint expects the error description to be provided as the request body, encoded in JSON:
experiment-name
: the name of the experiment being runerror
: a description of the error
For example, this is a valid request data:
{
"experiment-name": "pr-1",
"error": "pc is not powered on"
}
The endpoint replies with true
.
{
"status": "success",
"result": true
}