@@ -126,6 +126,37 @@ def extract_operations_from_audit_file(audit_file, swagger_operations):
126
126
return sorted (operations )
127
127
128
128
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
+
129
160
def compare_operations (ci_operations , pull_operations ):
130
161
"""
131
162
Compare API operations between CI baseline and Pull Request changes.
@@ -254,13 +285,14 @@ def create_argument_parser():
254
285
255
286
256
287
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 ):
258
289
"""Display the analysis results."""
259
290
swagger_count = len (swagger_operations )
260
291
ci_count = len (ci_operations )
261
292
pull_count = len (pull_operations )
262
293
added_count = len (added_operations )
263
294
removed_count = len (removed_operations )
295
+ not_found_count = len (operations_not_found )
264
296
net_change = added_count - removed_count
265
297
266
298
print ("SUMMARY" )
@@ -295,6 +327,20 @@ def display_results(swagger_operations, ci_operations, pull_operations,
295
327
print ("No operations removed." )
296
328
print ()
297
329
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
+
298
344
print ("Analysis complete!" )
299
345
print ("Generated files:" )
300
346
print (f"- { output_file } (swagger operations list)" )
@@ -335,10 +381,14 @@ def main():
335
381
pull_operations = extract_operations_from_audit_file (args .pull_audit_endpoints ,
336
382
swagger_operations_set )
337
383
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
+
338
388
# Analyze differences and display results
339
389
added_operations , removed_operations = compare_operations (ci_operations , pull_operations )
340
390
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 )
342
392
343
393
344
394
if __name__ == "__main__" :
0 commit comments