|
50 | 50 | - The timeout for the oc apply command |
51 | 51 | type: int |
52 | 52 | default: 60 |
| 53 | + stage_name: |
| 54 | + description: |
| 55 | + - The name of the stage for retry metrics tracking |
| 56 | + type: str |
| 57 | + required: false |
| 58 | + resource_identifier: |
| 59 | + description: |
| 60 | + - The resource identifier for retry metrics (e.g., original directory path from config) |
| 61 | + type: str |
| 62 | + required: false |
| 63 | + hotloop_retry_metrics: |
| 64 | + description: |
| 65 | + - Current list of retry metrics to append to |
| 66 | + type: list |
| 67 | + required: false |
| 68 | + default: [] |
53 | 69 |
|
54 | 70 | author: |
55 | 71 | - Harald Jensås <hjensas@redhat.com> |
@@ -173,6 +189,31 @@ def apply_kustomize(directory, timeout=60): |
173 | 189 | return rc, outs, errs, out_lines, err_lines |
174 | 190 |
|
175 | 191 |
|
| 192 | +def add_retry_metrics_fact( |
| 193 | + result, current_metrics, stage_name, directory, retry_count, retry_time |
| 194 | +): |
| 195 | + """Add retry metrics to ansible_facts in the result. |
| 196 | +
|
| 197 | + :param result: The module result dictionary to update. |
| 198 | + :param current_metrics: Current list of retry metrics. |
| 199 | + :param stage_name: The name of the stage. |
| 200 | + :param directory: The kustomize directory path. |
| 201 | + :param retry_count: Number of retries that occurred. |
| 202 | + :param retry_time: Total time spent in retries. |
| 203 | + """ |
| 204 | + result["ansible_facts"] = { |
| 205 | + "hotloop_retry_metrics": current_metrics |
| 206 | + + [ |
| 207 | + { |
| 208 | + "stage": stage_name, |
| 209 | + "directory": directory, |
| 210 | + "retry_count": retry_count, |
| 211 | + "retry_time": retry_time, |
| 212 | + } |
| 213 | + ] |
| 214 | + } |
| 215 | + |
| 216 | + |
176 | 217 | def validate_directory(directory): |
177 | 218 | """Validate the directory parameter. |
178 | 219 |
|
@@ -235,6 +276,9 @@ def run_module(): |
235 | 276 |
|
236 | 277 | directory = module.params["directory"] |
237 | 278 | timeout = module.params["timeout"] |
| 279 | + stage_name = module.params.get("stage_name") |
| 280 | + resource_identifier = module.params.get("resource_identifier", directory) |
| 281 | + hotloop_retry_metrics = module.params.get("hotloop_retry_metrics", []) |
238 | 282 |
|
239 | 283 | try: |
240 | 284 | # Validate directory parameter |
@@ -273,6 +317,15 @@ def run_module(): |
273 | 317 | msg = f"Kustomize directory {directory} applied" |
274 | 318 | if retry_count > 0: |
275 | 319 | msg += f" (WARNING: {retry_count} retries after {retry_time}s due to transient errors)" |
| 320 | + # Update ansible_facts with retry metrics |
| 321 | + add_retry_metrics_fact( |
| 322 | + result, |
| 323 | + hotloop_retry_metrics, |
| 324 | + stage_name, |
| 325 | + resource_identifier, |
| 326 | + retry_count, |
| 327 | + retry_time, |
| 328 | + ) |
276 | 329 | result["msg"] = msg |
277 | 330 | result["success"] = True |
278 | 331 | result["changed"] = True |
|
0 commit comments