Skip to content

Commit 32babfa

Browse files
authored
Merge pull request #35383 from dims/add-output-of-operation-ids-that-are-missing-in-audit-logs
Add output of operation id(s) that are missing in audit logs
2 parents 3226ef7 + 5b0436b commit 32babfa

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

experiment/audit/kubernetes_api_analysis.py

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,37 @@ def extract_operations_from_audit_file(audit_file, swagger_operations):
126126
return sorted(operations)
127127

128128

129+
def extract_not_found_operations_from_audit_file(audit_file, swagger_operations):
130+
"""
131+
Extract "NOT FOUND" operations from Kubernetes audit log file and filter
132+
by valid swagger operations.
133+
134+
Args:
135+
audit_file (str): Path to the audit log file
136+
swagger_operations (set): Set of valid operation IDs from swagger spec
137+
138+
Returns:
139+
list: Sorted list of "NOT FOUND" operations that exist in swagger
140+
"""
141+
if not os.path.exists(audit_file):
142+
return []
143+
144+
not_found_operations = set()
145+
146+
with open(audit_file, 'r') as f:
147+
for line in f:
148+
line = line.strip()
149+
# Look for lines with " | NOT FOUND" pattern
150+
if " | NOT FOUND" in line:
151+
# Extract operation name (first column before |)
152+
operation = line.split('|')[0].strip()
153+
# Only include operations that are defined in the swagger specification
154+
if operation and operation in swagger_operations:
155+
not_found_operations.add(operation)
156+
157+
return sorted(not_found_operations)
158+
159+
129160
def compare_operations(ci_operations, pull_operations):
130161
"""
131162
Compare API operations between CI baseline and Pull Request changes.
@@ -254,13 +285,14 @@ def create_argument_parser():
254285

255286

256287
def display_results(swagger_operations, ci_operations, pull_operations,
257-
added_operations, removed_operations, output_file):
288+
added_operations, removed_operations, operations_not_found, output_file):
258289
"""Display the analysis results."""
259290
swagger_count = len(swagger_operations)
260291
ci_count = len(ci_operations)
261292
pull_count = len(pull_operations)
262293
added_count = len(added_operations)
263294
removed_count = len(removed_operations)
295+
not_found_count = len(operations_not_found)
264296
net_change = added_count - removed_count
265297

266298
print("SUMMARY")
@@ -295,6 +327,20 @@ def display_results(swagger_operations, ci_operations, pull_operations,
295327
print("No operations removed.")
296328
print()
297329

330+
print("STABLE ENDPOINTS NOT FOUND IN PULL AUDIT LOG")
331+
print("============================================")
332+
print(f"Count: {not_found_count}")
333+
print()
334+
if operations_not_found:
335+
print("These are stable, non-deprecated API endpoints defined in the Swagger spec")
336+
print("but not exercised in the pull request audit log:")
337+
print()
338+
for i, operation in enumerate(operations_not_found, 1):
339+
print(f"{i:3d}. {operation}")
340+
else:
341+
print("All stable swagger operations were found in the pull request audit log.")
342+
print()
343+
298344
print("Analysis complete!")
299345
print("Generated files:")
300346
print(f"- {output_file} (swagger operations list)")
@@ -335,10 +381,14 @@ def main():
335381
pull_operations = extract_operations_from_audit_file(args.pull_audit_endpoints,
336382
swagger_operations_set)
337383

384+
# Extract NOT FOUND operations from pull request audit file
385+
operations_not_found = extract_not_found_operations_from_audit_file(args.pull_audit_endpoints,
386+
swagger_operations_set)
387+
338388
# Analyze differences and display results
339389
added_operations, removed_operations = compare_operations(ci_operations, pull_operations)
340390
display_results(swagger_operations, ci_operations, pull_operations,
341-
added_operations, removed_operations, args.output_file)
391+
added_operations, removed_operations, operations_not_found, args.output_file)
342392

343393

344394
if __name__ == "__main__":

0 commit comments

Comments
 (0)