Skip to content

Commit 06fdde0

Browse files
committed
ci: Remember failed workflows/td files
to be able to run them first in the next run on a PR
1 parent f77cb2d commit 06fdde0

File tree

4 files changed

+81
-2
lines changed

4 files changed

+81
-2
lines changed

misc/python/materialize/mzcompose/composition.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import yaml
4444
from psycopg import Connection, Cursor
4545

46-
from materialize import MZ_ROOT, mzbuild, spawn, ui
46+
from materialize import MZ_ROOT, buildkite, mzbuild, spawn, ui
4747
from materialize.mzcompose import cluster_replica_size_map, loader
4848
from materialize.mzcompose.service import Service
4949
from materialize.mzcompose.services.materialized import (
@@ -1564,3 +1564,30 @@ def cloud_hostname(self, quiet: bool = False) -> str:
15641564
# It is necessary to append the 'https://' protocol; otherwise, urllib can't parse it correctly.
15651565
cloud_hostname = urllib.parse.urlparse("https://" + cloud_url).hostname
15661566
return str(cloud_hostname)
1567+
1568+
@contextmanager
1569+
def test_parts(self, parts: list) -> Iterator[str]:
1570+
from materialize.test_analytics.config.test_analytics_db_config import (
1571+
create_test_analytics_config,
1572+
)
1573+
from materialize.test_analytics.test_analytics_db import TestAnalyticsDb
1574+
1575+
priority: dict[str, int] = {}
1576+
test_analytics: TestAnalyticsDb | None = None
1577+
1578+
if buildkite.is_in_buildkite():
1579+
test_analytics_config = create_test_analytics_config(self)
1580+
test_analytics = TestAnalyticsDb(test_analytics_config)
1581+
priority = test_analytics.builds.get_part_priorities()
1582+
1583+
sorted_parts = sorted(
1584+
parts, key=lambda part: priority.get(str(part), 0), reverse=True
1585+
)
1586+
for part in sorted_parts:
1587+
try:
1588+
yield part
1589+
except:
1590+
if buildkite.is_in_buildkite():
1591+
assert test_analytics
1592+
test_analytics.builds.add_build_job_failure(part)
1593+
raise

misc/python/materialize/test_analytics/data/build/build_data_storage.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,38 @@ def update_build_job_success(
173173
)
174174

175175
self.database_connector.add_update_statements(sql_statements)
176+
177+
def add_build_job_failure(
178+
self,
179+
part: str,
180+
) -> None:
181+
job_id = buildkite.get_var(BuildkiteEnvVar.BUILDKITE_JOB_ID)
182+
183+
sql_statements = []
184+
sql_statements.append(
185+
f"""
186+
INSERT INTO build_job_failure
187+
(
188+
build_job_id,
189+
part
190+
)
191+
VALUES
192+
(
193+
{as_sanitized_literal(job_id)},
194+
{as_sanitized_literal(part)}
195+
)
196+
"""
197+
)
198+
199+
self.database_connector.add_update_statements(sql_statements)
200+
201+
def get_part_priorities(self) -> dict[str, int]:
202+
# TODO: Join with the relevant ids
203+
with self.database_connector.create_cursor() as cur:
204+
# 2 for failures in this PR
205+
# 1 for failed recently in CI
206+
# 0 or nothing for rest
207+
cur.execute(f"SELECT part, 2 FROM build_job_failure")
208+
results = cur.fetchall()
209+
print(results)
210+
return {part: prio for part, prio in results}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-- Copyright Materialize, Inc. and contributors. All rights reserved.
2+
--
3+
-- Use of this software is governed by the Business Source License
4+
-- included in the LICENSE file at the root of this repository.
5+
--
6+
-- As of the Change Date specified in that file, in accordance with
7+
-- the Business Source License, use of this software will be governed
8+
-- by the Apache License, Version 2.0.
9+
10+
-- part of a build job that failed, can be a testdrive file or a workflow
11+
CREATE TABLE build_job_failure (
12+
build_job_id TEXT NOT NULL,
13+
part TEXT NOT NULL
14+
);
15+
16+
ALTER TABLE build_job_failure OWNER TO qa;
17+
GRANT SELECT, INSERT, UPDATE ON TABLE build_job_failure TO "hetzner-ci";

test/testdrive/mzcompose.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def workflow_default(c: Composition, parser: WorkflowArgumentParser) -> None:
214214
print(f"Passing through arguments to testdrive {passthrough_args}\n")
215215
# do not set default args, they should be set in the td file using set-arg-default to easen the execution
216216
# without mzcompose
217-
for file in args.files:
217+
with c.test_parts(args.files) as file:
218218
c.run_testdrive_files(
219219
(
220220
"--rewrite-results"

0 commit comments

Comments
 (0)