Skip to content

Commit b9fb93a

Browse files
authoredAug 17, 2021
Fixed wrong package dir on spec builder (#10)
* [add] Improved package description and badges * [fix] Fixed wrong package dir on spec builder
·
v0.1.270v0.1.1
1 parent 12e3500 commit b9fb93a

File tree

11 files changed

+1110
-399
lines changed

11 files changed

+1110
-399
lines changed
 

‎.github/workflows/poetry-ci-test-lint.yml

Lines changed: 0 additions & 57 deletions
This file was deleted.

‎.github/workflows/tox.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Run Tests using tox
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
pytest:
10+
strategy:
11+
matrix:
12+
python-version: [ 3.6, 3.7, 3.8, 3.9 ]
13+
os: [ ubuntu-latest ]
14+
env:
15+
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
16+
USING_COVERAGE: "3.9"
17+
18+
runs-on: ${{ matrix.os }}
19+
name: os ${{ matrix.os }} python ${{ matrix.python-version }} Linting, testing, and compliance
20+
steps:
21+
- uses: actions/checkout@master
22+
23+
- name: Set up Python ${{ matrix.python-version }}
24+
uses: actions/setup-python@v1
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
28+
- uses: docker-practice/actions-setup-docker@master
29+
30+
- name: Install Poetry
31+
uses: dschep/install-poetry-action@v1.3
32+
33+
- name: Install Tox
34+
run: |
35+
pip3 install black coverage flake8 tox tox-docker tox-poetry
36+
37+
- name: Run tox
38+
run: |
39+
tox
40+
41+
- name: Upload coverage to Codecov
42+
uses: codecov/codecov-action@v1
43+
if: contains(env.USING_COVERAGE, matrix.python-version)
44+
with:
45+
fail_ci_if_error: true

‎poetry.lock

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

‎pyproject.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tool.poetry]
22
name = "redis-benchmarks-specification"
33
version = "0.1.0"
4-
description = ""
4+
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 <filipecosta.90@gmail.com>"]
66

77
[tool.poetry.dependencies]
@@ -14,16 +14,19 @@ marshmallow = "^3.12.2"
1414
argparse = "^1.4.0"
1515
Flask-HTTPAuth = "^4.4.0"
1616
PyYAML = "^5.4.1"
17-
docker = "^5.0.0"
17+
docker = "^4.4.4"
1818
redisbench-admin = "^0.4.8"
1919
psutil = "^5.8.0"
20-
black = "20.8b1"
20+
tox-docker = "^3.0.0"
2121

2222
[tool.poetry.dev-dependencies]
23+
black = "20.8b1"
2324
pytest = "^5.2"
2425
flake8 = "^3.9.2"
2526
pytest-cov = "^2.12.1"
2627
codecov = "^2.1.12"
28+
tox-poetry-installer = {extras = ["poetry"], version = "^0.8.1"}
29+
tox-docker = {extras = ["poetry"], version = "^3.0.0"}
2730

2831
[build-system]
2932
requires = ["poetry-core>=1.0.0"]

‎redis_benchmarks_specification/__api__/api.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,31 @@ def verify_password(username, password):
5252
return result
5353

5454

55-
def commit_schema_to_stream(json_str: str):
55+
def commit_schema_to_stream(json_str: str, conn: redis.StrictRedis):
5656
""" uses to the provided JSON dict of fields and pushes that info to the corresponding stream """
5757
fields = loads(json_str)
5858
reply_fields = loads(json_str)
5959
result = False
6060
error_msg = None
61-
github_url = "https://github.com/redis/redis/archive/{}.zip".format(
62-
fields["git_hash"]
63-
)
64-
try:
65-
response = urlopen(github_url, timeout=5)
66-
content = response.read()
67-
fields["zip_archive"] = bytes(content)
68-
fields["zip_archive_len"] = len(bytes(content))
69-
reply_fields["archived_zip"] = True
70-
result = True
71-
except URLError as e:
72-
error_msg = "Catched URLError while fetching {} content. Error {}".format(
73-
github_url, e.__str__()
61+
if "git_hash" not in fields:
62+
error_msg = "Missing required 'git_hash' field"
63+
else:
64+
github_url = "https://github.com/redis/redis/archive/{}.zip".format(
65+
fields["git_hash"]
7466
)
75-
logging.error(error_msg)
76-
result = False
67+
try:
68+
response = urlopen(github_url, timeout=5)
69+
content = response.read()
70+
fields["zip_archive"] = bytes(content)
71+
fields["zip_archive_len"] = len(bytes(content))
72+
reply_fields["archived_zip"] = True
73+
result = True
74+
except URLError as e:
75+
error_msg = "Catched URLError while fetching {} content. Error {}".format(
76+
github_url, e.__str__()
77+
)
78+
logging.error(error_msg)
79+
result = False
7780

7881
if result is True:
7982
id = conn.xadd(STREAM_KEYNAME_GH_EVENTS_COMMIT, fields)
@@ -84,6 +87,7 @@ def commit_schema_to_stream(json_str: str):
8487

8588
class CommitSchema(Schema):
8689
git_branch = fields.String(required=False)
90+
git_tag = fields.String(required=False)
8791
git_hash = fields.String(required=True)
8892

8993

@@ -103,7 +107,9 @@ def base():
103107
# Convert request body back to JSON str
104108
data_now_json_str = dumps(result)
105109

106-
result, response_data, err_message = commit_schema_to_stream(data_now_json_str)
110+
result, response_data, err_message = commit_schema_to_stream(
111+
data_now_json_str, conn
112+
)
107113
if result is False:
108114
return jsonify(err_message), 400
109115

‎redis_benchmarks_specification/__builder__/builder.py

Lines changed: 61 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import logging
44
import tempfile
55
import shutil
6+
7+
import docker
68
import redis
79
import os
810
from zipfile import ZipFile, ZipInfo
@@ -20,7 +22,6 @@
2022
STREAM_GH_EVENTS_COMMIT_BUILDERS_CG,
2123
STREAM_KEYNAME_NEW_BUILD_EVENTS,
2224
)
23-
from redis_benchmarks_specification.__common__.package import PACKAGE_DIR
2425

2526

2627
class ZipFileWithPermissions(ZipFile):
@@ -73,10 +74,9 @@ def main():
7374
level=LOG_LEVEL,
7475
datefmt=LOG_DATEFMT,
7576
)
76-
logging.info("Using package dir {} for inner file paths".format(PACKAGE_DIR))
77-
builders_folder = os.path.abspath(
78-
PACKAGE_DIR + "/" + args.setups_folder + "/builders"
79-
)
77+
78+
builders_folder = os.path.abspath(args.setups_folder + "/builders")
79+
logging.info("Using package dir {} for inner file paths".format(builders_folder))
8080
different_build_specs = os.listdir(builders_folder)
8181
logging.info(
8282
"Using the following build specs folder {}, containing {} different specs.".format(
@@ -106,35 +106,18 @@ def main():
106106
logging.error("Error message {}".format(e.__str__()))
107107
exit(1)
108108

109-
logging.info("checking build spec requirements")
110-
already_checked_images = []
111-
for build_spec in different_build_specs:
112-
build_config, id = get_build_config(builders_folder + "/" + build_spec)
113-
if build_config["kind"] == "docker":
114-
build_image = build_config["build_image"]
115-
if build_image not in already_checked_images:
116-
logging.info(
117-
"Build {} requirement: checking build image {} is available.".format(
118-
id, build_image
119-
)
120-
)
121-
import docker
109+
build_spec_image_prefetch(builders_folder, different_build_specs)
122110

123-
client = docker.from_env()
124-
image = client.images.pull(build_image)
125-
logging.info(
126-
"Build {} requirement: build image {} is available with id: {}.".format(
127-
id, build_image, image.id
128-
)
129-
)
130-
already_checked_images.append(build_image)
131-
else:
132-
logging.info(
133-
"Build {} requirement: build image {} availability was already checked.".format(
134-
id, build_image
135-
)
136-
)
111+
builder_consumer_group_create(conn)
137112

113+
previous_id = args.consumer_start_id
114+
while True:
115+
previous_id = builder_process_stream(
116+
builders_folder, conn, different_build_specs, previous_id
117+
)
118+
119+
120+
def builder_consumer_group_create(conn):
138121
try:
139122
conn.xgroup_create(
140123
STREAM_KEYNAME_GH_EVENTS_COMMIT,
@@ -152,21 +135,20 @@ def main():
152135
STREAM_GH_EVENTS_COMMIT_BUILDERS_CG
153136
)
154137
)
155-
previous_id = None
156-
while True:
157-
if previous_id is None:
158-
previous_id = args.consumer_start_id
159-
logging.info("Entering blocking read waiting for work.")
160-
newTestInfo = conn.xreadgroup(
161-
STREAM_GH_EVENTS_COMMIT_BUILDERS_CG,
162-
"{}-proc#{}".format(STREAM_GH_EVENTS_COMMIT_BUILDERS_CG, "1"),
163-
{STREAM_KEYNAME_GH_EVENTS_COMMIT: previous_id},
164-
count=1,
165-
block=0,
166-
)
167-
if len(newTestInfo[0]) < 2 or len(newTestInfo[0][1]) < 1:
168-
previous_id = ">"
169-
continue
138+
139+
140+
def builder_process_stream(builders_folder, conn, different_build_specs, previous_id):
141+
logging.info("Entering blocking read waiting for work.")
142+
newTestInfo = conn.xreadgroup(
143+
STREAM_GH_EVENTS_COMMIT_BUILDERS_CG,
144+
"{}-proc#{}".format(STREAM_GH_EVENTS_COMMIT_BUILDERS_CG, "1"),
145+
{STREAM_KEYNAME_GH_EVENTS_COMMIT: previous_id},
146+
count=1,
147+
block=0,
148+
)
149+
if len(newTestInfo[0]) < 2 or len(newTestInfo[0][1]) < 1:
150+
previous_id = ">"
151+
else:
170152
streamId, testDetails = newTestInfo[0][1][0]
171153
logging.info("Received work . Stream id {}.".format(streamId))
172154
# commit = None
@@ -276,7 +258,37 @@ def main():
276258
)
277259
)
278260
shutil.rmtree(temporary_dir, ignore_errors=True)
279-
280261
else:
281262
logging.error("Missing commit information within received message.")
282-
continue
263+
return previous_id
264+
265+
266+
def build_spec_image_prefetch(builders_folder, different_build_specs):
267+
logging.info("checking build spec requirements")
268+
already_checked_images = []
269+
for build_spec in different_build_specs:
270+
build_config, id = get_build_config(builders_folder + "/" + build_spec)
271+
if build_config["kind"] == "docker":
272+
build_image = build_config["build_image"]
273+
if build_image not in already_checked_images:
274+
logging.info(
275+
"Build {} requirement: checking build image {} is available.".format(
276+
id, build_image
277+
)
278+
)
279+
import docker
280+
281+
client = docker.from_env()
282+
image = client.images.pull(build_image)
283+
logging.info(
284+
"Build {} requirement: build image {} is available with id: {}.".format(
285+
id, build_image, image.id
286+
)
287+
)
288+
already_checked_images.append(build_image)
289+
else:
290+
logging.info(
291+
"Build {} requirement: build image {} availability was already checked.".format(
292+
id, build_image
293+
)
294+
)

‎redis_benchmarks_specification/__self_contained_coordinator__/self_contained_coordinator.py

Lines changed: 282 additions & 237 deletions
Large diffs are not rendered by default.

‎redis_benchmarks_specification/test-suites/redis-benchmark-full-suite-1Mkeys-100B.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,17 @@ clientconfig:
3737
requests:
3838
cpus: "2"
3939
memory: "2g"
40+
exporter:
41+
redistimeseries:
42+
break_by:
43+
- version
44+
- commit
45+
timemetric: "$.StartTime"
46+
metrics:
47+
- "$.Tests.Overall.rps"
48+
- "$.Tests.Overall.avg_latency_ms"
49+
- "$.Tests.Overall.p50_latency_ms"
50+
- "$.Tests.Overall.p95_latency_ms"
51+
- "$.Tests.Overall.p99_latency_ms"
52+
- "$.Tests.Overall.max_latency_ms"
53+
- "$.Tests.Overall.min_latency_ms"

‎tox.ini

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[testenv:integration-tests]
2+
deps =
3+
pytest
4+
pytest-cov
5+
codecov
6+
black
7+
flake8
8+
9+
10+
commands =
11+
black --check redis_benchmarks_specification
12+
flake8 redis_benchmarks_specification
13+
coverage erase
14+
coverage run --include=redis_benchmarks_specification/* -m pytest -ra
15+
coverage report -m
16+
17+
docker =
18+
rts_datasink
19+
20+
[docker:rts_datasink]
21+
image = redislabs/redistimeseries:1.4.7
22+
ports =
23+
6379:6379/tcp

‎utils/tests/test_api.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Apache License Version 2.0
2+
#
3+
# Copyright (c) 2021., Redis Labs
4+
# All rights reserved.
5+
#
6+
from redis_benchmarks_specification.__api__.api import commit_schema_to_stream
7+
import redis
8+
9+
from redis_benchmarks_specification.__common__.env import (
10+
STREAM_KEYNAME_GH_EVENTS_COMMIT,
11+
)
12+
13+
14+
def test_commit_schema_to_stream():
15+
result, reply_fields, error_msg = commit_schema_to_stream(
16+
'{"git_hashss":"0cf2df84d4b27af4bffd2bf3543838f09e10f874"}', None
17+
)
18+
assert result == False
19+
assert error_msg is not None
20+
try:
21+
conn = redis.StrictRedis()
22+
conn.ping()
23+
conn.flushall()
24+
result, reply_fields, error_msg = commit_schema_to_stream(
25+
'{"git_hash":"0cf2df84d4b27af4bffd2bf3543838f09e10f874"}', conn
26+
)
27+
assert result == True
28+
assert error_msg == None
29+
reply = conn.xread({STREAM_KEYNAME_GH_EVENTS_COMMIT: 0}, 1)
30+
assert (
31+
reply[0][1][0][1][b"git_hash"]
32+
== b"0cf2df84d4b27af4bffd2bf3543838f09e10f874"
33+
)
34+
35+
except redis.exceptions.ConnectionError:
36+
pass

‎utils/tests/test_builder.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Apache License Version 2.0
2+
#
3+
# Copyright (c) 2021., Redis Labs
4+
# All rights reserved.
5+
#
6+
from redis_benchmarks_specification.__api__.api import commit_schema_to_stream
7+
import redis
8+
9+
from redis_benchmarks_specification.__common__.env import (
10+
STREAM_KEYNAME_GH_EVENTS_COMMIT,
11+
)
12+
13+
14+
def test_commit_schema_to_stream():
15+
result, reply_fields, error_msg = commit_schema_to_stream(
16+
'{"git_hashss":"0cf2df84d4b27af4bffd2bf3543838f09e10f874"}', None
17+
)
18+
assert result == False
19+
assert error_msg is not None
20+
try:
21+
conn = redis.StrictRedis()
22+
conn.ping()
23+
conn.flushall()
24+
result, reply_fields, error_msg = commit_schema_to_stream(
25+
'{"git_hash":"0cf2df84d4b27af4bffd2bf3543838f09e10f874"}', conn
26+
)
27+
assert result == True
28+
assert error_msg == None
29+
reply = conn.xread({STREAM_KEYNAME_GH_EVENTS_COMMIT: 0}, 1)
30+
assert (
31+
reply[0][1][0][1][b"git_hash"]
32+
== b"0cf2df84d4b27af4bffd2bf3543838f09e10f874"
33+
)
34+
35+
except redis.exceptions.ConnectionError:
36+
pass

0 commit comments

Comments
 (0)
Please sign in to comment.