Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,13 @@ reporting:
repo_url: https://example.org/project.git
project_name: Some Project that Wants Good Performance
record_all: true
api_token: your-api-token-here
```

The `api_token` is obtained from the ReBenchDB admin UI by clicking
"Generate My API Token". The full token is shown only once, at generation
time — copy it immediately.

---

## Machines
Expand Down
3 changes: 2 additions & 1 deletion rebench/configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ def get_rebench_db_connector(self):

self._rebench_db_connector = ReBenchDB(
self.rebench_db['db_url'], self.rebench_db['project_name'],
self.options.experiment_name, self.ui)
self.options.experiment_name, self.ui,
self.rebench_db.get('api_token'))
return self._rebench_db_connector

def _process_cli_options(self):
Expand Down
3 changes: 3 additions & 0 deletions rebench/rebench-schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ schema;reporting_type:
record_all:
type: bool
desc: All experiments should be stored in the ReBenchDB
api_token:
type: str
desc: API token for authenticating with ReBenchDB.
codespeed:
type: map
desc: Send results to Codespeed for continuous performance tracking.
Expand Down
27 changes: 26 additions & 1 deletion rebench/rebenchdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from time import sleep

from http.client import HTTPException
from urllib.error import HTTPError
from urllib.request import urlopen, Request as HttpRequest

from .output import UIError
Expand All @@ -27,7 +28,7 @@ def get_current_time():

class ReBenchDB(object):

def __init__(self, server_base_url, project_name, experiment_name, ui):
def __init__(self, server_base_url, project_name, experiment_name, ui, api_token=None):
self.ui = ui

if not server_base_url:
Expand All @@ -45,6 +46,7 @@ def __init__(self, server_base_url, project_name, experiment_name, ui):
self._server_base_url = server_base_url
self._project_name = project_name
self._experiment_name = experiment_name
self._api_token = api_token
self._api_v2 = None

def is_api_v2(self):
Expand Down Expand Up @@ -109,6 +111,8 @@ def convert_data_to_json(self, data):
def _send_to_rebench_db(self, payload_data, operation):
payload_data["projectName"] = self._project_name
payload_data["experimentName"] = self._experiment_name
if self._api_token:
payload_data["token"] = self._api_token
url = self._server_base_url + operation

payload = self.convert_data_to_json(payload_data)
Expand All @@ -131,6 +135,27 @@ def _send_with_retries(self, payload_bytes, url):
self.ui.error("{ind}Error: Reporting to ReBenchDB failed.\n"
+ "{ind}{ind}" + str(te) + "\n")
return False, None
except HTTPError as error:
body = error.read().decode("utf-8", errors="replace")
if error.code == 401 and "Authorization required" in body:
message = (
"ReBenchDB requires an API token, but none is configured. "
"Set reporting.rebenchdb.api_token in your configuration file. "
"Server response: " + body)
elif error.code == 401:
message = "ReBenchDB rejected the configured API token. Server response: " + body
elif error.code == 403:
message = (
"ReBenchDB denied write access for this token. Check that project_name "
"matches the server's project name exactly. "
"Server response: " + body)
else:
message = (
"ReBenchDB request failed with status " + str(error.code)
+ ". Server response: " + body)
self.ui.error("{ind}Error: Reporting to ReBenchDB failed.\n"
+ "{ind}{ind}" + message + "\n")
return False, None
except (IOError, HTTPException) as error:
# pylint: disable-next=no-member
is_client_error = hasattr(error, "status") and 400 <= error.status < 500
Expand Down