|
| 1 | +# call this script from the project root with python3 -m scripts.gather_version_artifacts |
| 2 | + |
1 | 3 | import os |
2 | 4 | from glob import glob |
3 | | -from typing import List, Dict, Tuple |
| 5 | +from typing import List |
4 | 6 |
|
5 | 7 | from tested_versions_utils import TestedVersions |
6 | 8 |
|
7 | | -ARTIFACT_DIR_NAME = "versions_artifacts" |
8 | | - |
| 9 | +ARTIFACTS_PATH = "versions_artifacts" |
| 10 | +INSTRUMENTATIONS_PATH = "src/instrumentations/" |
9 | 11 |
|
10 | 12 | # Before this script runs, the job downloads the artifacts into files with the following example structure: |
11 | 13 | # |
12 | 14 | # versions_artifacts/ |
13 | | -# 12/ |
14 | | -# express: (next lines are the data inside the file) |
15 | | -# 4.17.2 |
16 | | -# !4.17.3 |
17 | | -# mongoose: |
18 | | -# 6.4.4 |
19 | | -# 3.9.7 |
20 | | -# 14/ |
21 | | -# express: |
22 | | -# 4.17.2 |
23 | | -# !4.17.3 |
24 | | -# mongoose: |
25 | | -# 3.9.7 |
26 | | -# 6.4.4 |
| 15 | +# 3.7/ |
| 16 | +# boto3: (next lines are the data inside the file) |
| 17 | +# 1.0.0 |
| 18 | +# !2.0.0 |
| 19 | +# 3.10/ |
| 20 | +# fastapi: |
| 21 | +# 5.1.0 |
| 22 | +# 5.2.0 |
27 | 23 | # |
28 | 24 | # Each file contains the original supported versions and the results from the tests in the previous job. |
29 | 25 |
|
| 26 | + |
30 | 27 | def main() -> None: |
31 | | - runtime_to_files = { |
32 | | - python_runtime: sorted( |
33 | | - os.listdir(os.path.join(ARTIFACT_DIR_NAME, python_runtime)) |
34 | | - ) |
35 | | - for python_runtime in os.listdir(ARTIFACT_DIR_NAME) |
| 28 | + files_by_runtime = { |
| 29 | + python_runtime: sorted(os.listdir(os.path.join(ARTIFACTS_PATH, python_runtime))) |
| 30 | + for python_runtime in os.listdir(ARTIFACTS_PATH) |
36 | 31 | } |
37 | | - print("runtime_to_files:", runtime_to_files) |
38 | | - if not any(runtime_to_files.values()): |
| 32 | + print(f"new results detected: {files_by_runtime}") |
| 33 | + |
| 34 | + if not any(files_by_runtime.values()): |
39 | 35 | print("No files were found so nothing to update, returning") |
40 | 36 | return |
41 | | - files_names = list(runtime_to_files.values())[0] |
42 | | - if any([files != files_names for files in runtime_to_files.values()]): |
43 | | - raise Exception("Got different files from different runtimes") |
44 | | - origin_tested_files = glob( |
45 | | - "src/instrumentations/*/tested_versions/*" |
46 | | - ) |
47 | | - for instrumentation_name in files_names: |
48 | | - handle_dependency( |
49 | | - instrumentation_name, origin_tested_files, tuple(runtime_to_files) |
50 | | - ) |
51 | 37 |
|
| 38 | + for runtime, dependencies in files_by_runtime.items(): |
| 39 | + update_dependencies(dependencies, runtime) |
52 | 40 |
|
53 | | -def handle_dependency( |
54 | | - instrumentation_name: str, origin_tested_files: List[str], runtimes: Tuple[str, ...] |
55 | | -) -> None: |
56 | | - print("working on:", instrumentation_name) |
57 | | - origin_path = next( |
58 | | - path |
59 | | - for path in origin_tested_files |
60 | | - if path.endswith(f"tested_versions/{instrumentation_name}") |
61 | | - ) |
62 | 41 |
|
63 | | - runtime_to_tested_versions = calculate_runtime_to_tested_versions_dict( |
64 | | - instrumentation_name, runtimes |
65 | | - ) |
66 | | - |
67 | | - for version in list(runtime_to_tested_versions.values())[0].all_versions: |
68 | | - supported = all( |
69 | | - [ |
70 | | - # A version is supported only if it works in all runtimes |
71 | | - (version in runtime_to_tested_versions[runtime].supported_versions) |
72 | | - for runtime in runtimes |
73 | | - ] |
| 42 | +def update_dependencies(dependencies: List[str], runtime: str) -> None: |
| 43 | + for instrumentation_name in dependencies: |
| 44 | + print( |
| 45 | + f"processing {instrumentation_name} for {runtime}...", |
74 | 46 | ) |
75 | | - |
76 | | - TestedVersions.add_version_to_file(origin_path, version, supported) |
77 | | - |
78 | | - |
79 | | -def calculate_runtime_to_tested_versions_dict( |
80 | | - instrumentation_name: str, runtimes: Tuple[str, ...] |
81 | | -) -> Dict[str, TestedVersions]: |
82 | | - runtime_to_tested_versions = { |
83 | | - runtime: TestedVersions.from_file( |
84 | | - os.path.join(ARTIFACT_DIR_NAME, runtime, instrumentation_name) |
| 47 | + # find all the relevant files in the instrumentations path |
| 48 | + # NOTE: this handles the case where the instrumentation's tested versions are |
| 49 | + # not in its own path, eg. uvicorn |
| 50 | + original_tested_versions_files = glob( |
| 51 | + f"{INSTRUMENTATIONS_PATH}/*/tested_versions/{runtime}/*" |
85 | 52 | ) |
86 | | - for runtime in runtimes |
87 | | - } |
88 | | - print("runtime_to_tested_versions:", runtime_to_tested_versions) |
89 | | - |
90 | | - # Sanity check that we tested the same versions in all runtimes |
91 | | - all_versions = set(list(runtime_to_tested_versions.values())[0].all_versions) |
92 | | - if any( |
93 | | - [ |
94 | | - set(tested_versions.all_versions) != all_versions |
95 | | - for tested_versions in runtime_to_tested_versions.values() |
96 | | - ] |
97 | | - ): |
98 | | - raise Exception("Got different versions from different runtimes") |
99 | | - return runtime_to_tested_versions |
| 53 | + for original_tested_versions_file in original_tested_versions_files: |
| 54 | + if original_tested_versions_file.endswith( |
| 55 | + f"tested_versions/{runtime}/{instrumentation_name}" |
| 56 | + ): |
| 57 | + tested_versions = TestedVersions.from_file( |
| 58 | + os.path.join(ARTIFACTS_PATH, runtime, instrumentation_name) |
| 59 | + ) |
| 60 | + for version in tested_versions.all_versions: |
| 61 | + supported = version in tested_versions.supported_versions |
| 62 | + TestedVersions.add_version_to_file( |
| 63 | + original_tested_versions_file, version, supported |
| 64 | + ) |
100 | 65 |
|
101 | 66 |
|
102 | 67 | if __name__ == "__main__": |
|
0 commit comments