Files
floci/compatibility-tests/sdk-test-awscli/test
Allen Sanborn 8921ca1118 feat(ec2): answer MonitorInstances and UnmonitorInstances (#3319)
* feat(ec2): answer MonitorInstances and UnmonitorInstances

Both actions returned UnsupportedOperation. Detailed monitoring is a CloudWatch
billing switch with no behaviour an emulator can meaningfully model, which is
presumably why it was left out -- but declining the call is more costly than
answering it, because one unsupported action fails an entire deployment regardless
of how much of the rest of it succeeded. An aws_instance declared with

    monitoring = true

calls MonitorInstances immediately after RunInstances, so the whole configuration
is discarded over a flag with no state behind it.

Acknowledge the requested state and echo every instance the caller named. Nothing
is stored: there is no monitoring data to serve, and DescribeInstances does not
report a monitoring state today, so persisting one would only create a second
place for it to be wrong.

Reference: the MonitorInstances response shape -- instancesSet of
InstanceMonitoring, each with instanceId and monitoring.state, plus requestId --
https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_MonitorInstances.html
https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_UnmonitorInstances.html

One deliberate deviation: AWS reports state "pending" because the change is applied
asynchronously, then settles on "enabled". The emulator has nothing to settle, so it
reports the terminal state directly. Reporting "pending" for a transition that would
never complete would be worse for any client that polls.

* fix(ec2): reject monitoring for an instance that does not exist, and store the state

Two problems, both of which made the action answer confidently about something it
had not done.

The handler echoed every InstanceId back with a 200 without resolving it, and did
not even take a region to resolve it with. Naming an instance that does not exist
got a success response saying its monitoring was enabled. Every other instance
operation raises InvalidInstanceID.NotFound; this now does too, by delegating to
the service and resolving each id through getRequiredInstance, which is the same
shape stopInstances and the rest already use.

The state was also never stored. Instance already carries a monitoring member and
DescribeInstances already emits it, so MonitorInstances reported "enabled" while
every subsequent read still said "disabled". The state now persists, so the round
trip agrees with itself.

The previous tests asserted the old behaviour: they passed a made-up instance id and
expected 200. They are rewritten to launch a real instance, and two cases are added
for the not-found path plus one that reads the state back through DescribeInstances.

* test(ec2): name the monitoring suite for what it is, an integration test

It is a @QuarkusTest driving the HTTP endpoint, and the repository's dominant
convention for those is *IntegrationTest: 607 of the 736 @QuarkusTest classes on
main follow it. Renaming rather than arguing, since the evidence here points at
the convention.

* test(ec2): cover monitoring through the SDK path, not only the Query wire

AGENTS.md asks for management APIs to be validated with SDK clients and "not only
handcrafted HTTP requests". The Java test drives the Query endpoint with RestAssured,
which is right for pinning exact XML but does not exercise the path aws_instance
actually takes: monitoring = true calls MonitorInstances through the SDK, which parses
the response rather than reading whatever XML we happen to emit.

Three cases in the awscli suite, which is where EC2 SDK coverage already lives:
enable and read back through DescribeInstances, disable and read back, and reject an
instance that does not exist. The read-backs are the point rather than padding: the
bug this guards against was the handler answering "enabled" while every later read
still said "disabled", which asserting on the mutating call's own response cannot see.

Verified as far as this machine allows. run-instances, the teardown and the harness
plumbing all work against a local emulator; the three assertions themselves cannot
pass here because the released 2.0.1 image predates MonitorInstances, which is the
gap this PR closes. They run against the branch build in CI.
2026-09-09 22:36:02 -04:00
..