Skip to content

Commit d6b183d

Browse files
WIP on PR githubupdate builder/runner
1 parent ab6dc9c commit d6b183d

File tree

9 files changed

+566
-145
lines changed

9 files changed

+566
-145
lines changed

pyproject.toml

Lines changed: 1 addition & 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.76"
3+
version = "0.1.80"
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]>","Redis Performance Group <[email protected]>"]
66
readme = "Readme.md"

redis_benchmarks_specification/__api__/app.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,13 @@ def base():
8686
event_type = "Ignored event from webhook"
8787
use_event = False
8888
# Pull request labeled
89+
pull_request_number = None
8990
trigger_label = PULL_REQUEST_TRIGGER_LABEL
9091
if "pull_request" in request_data:
9192
action = request_data["action"]
9293
if should_action(action):
9394
pull_request_dict = request_data["pull_request"]
95+
9496
head_dict = pull_request_dict["head"]
9597
repo_dict = head_dict["repo"]
9698
labels = []
@@ -107,9 +109,8 @@ def base():
107109
label_name = label["name"]
108110
if trigger_label == label_name:
109111
use_event = True
110-
event_type = "Pull request labeled with '{}'".format(
111-
trigger_label
112-
)
112+
pull_request_number = request_data["number"]
113+
event_type = f"Pull request #{pull_request_number} labeled with '{trigger_label}'"
113114
detected_label = True
114115
if detected_label is False:
115116
app.logger.info(
@@ -161,6 +162,8 @@ def base():
161162
"gh_repo": gh_repo,
162163
"gh_org": gh_org,
163164
}
165+
if pull_request_number is not None:
166+
fields_after["pull_request_number"] = pull_request_number
164167
app.logger.info(
165168
"Using event {} to trigger benchmark. final fields: {}".format(
166169
event_type, fields_after
@@ -174,7 +177,6 @@ def base():
174177
event_type, response_data
175178
)
176179
)
177-
178180
else:
179181
app.logger.info(
180182
"{}. input json was: {}".format(event_type, request_data)

redis_benchmarks_specification/__builder__/builder.py

Lines changed: 93 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,19 @@
3131
REDIS_SOCKET_TIMEOUT,
3232
REDIS_BINS_EXPIRE_SECS,
3333
)
34+
from redis_benchmarks_specification.__common__.github import (
35+
check_github_available_and_actionable,
36+
generate_build_finished_pr_comment,
37+
update_comment_if_needed,
38+
create_new_pr_comment,
39+
)
3440
from redis_benchmarks_specification.__common__.package import (
3541
populate_with_poetry_data,
3642
get_version_string,
3743
)
3844

45+
PERFORMANCE_GH_TOKEN = os.getenv("PERFORMANCE_GH_TOKEN", None)
46+
3947

4048
class ZipFileWithPermissions(ZipFile):
4149
def _extract_member(self, member, targetpath, pwd):
@@ -80,6 +88,8 @@ def main():
8088
action="store_true",
8189
help="Store the docker images in redis keys.",
8290
)
91+
parser.add_argument("--github_token", type=str, default=PERFORMANCE_GH_TOKEN)
92+
parser.add_argument("--pull-request", type=str, default=None, nargs="?", const="")
8393
args = parser.parse_args()
8494
if args.logname is not None:
8595
print("Writting log to {}".format(args.logname))
@@ -138,7 +148,8 @@ def main():
138148
build_spec_image_prefetch(builders_folder, different_build_specs)
139149

140150
builder_consumer_group_create(conn)
141-
151+
if args.github_token is not None:
152+
logging.info("detected a github token. will update as much as possible!!! =)")
142153
previous_id = args.consumer_start_id
143154
while True:
144155
previous_id, new_builds_count, _ = builder_process_stream(
@@ -148,6 +159,7 @@ def main():
148159
previous_id,
149160
args.docker_air_gap,
150161
arch,
162+
args.github_token,
151163
)
152164

153165

@@ -172,15 +184,28 @@ def builder_consumer_group_create(conn, id="$"):
172184
)
173185

174186

187+
def check_benchmark_build_comment(comments):
188+
res = False
189+
pos = -1
190+
for n, comment in enumerate(comments):
191+
body = comment.body
192+
if "CE Performance Automation : step 1 of 2" in body:
193+
res = True
194+
pos = n
195+
return res, pos
196+
197+
175198
def builder_process_stream(
176199
builders_folder,
177200
conn,
178201
different_build_specs,
179202
previous_id,
180203
docker_air_gap=False,
181204
arch="amd64",
205+
github_token=None,
182206
):
183207
new_builds_count = 0
208+
auto_approve_github_comments = True
184209
build_stream_fields_arr = []
185210
logging.info("Entering blocking read waiting for work.")
186211
consumer_name = "{}-proc#{}".format(STREAM_GH_EVENTS_COMMIT_BUILDERS_CG, "1")
@@ -197,7 +222,6 @@ def builder_process_stream(
197222
else:
198223
streamId, testDetails = newTestInfo[0][1][0]
199224
logging.info("Received work . Stream id {}.".format(streamId))
200-
conn.lpush("benchmarks:{streamId}")
201225
# commit = None
202226
# commited_date = ""
203227
# tag = ""
@@ -217,6 +241,12 @@ def builder_process_stream(
217241
buffer = conn.get(binary_zip_key)
218242
git_timestamp_ms = None
219243
use_git_timestamp = False
244+
commit_datetime = "n/a"
245+
if b"commit_datetime" in testDetails:
246+
commit_datetime = int(testDetails[b"commit_datetime"].decode())
247+
commit_summary = "n/a"
248+
if b"commit_summary" in testDetails:
249+
commit_summary = int(testDetails[b"commit_summary"].decode())
220250
git_branch, git_version = get_branch_version_from_test_details(testDetails)
221251
if b"use_git_timestamp" in testDetails:
222252
use_git_timestamp = bool(testDetails[b"use_git_timestamp"])
@@ -239,6 +269,30 @@ def builder_process_stream(
239269
if b"tests_groups_regexp" in testDetails:
240270
tests_groups_regexp = testDetails[b"tests_groups_regexp"].decode()
241271

272+
# github updates
273+
is_actionable_pr = False
274+
contains_regression_comment = False
275+
github_pr = None
276+
old_regression_comment_body = ""
277+
pr_link = ""
278+
regression_comment = ""
279+
pull_request = None
280+
if b"pull_request" in testDetails:
281+
pull_request = testDetails[b"pull_request"].decode()
282+
logging.info(f"Detected PR info in builder. PR: {pull_request}")
283+
verbose = True
284+
285+
fn = check_benchmark_build_comment
286+
(
287+
contains_regression_comment,
288+
github_pr,
289+
is_actionable_pr,
290+
old_regression_comment_body,
291+
pr_link,
292+
regression_comment,
293+
) = check_github_available_and_actionable(
294+
fn, github_token, pull_request, "redis", "redis", verbose
295+
)
242296
for build_spec in different_build_specs:
243297
build_config, id = get_build_config(builders_folder + "/" + build_spec)
244298
build_config_metadata = get_build_config_metadata(build_config)
@@ -356,6 +410,8 @@ def builder_process_stream(
356410
"tests_priority_lower_limit": tests_priority_lower_limit,
357411
"tests_groups_regexp": tests_groups_regexp,
358412
}
413+
if pull_request is not None:
414+
build_stream_fields["pull_request"] = pull_request
359415
if git_branch is not None:
360416
build_stream_fields["git_branch"] = git_branch
361417
if git_version is not None:
@@ -389,12 +445,44 @@ def builder_process_stream(
389445
id, git_hash, benchmark_stream_id
390446
)
391447
)
392-
builder_list_completed = f"builder:{streamId}:builds_completed"
393-
conn.lpush(builder_list_completed, benchmark_stream_id)
448+
streamId_decoded = streamId.decode()
449+
benchmark_stream_id_decoded = benchmark_stream_id.decode()
450+
builder_list_completed = (
451+
f"builder:{streamId_decoded}:builds_completed"
452+
)
453+
conn.lpush(builder_list_completed, benchmark_stream_id_decoded)
394454
conn.expire(builder_list_completed, REDIS_BINS_EXPIRE_SECS)
395455
logging.info(
396-
f"Adding information of build->benchmark stream info in list {builder_list_completed}. Adding benchmark stream id: {benchmark_stream_id}"
456+
f"Adding information of build->benchmark stream info in list {builder_list_completed}. Adding benchmark stream id: {benchmark_stream_id_decoded}"
457+
)
458+
benchmark_stream_ids = [benchmark_stream_id_decoded]
459+
comment_body = generate_build_finished_pr_comment(
460+
benchmark_stream_ids,
461+
commit_datetime,
462+
commit_summary,
463+
git_branch,
464+
git_hash,
465+
tests_groups_regexp,
466+
tests_priority_lower_limit,
467+
tests_priority_upper_limit,
468+
tests_regexp,
397469
)
470+
if is_actionable_pr:
471+
if contains_regression_comment:
472+
update_comment_if_needed(
473+
auto_approve_github_comments,
474+
comment_body,
475+
old_regression_comment_body,
476+
regression_comment,
477+
verbose,
478+
)
479+
else:
480+
create_new_pr_comment(
481+
auto_approve_github_comments,
482+
comment_body,
483+
github_pr,
484+
pr_link,
485+
)
398486
shutil.rmtree(temporary_dir, ignore_errors=True)
399487
new_builds_count = new_builds_count + 1
400488
build_stream_fields_arr.append(build_stream_fields)

redis_benchmarks_specification/__cli__/args.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# All rights reserved.
55
#
66
import datetime
7-
7+
import os
88

99
from redis_benchmarks_specification.__common__.env import (
1010
GH_REDIS_SERVER_HOST,
@@ -21,6 +21,7 @@
2121
START_TIME_LAST_YEAR_UTC = START_TIME_NOW_UTC - datetime.timedelta(days=7)
2222
CLI_TOOL_STATS = "stats"
2323
CLI_TOOL_TRIGGER = "trigger"
24+
PERFORMANCE_GH_TOKEN = os.getenv("PERFORMANCE_GH_TOKEN", None)
2425

2526

2627
def spec_cli_args(parser):
@@ -69,6 +70,15 @@ def spec_cli_args(parser):
6970
action="store_true",
7071
help="Include modules statistics on commandstats.",
7172
)
73+
parser.add_argument("--github_token", type=str, default=PERFORMANCE_GH_TOKEN)
74+
parser.add_argument("--pull-request", type=str, default=None, nargs="?", const="")
75+
parser.add_argument(
76+
"--auto-approve",
77+
required=False,
78+
default=False,
79+
action="store_true",
80+
help="Skip interactive approval of changes to github before applying.",
81+
)
7282
parser.add_argument("--summary-csv", type=str, default="")
7383
parser.add_argument("--group-csv", type=str, default="")
7484
parser.add_argument("--commands-json-file", type=str, default="./commands.json")

0 commit comments

Comments
 (0)