|
| 1 | +# Resource History Capture |
| 2 | + |
| 3 | + |
| 4 | +## Why it exists |
| 5 | + |
| 6 | +The REST API tests capture AWS-side history for the backing resource (EC2Fleet, SpotFleet, or ASG) to: |
| 7 | +- Provide a exact event timeline for post-test analysis that preserve timestamp for every single EC2 provided. |
| 8 | +- Support consistent request time calculations in metrics tooling. |
| 9 | + |
| 10 | +## When it runs |
| 11 | + |
| 12 | +History capture is triggered by `_capture_history_if_enabled` in `tests/onaws/test_rest_api_onaws.py` when: |
| 13 | +- `CAPTURE_RESOURCE_HISTORY` is `True`. |
| 14 | +- The backing resource is not `RunInstances` (there is no fleet/ASG history for that path). |
| 15 | + |
| 16 | +## Provider-specific behavior |
| 17 | + |
| 18 | +### EC2Fleet Request and Spot Fleet Request |
| 19 | + |
| 20 | +There’s no special handling beyond the generic flow: it calls describe_fleet_history with StartTime = now - 1h, paginates by NextToken, then runs the general completeness check and (if needed) synthesizes missing instance “launched” records. |
| 21 | + |
| 22 | +### EC2Fleet Instant |
| 23 | + |
| 24 | + Instant fleet does not provide history for individual instances. So history file is generated by manually by looking at the timestamps of individual EC2 instnces that were provisioned as part of the fleet request. |
| 25 | + |
| 26 | + - Create a synthetic `fleetRequestChange` "submitted" event at `CreateTime`. |
| 27 | + - Add `instanceChange` "launched" events using instance `LaunchTime`. |
| 28 | + |
| 29 | +### ASG |
| 30 | + |
| 31 | + ASG does not have an equivalent of the fleet submition time, so we check the time when ASG was created by itself. |
| 32 | + |
| 33 | +```python |
| 34 | +response = asg_client.describe_auto_scaling_groups( |
| 35 | + AutoScalingGroupNames=[resource_id] |
| 36 | +) |
| 37 | +groups = response.get("AutoScalingGroups", []) |
| 38 | +created_at: datetime | None = groups[0].get("CreatedTime") if groups else None |
| 39 | +``` |
| 40 | + |
| 41 | +then we generate a synthetic event in the history file |
| 42 | + |
| 43 | +```json |
| 44 | +"history": [ |
| 45 | + { |
| 46 | + "EventInformation": { |
| 47 | + "EventSubType": "submitted" |
| 48 | + }, |
| 49 | + "EventType": "fleetRequestChange", |
| 50 | + "Timestamp": "2026-01-15 11:16:02.087000+00:00" |
| 51 | + }, |
| 52 | +``` |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | +## Output |
| 57 | + |
| 58 | +- File: `{METRICS_DIR}/{test_name}_history.json` |
| 59 | + |
0 commit comments