-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstrumentation_analysis.py
119 lines (91 loc) · 3.83 KB
/
instrumentation_analysis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
from datetime import datetime
from typing import List, Set
import pandas as pd
from github_client import GithubClient
class Instrumentation:
def __init__(self, name: str, has_javaagent: bool = False,
has_library: bool = False, parent: str = None):
self.name = name
self.has_javaagent = has_javaagent
self.has_library = has_library
self.parent = parent
def analyze_instrumentation(file_list: List[str]) -> List[Instrumentation]:
instrumentations = {}
for i in file_list:
parts = i.split("/")
inst_name = parts[0]
parent = None
if len(parts) > 2:
inst_name = parts[len(parts) - 2]
parent = i.split(inst_name)[0].rstrip("/")
inst = instrumentations.get(inst_name, Instrumentation(inst_name))
if i.endswith("/javaagent"):
inst.has_javaagent = True
elif i.endswith("/library"):
inst.has_library = True
inst.parent = parent
instrumentations[inst_name] = inst
items = list(instrumentations.values())
return items
def parse_readme(file_list: List[str]) -> (Set[str], Set[str]):
javaagent_has_readme = set()
library_has_readme = set()
for i in file_list:
parts = i.split("/")
if i.lower().endswith("javaagent/readme.md"):
javaagent_has_readme.add(parts[len(parts) - 3])
elif i.lower().endswith("library/readme.md"):
library_has_readme.add(parts[len(parts) - 3])
return javaagent_has_readme, library_has_readme
def main():
repo = "open-telemetry/opentelemetry-java-instrumentation"
client = GithubClient()
today = (datetime.now().date() + pd.Timedelta(days=1)).strftime(
"%Y-%m-%dT%H:%M:%SZ")
commit = client.get_most_recent_commit(repo, today, "main")
repo_files = client.get_repository_at_commit(
repository=repo,
commit_sha=commit
)
instrumentations = []
readmes = []
for i in repo_files["tree"]:
if i["path"].lower().endswith("readme.md"):
readmes.append(i["path"].replace("instrumentation/", ""))
if i["path"].startswith("instrumentation/") \
and i["type"] == "tree" \
and (i["path"].endswith("/javaagent") or i["path"].endswith("/library")) \
and "/io/opentelemetry/javaagent" not in i["path"] \
and "-common/" not in i["path"]:
instrumentations.append(i["path"].replace("instrumentation/", ""))
inst_list = analyze_instrumentation(instrumentations)
javaagent_has_readme, library_has_readme = parse_readme(readmes)
library: List[Instrumentation] = []
javaagent: List[Instrumentation] = []
no_javaagent = []
output = ""
for i in inst_list:
output += f"{i.name}:\n"
if i.has_javaagent:
output += " javaagent\n"
javaagent.append(i)
else:
no_javaagent.append(i)
if i.has_library:
output += " library\n"
library.append(i)
javaagent_count = len(javaagent)
library_count = len(library)
print(f"{len(inst_list)} instrumentation items")
print("\n")
print(f"{javaagent_count} javaagent instrumentations ({int(javaagent_count / len(inst_list) * 100)}%)")
print(f"Readmes: {len(javaagent_has_readme)}\n\n")
print(f"{library_count} library instrumentations ({int(library_count / len(inst_list) * 100)}%)")
print(f"Readmes: {len(library_has_readme)}")
print("\nLibraries:\n")
for i in library:
full_inst_name = f"{i.parent}/{i.name}" if i.parent else i.name
link = f"https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/{full_inst_name}/library"
print(f"{'- [x]' if i.name in library_has_readme else '- [ ]'} [{i.name}]({link})")
if __name__ == '__main__':
main()