Skip to content

Commit 8843cb3

Browse files
[add] Added redis-benchmarks-spec-cli trigger tool; Enabling historical data benchmarks triggering (#38)
* [add] Added redis-benchmarks-spec-cli trigger tool * [fix] only checking test_get_commit_dict_from_sha when gh_token is present
1 parent 813d65c commit 8843cb3

File tree

17 files changed

+432
-70
lines changed

17 files changed

+432
-70
lines changed

poetry.lock

Lines changed: 71 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "redis-benchmarks-specification"
3-
version = "0.1.8"
3+
version = "0.1.9"
44
description = "The Redis benchmarks specification describes the cross-language/tools requirements and expectations to foster performance and observability standards around redis related technologies. Members from both industry and academia, including organizations and individuals are encouraged to contribute."
55
authors = ["filipecosta90 <[email protected]>"]
66
readme = "Readme.md"
@@ -19,6 +19,8 @@ docker = "^4.4.4"
1919
redisbench-admin = "^0.4.16"
2020
psutil = "^5.8.0"
2121
tox-docker = "^3.0.0"
22+
PyGithub = "^1.55"
23+
GitPython = "^3.1.20"
2224

2325
[tool.poetry.dev-dependencies]
2426
black = "20.8b1"
@@ -37,3 +39,4 @@ build-backend = "poetry.core.masonry.api"
3739
redis-benchmarks-spec-api = "redis_benchmarks_specification.__api__.api:main"
3840
redis-benchmarks-spec-builder = "redis_benchmarks_specification.__builder__.builder:main"
3941
redis-benchmarks-spec-sc-coordinator = "redis_benchmarks_specification.__self_contained_coordinator__.self_contained_coordinator:main"
42+
redis-benchmarks-spec-cli = "redis_benchmarks_specification.__cli__.cli:main"

redis_benchmarks_specification/__api__/app.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
from flask_httpauth import HTTPBasicAuth
66

77
from redis_benchmarks_specification.__api__.schema import (
8-
commit_schema_to_stream,
98
CommitSchema,
109
)
10+
from redis_benchmarks_specification.__common__.builder_schema import (
11+
commit_schema_to_stream,
12+
)
1113
from redis_benchmarks_specification.__common__.env import (
1214
REDIS_AUTH_SERVER_HOST,
1315
REDIS_AUTH_SERVER_PORT,
@@ -43,20 +45,21 @@ def verify_password(username, password):
4345
def base():
4446
# Get Request body from JSON
4547
request_data = request.json
48+
gh_org = "redis"
49+
gh_repo = "redis"
4650
schema = CommitSchema()
4751
try:
4852
# Validate request body against schema data types
4953
result = schema.load(request_data)
5054
except ValidationError as err:
51-
# Return a nice message if validation fails
52-
return jsonify(err.messages), 400
55+
err_message = err.messages
56+
if result is True:
57+
# Convert request body back to JSON str
58+
data_now_json_str = dumps(result)
5359

54-
# Convert request body back to JSON str
55-
data_now_json_str = dumps(result)
56-
57-
result, response_data, err_message = commit_schema_to_stream(
58-
data_now_json_str, conn
59-
)
60+
result, response_data, err_message = commit_schema_to_stream(
61+
data_now_json_str, conn, gh_org, gh_repo
62+
)
6063
if result is False:
6164
return jsonify(err_message), 400
6265

redis_benchmarks_specification/__api__/schema.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,5 @@
1-
import logging
2-
from json import loads
3-
from urllib.error import URLError
4-
from urllib.request import urlopen
5-
6-
import redis
71
from marshmallow import Schema, fields
82

9-
from redis_benchmarks_specification.__common__.env import (
10-
STREAM_KEYNAME_GH_EVENTS_COMMIT,
11-
)
12-
13-
14-
def commit_schema_to_stream(json_str: str, conn: redis.StrictRedis):
15-
""" uses to the provided JSON dict of fields and pushes that info to the corresponding stream """
16-
fields = loads(json_str)
17-
reply_fields = loads(json_str)
18-
result = False
19-
error_msg = None
20-
if "git_hash" not in fields:
21-
error_msg = "Missing required 'git_hash' field"
22-
else:
23-
github_url = "https://github.com/redis/redis/archive/{}.zip".format(
24-
fields["git_hash"]
25-
)
26-
try:
27-
response = urlopen(github_url, timeout=5)
28-
content = response.read()
29-
fields["zip_archive"] = bytes(content)
30-
fields["zip_archive_len"] = len(bytes(content))
31-
reply_fields["archived_zip"] = True
32-
result = True
33-
except URLError as e:
34-
error_msg = "Catched URLError while fetching {} content. Error {}".format(
35-
github_url, e.__str__()
36-
)
37-
logging.error(error_msg)
38-
result = False
39-
40-
if result is True:
41-
id = conn.xadd(STREAM_KEYNAME_GH_EVENTS_COMMIT.encode(), fields)
42-
reply_fields["id"] = id
43-
44-
return result, reply_fields, error_msg
45-
463

474
class CommitSchema(Schema):
485
git_branch = fields.String(required=False)

redis_benchmarks_specification/__builder__/builder.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ def builder_process_stream(builders_folder, conn, different_build_specs, previou
177177
git_branch = None
178178
if b"git_branch" in testDetails:
179179
git_branch = testDetails[b"git_branch"]
180+
git_timestamp_ms = None
181+
use_git_timestamp = False
182+
if b"use_git_timestamp" in testDetails:
183+
use_git_timestamp = bool(testDetails[b"use_git_timestamp"])
184+
if b"git_timestamp_ms" in testDetails:
185+
git_timestamp_ms = int(testDetails[b"git_timestamp_ms"].decode())
180186

181187
for build_spec in different_build_specs:
182188
build_config, id = get_build_config(builders_folder + "/" + build_spec)
@@ -246,6 +252,7 @@ def builder_process_stream(builders_folder, conn, different_build_specs, previou
246252
build_stream_fields = {
247253
"id": id,
248254
"git_hash": git_hash,
255+
"use_git_timestamp": str(use_git_timestamp),
249256
"build_image": build_image,
250257
"run_image": run_image,
251258
"compiler": compiler,
@@ -259,6 +266,8 @@ def builder_process_stream(builders_folder, conn, different_build_specs, previou
259266
}
260267
if git_branch is not None:
261268
build_stream_fields["git_branch"] = git_branch
269+
if git_timestamp_ms is not None:
270+
build_stream_fields["git_timestamp_ms"] = git_timestamp_ms
262271
for artifact in build_artifacts:
263272
bin_artifact = open(
264273
"{}src/{}".format(redis_temporary_dir, artifact), "rb"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Apache 2 License
2+
#
3+
# Copyright (c) 2021., Redis Labs
4+
# All rights reserved.
5+
#

0 commit comments

Comments
 (0)