Repository navigation
feat(gateway): Accept enableApplicationLogs and enableTraces, send the logs of a new Box gateway, and find the target ids of two Box gateways - #2860
Conversation
The CDK library adds two optional fields to a gateway entry, on the branch `sa/box-gateway-vended-logs` of aws/agentcore-l3-cdk-constructs. When `enableApplicationLogs` is `true`, the gateway sends its `APPLICATION_LOGS` to CloudWatch Logs. When `enableTraces` is `true`, the gateway sends its `TRACES` to X-Ray. The CLI gateway schema does not accept an unknown field. Thus the CLI does not accept a project that sets one of the two fields, and a user cannot send the `TRACES` of a gateway to X-Ray. `AgentCoreGatewaySchema` has the two fields as optional booleans, with the same doc comments as the CDK library schema. The two fields have no schema default. The CLI writes the parsed spec back to `agentcore.json`, and a schema default adds the field to each project file. The default of `enableApplicationLogs` also changes with `boundRuntime`, and the CDK library applies it. The CLI has no other copy of the gateway schema that it must keep in step with the CDK library. The v0 schema in `src/projectSchemas/v0` is a frozen copy, and this change does not touch it. Tests: `gateway application logs and traces` in `src/projectSchemas/gateway.test.ts`. The schema accepts `true` and `false` for each field. Each value stays after the CLI writes the spec to JSON and reads it again. A gateway without the two fields has no such field after it is written and read again. The schema does not accept a string for each field.
A project with two Box runtimes has two Box gateways. Each Box gateway has a `bedrock` target, and usually an `agentcore` target. The CDK library change on the branch `sa/box-gateway-vended-logs` of aws/agentcore-l3-cdk-constructs adds the gateway name to the export name of a target name that two or more gateways have: `GatewayTarget-<gateway>-<target>-Id`. `agentcore project status` looks for `GatewayTarget-<target>-Id` only. Thus, after a deploy, the status shows each of these targets as `local-only`. `identifierOf` in `src/core/project/backends/cdk.ts` looks for the name with the gateway first, and then for the name without the gateway. A target name that only one gateway has keeps the name without the gateway. Thus a project with one gateway finds its targets with no change. Tests: in `src/core/project/backends/cdk.test.ts`, the test `resolves a target name that two gateways share to each gateway's own id` gives two gateways with a `bedrock` target, and one of them also with an `egress-github` target. Each `bedrock` target gets the id of the gateway that has it, and `egress-github` gets the id from the name without the gateway. The test `resolves the target of one gateway through the export name without the gateway` gives one gateway with a `bedrock` target, and the target gets its id.
… of a new Box project On the branch `sa/box-gateway-vended-logs` of aws/agentcore-l3-cdk-constructs, the CDK library sends the `APPLICATION_LOGS` of a gateway only when its entry sets `enableApplicationLogs: true`. This is the same for a gateway with `boundRuntime`. Before that change, a gateway with `boundRuntime` sent them when the entry did not set the field. Thus, after that change, a Box gateway without the field sends no logs. `boxGatewaySpec` writes `enableApplicationLogs: true`. Thus the Box gateway of a new Box project sends its `APPLICATION_LOGS`. `agentcore build` changes only the targets of a Box gateway. Thus a `false` that a user writes stays, and `agentcore build` does not add the field to a Box gateway without it. A Box project from a previous CLI version gets no new resources from a CDK update. The doc comment of the field gives the new default. Tests: in `manager.box.test.ts`, a Box template writes `enableApplicationLogs: true` in each Box gateway. In `manager.boxNetwork.test.ts`, `agentcore build` keeps a `false`, and does not add the field when the user removes it. Without the field in `boxGatewaySpec`, 2 tests show an error. With an `agentcore build` that writes `true` at each run, or only when the field is not there, 1 test shows an error.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## box-integration #2860 +/- ##
===================================================
+ Coverage 96.78% 96.79% +0.01%
===================================================
Files 766 766
Lines 66590 66803 +213
===================================================
+ Hits 64452 64665 +213
Misses 2138 2138 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
leo237
left a comment
There was a problem hiding this comment.
Review of #2860 at 34da4891 (first review by leo237)
Plan check. The squash plan doc (https://pippin.amazon.dev/docs/XFRmP1pP9L90nl/box-integration-squash-and-pr-plan-v2) returned 401 when I tried to read it, so I checked the commits against the branches. None of the three commits (54abc7e6, a2404eee, 34da4891) ports anything from box-integration-development:
- Dev has no
enableApplicationLogs/enableTracesinsrc/projectSchemas/gateway.ts. - Dev's
identifierOfstill reads onlyGatewayTarget-<target>-Id. - The source commit
2f8ac91cis on theSaiAbhishek98fork (fix/box-runtime-gaps), not on dev.
So this is a standalone CLI partner of aws/agentcore-l3-cdk-constructs#470, not one of the phased plan PRs. There are no missing or extra plan commits to check against.
Nothing is applied twice. No merged plan PR touches identifierOf, AgentCoreGatewaySchema or boxGatewaySpec, and #2857 and #2859 (0a8510b4) don't either. The base is 71051b42 (#2852). box-integration has since moved to dd36f7b2 (#2853), and the PR is still MERGEABLE. #2853's change to cdk.ts (the runtimeRunsInBox OTel warning) does not overlap this diff.
Protected box-integration fixes. The diff touches only identifierOf, AgentCoreGatewaySchema and boxGatewaySpec. None of the #2845/#2848/#2849/#2850/#2851/#2852/#2853 fixes is changed, and runtimeRunsInBox stays as it is.
What I checked
-
The defaults match L3 #470 at its current head. L3 #470 now has
4df982c9, which sendsAPPLICATION_LOGSonly whenenableApplicationLogs: true. TheenableApplicationLogsdoc comment ("Defaults to false for every gateway"), the defaults table in the body and34da4891all agree with it. -
Every Box gateway the CLI creates gets
enableApplicationLogs: true. All three callers ofboxGatewaySpecget it:newProjectSpec(create),ensureBoxGateway, and the "Runtime has no Box gateway" validation message that prints the entry to paste. BecausepatchNamedEntrieswrites back only the fields that changed,buildkeeps a user'sfalseand does not add the field back.manager.boxNetwork.test.tscovers both cases. -
Silent failures. None found. A Box project created before this PR has a Box gateway without the field, so it sends no
APPLICATION_LOGSafter the CDK bump, with no message. Before #470 the CDK sent no Box gateway logs at all, so nothing that worked before is lost. I am noting it, not blocking on it. -
New types. None. The PR adds two optional booleans to an existing
.strict()schema, with no schema default. That is right for a schema the CLI writes back toagentcore.json. The frozen v0 schema is unchanged. -
Comments. The
identifierOf,enableApplicationLogs,enableTracesandboxGatewaySpeccomments are accurate. -
Tests. The coverage is good:
- the schema round trip, with no default added;
- rejection of a non-boolean value;
- shared and unique target names, including the
_to-sanitization throughsecond_agent-box; - create writes
true; - build keeps
falseand does not add a removed field back.
None of the new tests uses a Windows-unsafe pattern.
Non-blocking
- The lookup order in
identifierOfcan silently pick the wrong id (inline). The PR body already describes this case. If the lookup used the gateway-qualified name only when the spec has the target name on two or more gateways (the L3's own rule), there would be no ambiguity. - Test nit (inline). The
cdk.test.tsgateways are namedagent-box, not the real<runtime>-box-egress. There is also no test for a shared name in the spec when the stack has only the unqualified export (the fallback path). - Merge order / pin. Until
@aws/agentcore-cdkships with #470 andsrc/assets/cdk/package.jsonis bumped from1.0.2, two things happen. A user-set field passes the CLI and then fails at synth. Every new Box project also writesenableApplicationLogs: true, which the current strict L3 gateway schema rejects. So new Box projects will not synth until #470 merges and the pin is bumped. The body states the merge order. Please keep this PR and the pin bump together with #470. - Existing Box projects made before this PR keep a gateway without the field, so they send no logs (see above). A one-line release note telling users to add
"enableApplicationLogs": truewould help.
Open items from earlier reviews
This PR does not touch the following items, and none of them were expected here. They stay with their later PRs:
- the
network?.region ?? DEFAULT_EGRESS_BEDROCK_REGIONfallback; - the
agentcore devcredential refresh andAWS_PROFILEreporting; box.versioninagentcore dev;- the assert comment;
- the refusal message after
remove; - the seven duplicated template files;
- the
start.pytest; - the skipped telemetry targets (
29d283d6); BOX_BASE_PROJECT_WRITE_TOOLS.
The ensureBoxGateway doc comment still lists add runtime and export harness as callers, although #2853 makes Box projects refuse both. That comment predates this PR.
CI (head 34da4891)
Linux, Windows, Analyze, CodeQL and the CodeBuild e2e checks pass. verify / macOS was still pending after about 13 minutes of waiting. The known flaky macOS screen-test 5 s timeouts and the Windows transactionSearch EFAULT test on the base are non-blocking if either appears.
Decision: APPROVE. Only non-blocking items remain, assuming macOS goes green.
tejaskash
left a comment
There was a problem hiding this comment.
Requesting changes for the target id lookup (inline), which can give a target another target's id, including in existing single-gateway projects. The schema side matches #470: same field names, types, no default, and the export name sanitizer is the same. Upgrade looks right too, since build doesn't add the field and the L3 default is off.
One description fix: add runtime and export harness also write enableApplicationLogs: true through ensureBoxGateway (manager.tsx:2254), not just create. So a Box project made by an earlier CLI that adds a runtime ends up with one gateway logging and one not. That's reasonable, since a new gateway has no log group to collide with, but the description and release note should say so.
…e CDK library writes Before this change, `identifierOf` looked for `GatewayTarget-<gateway>-<target>-Id` first, and then for `GatewayTarget-<target>-Id`. A gateway name and a target name can have a hyphen. Thus a target could get the id of a different target. An example is the gateway `a` with the target `b`, and the gateway `tools` with the target `a-b`. The target `b` got the id of `tools:a-b`. This occurred also with one gateway: `tools` with the targets `search` and `tools-search`. Also, a target of a new gateway that was not deployed got the id of the target of a different gateway with that name. After this change, the CLI counts the gateways in `agentCoreGateways` that have each target name. The CDK library does the same. For a target name that two or more gateways have, it looks only for `GatewayTarget-<gateway>:<target>-Id`. For a different target name, it looks only for `GatewayTarget-<target>-Id`. When the gateway itself has no deployed id, each of its targets is `local-only`. When a second gateway gets a target name of a deployed gateway, the two targets are `local-only` until the next deploy writes the new export names. Tests: in `cdk.test.ts`, one `test.each` with the gateway names of `boxGatewaySpec` has seven tests: a shared name, one gateway, the two hyphen examples above, a shared name with a hyphen, a shared name with only the export from before, and a gateway that is not deployed. The lookup of the previous commit makes 5 tests show an error. The two names in the other sequence with a fallback, a hyphen as the separator, and no check of the gateway each make 1 or 2 tests show an error.
…ells the assertion again `gateway.test.ts` had a test that `AgentCoreGatewaySchema` refuses a string for each of the two fields. That is the behavior of `z.boolean()`, not a decision of this change. A comment in `manager.boxNetwork.test.ts` told again what the next assertion examines. The two are removed.
…d how to stop them `agentcore create` writes `enableApplicationLogs: true` in the Box gateway of a new Box project. Thus the gateway sends its `APPLICATION_LOGS` to CloudWatch Logs, and the logs can hold the request and response bodies of its calls. CloudWatch Logs keeps them for 90 days, and the log group has no KMS key. Before this change, `create` did not tell the user about this. After this change, `create` gives a warning for each Box gateway with `enableApplicationLogs: true`. The warning says what the logs can hold, how long CloudWatch Logs keeps them, and that `"enableApplicationLogs": false` stops them. Tests: in `manager.boxNetwork.test.ts`, `create` of a Box project gives the warning. Without the warning, 1 test shows an error.
`box-integration` changed the imports of `cdk.test.ts`, and this branch also changed them. Thus the branch had a conflict with `box-integration`. The merge keeps the two imports.
|
Thank you. 3b54f984 makes the target id lookup accurate. The CLI counts the gateways that have each target name, as the CDK library does. Then it looks only for the one export name that the CDK library writes. A target of a gateway that is not deployed gets no id. Each inline comment has its own reply. About |
leo237
left a comment
There was a problem hiding this comment.
Re-review of #2860 at 239df187 (since our approval at 34da4891)
What changed. This was a merge, not a rebase. There are three new commits, 3b54f984, 14cf2109 and 6a48a181, and a merge, 239df187, which brings in box-integration at f5503f02 (#2857). The one conflict, in the imports of cdk.test.ts, is resolved correctly: it keeps both boxGatewaySpec and BOX_RELEASE. Leaving out the conflicted file, the merge adds nothing beyond #2853 and #2857.
The branch does not have #2858 or #2859 yet. Its merge base is f5503f02, and box-integration is now at 1405932a. A trial merge of box-integration into this branch is clean. It touches only the eight files of this PR, and every must-survive fix from #2845, #2848/#2849, #2850, #2851, #2852, #2853, #2857 and #2859 stays as it is. However, see CI and the first blocking item below.
Plan check. The squash plan doc (https://pippin.amazon.dev/docs/XFRmP1pP9L90nl/box-integration-squash-and-pr-plan-v2) still returns 401, so I checked against the branches. None of the three new commits is on box-integration-development, and dev has no enableApplicationLogs, boxGatewayLogsNotice or gatewaysByTargetName. They are review fixes for this standalone partner of aws/agentcore-l3-cdk-constructs#470, not dev ports. No later plan PR covers the items below.
L3 #470 and the pin. aws/agentcore-l3-cdk-constructs#470 is still open (head 57b08a4b). Once this branch has the current box-integration, the pin in src/assets/cdk/package.json is 1.1.0 (from the v1.x sync, #2858), not 1.0.2. But 1.1.0 does not contain #470, so the merge-order point from our last review still applies. The description should say 1.1.0 instead of 1.0.2.
Earlier comments: addressed
- Our
identifierOfordering comment, and tejaskash's. Addressed in3b54f984. The lookup counts the gateways that have each target name, exactly ascreateGatewayOutputsdoes in L3 #470 at57b08a4b. It then asks for only the one export name,GatewayTarget-<gateway>:<target>-IdorGatewayTarget-<target>-Id, with no fallback. The colon gets throughstackExportName([^a-zA-Z0-9:-]) and matches the L3'sexportName. The three hyphen examples (ours, and both of tejaskash's) are now test cases. - tejaskash's "target of an undeployed gateway takes another gateway's id". Addressed. Targets of a gateway without a
Gateway-<name>-Arnexport are reportedlocal-only. - Our test nit. Addressed. The tests use
boxGatewaySpec(...)names, and the "shared in spec, only unqualified in stack" case is pinned. It now expects no id instead of a fallback. - tejaskash's comment nits and the zod-rejects-a-string test. Addressed in
3b54f984and14cf2109. The tests are now a singletest.each. - The
ensureBoxGatewaydoc comment from our last review. Gone, because #2853 removedensureBoxGateway.
Blocking
- CI:
verify / Linuxfails witherror: Script not found "test:package"(step "Smoke test npm installation with host TypeScript versions"). The workflow from #2858 runsbun run test:package, and this branch'spackage.jsondoes not have the script yet. Please merge (or rebase onto) the currentbox-integration. - After that merge,
add runtimein a Box project turns onAPPLICATION_LOGSwith no notice (inline atmanager.tsx:628). #2859 broughtadd runtimeback for Box projects, and itsaddBoxRuntimewritesboxGatewaySpec(name), which now carriesenableApplicationLogs: true. The new notice (6a48a181) is given only bycreate. The PR description's "Onlycreatewrites a Box gateway" paragraph relies on #2853 refusing a second runtime, and #2859 has since undone that. tejaskash asked for exactly this case to be covered. Please give the same notice fromaddBoxRuntime, add a test for it, and update the description.
Reviewed and fine
- Silent failures. The new lookup gives no id instead of a wrong id. In one case a target is shown
local-onlyeven though it is deployed: when a second gateway takes an existing target name and has not been deployed yet. That is the safe direction, and the description says so. - Comments. The new
identifierOfcomment, the gateway-not-deployed comment, theboxGatewaySpecdoc andboxGatewayLogsNoticeare accurate. The 90-day retention matchesRetentionDays.THREE_MONTHSin L3 #470. - New types. None. The
local-onlystub child has the same shape thatresolvereturns for a target with no id. - Tests. Seven
test.eachcases cover the lookup, and acreatewarning test covers the notice. No Windows-unsafe patterns (no hard-coded/paths, no splitting on:for paths, no POSIX file modes, nosh, no empty env).
Non-blocking
- Nit (inline at
cdk.test.ts:1584). No case now has a_in a gateway name, so the_to-change for the qualified<gateway>:<target>export is not tested. - Nit. The notice test checks only that the warning is present. A negative case would pin that a non-Box
creategives no notice.
CI (head 239df187)
verify / Linux: fail, withScript not found "test:package"(blocking item 1).verify / Windows, Analyze, CodeQL and the CodeBuildagentcore-e2echeck: pass.e2ewas skipped.verify / macOS: still pending when I posted (about 9 minutes after the run started). The known flaky 5 s macOS screen-test timeouts and the WindowstransactionSearchEFAULT test on the base are non-blocking if either shows up.
Decision: COMMENT. Two blocking items: the CI failure, which a merge of box-integration fixes, and the missing logs notice on add runtime once #2859 is in.
`box-integration` has two new PRs. The CI workflow of the base runs `bun run test:package`, and the branch did not have that script. Also, `add runtime` writes a Box gateway again. The merge has no conflict.
…ds its logs `add runtime` in a Box project writes a new Box gateway with `boxGatewaySpec`, thus with `enableApplicationLogs: true`. Before this change, only `create` told the user that the gateway sends its `APPLICATION_LOGS`, which can hold the request and response bodies of its calls. After this change, `boxGatewayLogsWarnings` gives the warning for each Box gateway with `enableApplicationLogs: true` in a list. `create` gives it for the Box gateways of the new project. `addBoxRuntime` gives it for the Box gateway that it writes. These are the two commands that write a new Box gateway. Tests: in `manager.box.test.ts`, `add runtime` gives the warning for its new gateway only. Each `create --template` test makes sure that a Box template gives the warning and that a different template does not. Without the warning of `add runtime`, 1 test shows an error. Without the warning of `create`, 3 tests show an error. With no warning from `boxGatewayLogsWarnings`, 4 tests show an error.
…in its name No target id test had a gateway name with an underscore. Thus no test examined the change from `_` to `-` in the export name `GatewayTarget-<gateway>:<target>-Id`. After this change, a test has the gateways `my_tools` and `other` with the target `search`. Without the change from `_` to `-` in `stackExportName`, 2 tests show an error.
leo237
left a comment
There was a problem hiding this comment.
Re-review of #2860 at fd93daaf (since our COMMENT at 239df187)
What changed. This was a merge, not a rebase. There are three new commits:
7c2b49famergesbox-integrationat1405932a(#2858 and #2859).aff8f148adds the logs notice toadd runtime.fd93daafadds the_gateway-name test.
The merge base is now the current box-integration head (1405932a). 7c2b49fa is a clean auto-merge: replaying it gives a tree identical to the commit. Against box-integration, the PR touches only its own eight files. The only lines it removes are the old identifierOf lookup, the old addBoxRuntime push (now split into two lines) and a reworded doc comment. Nothing from #2858 or #2859 is lost. That includes the per-runtime .box/<name>/ profile, boxValidation.ts, add runtime in Box projects and addBoxRuntime. All must-survive fixes from #2845 through #2857 are unchanged, since none of those files differ except the eight above.
Plan check. The squash plan doc (https://pippin.amazon.dev/docs/XFRmP1pP9L90nl/box-integration-squash-and-pr-plan-v2) still returns 401, so I checked against the branches. box-integration-development still has no enableApplicationLogs or boxGatewayLogs*. These are review fixes for this standalone partner PR, not dev ports.
Earlier comments: addressed
- Blocking 1, CI
Script not found "test:package". Addressed by the merge ofbox-integration.verify / Linuxnow passes. - Blocking 2, the missing notice on
add runtime(inline atmanager.tsx:628). Addressed inaff8f148:boxGatewayLogsWarningsis shared bycreateandaddBoxRuntime.addBoxRuntimepasses only the gateway it writes, so the existing Box gateway does not get a second notice.- The new test "add runtime says that the new Box gateway sends its logs, and how to stop them" checks for exactly one notice, for
search-box-egress. - These are the only two writers of a Box gateway.
templates/project.ts:140is used bycreate,manager.tsx:2445only computes the name, andproject.ts:176prints a schema message.
- Nit: no
_to-test for the qualified name (inline atcdk.test.ts:1584). Addressed infd93daaf.my_toolsandothersharesearch, and the lookup findsGatewayTarget-my-tools:search-Id. The fixture now sanitizes theGateway-<name>-Arnexport the same way. - Nit: no negative case for the notice. Addressed. Each
create --templatecase now assertswarnings.includes(notice) === (projectType === "box"). - Description. Addressed. It now says the pin is
1.1.0, drops "Onlycreatewrites a Box gateway", and explains that one Box gateway can have logs while another does not. - tejaskash's earlier items were addressed in
3b54f984/14cf2109, as noted in our last review.
Reviewed and fine
- Silent failures. None new. The notice is yielded inside the
trythat discards the staged paths, so a failed box scaffold gives no notice. - Comments. The reworded
boxGatewayLogsNoticedoc and the newboxGatewayLogsWarningsdoc ("createandadd runtime") are accurate. - New types. None exported.
boxGatewayLogsWarningstakes an inline structural type for the gateway (see the nit below). - Windows safety. The new tests have no hard-coded paths, no splitting on
:for paths, no file modes, noshand no empty env.
Non-blocking
- Nit (inline at
manager.tsx:2149). InaddBoxRuntime, the notice is yielded beforeaddResourceparses and writesagentcore.json(manager.tsx:1071-1076). If that write fails, the user sees "sends its APPLICATION_LOGS" followed by an error, for a gateway that was never written. The error is visible, so nothing fails silently. Yielding the notice after the spec write, ascreatedoes after reading the project back, would make the two commands consistent. - Nit.
boxGatewayLogsWarningscould takereadonly AgentCoreGateway[](the schema's inferred type) instead of the inline{ name; boundRuntime?; enableApplicationLogs? }, so it stays in step with the schema.
Note: L3 merge order
aws/agentcore-l3-cdk-constructs#470 is still open (head 57b08a4b, CHANGES_REQUESTED). The @aws/agentcore-cdk pin on box-integration is 1.1.0, which does not contain #470. Until #470 is merged and released, and the pin is raised:
- a new Box project (
enableApplicationLogs: true) fails at synth against the strict L3 schema; - shared target names show as
local-only.
So, as the description says, merge #470 first or at the same time, then raise the pin.
CI (head fd93daaf)
verify / Linux,verify / Windows, Analyze, CodeQL and CodeBuildagentcore-e2e: pass.e2e: skipped.verify / macOS: still pending when I posted (about 10 minutes into the run). The known flaky 5 s macOS screen-test timeouts and the WindowstransactionSearchEFAULT test on the base are non-blocking if either shows up.
Decision: APPROVE. Both blocking items from our last review are fixed, and only nits remain. The L3 #470 merge order is a note, not a blocker for this PR.
`box-integration` has three new changes: PR 5 ([aws#2866](aws#2866)), the pin of box 0.1.11-mquang.preview.9 ([aws#2867](aws#2867)), and `--containment` ([aws#2854](aws#2854)). Two files had a merge conflict. In `create` in `manager.tsx`, `box-integration` gives `defaultLogTargetNotices`, and this branch gives `boxGatewayLogsWarnings`. The merge keeps the two. In the imports of `manager.boxNetwork.test.ts`, `box-integration` removes `renderRuntimeBoxProfile`, and this branch adds `boxGatewayLogsNotice`. The merge keeps only `boxGatewayLogsNotice`. A test of `box-integration` makes sure that `add runtime` gives no `warning` before the write of agentcore.json. The name of the test is "a failed write of agentcore.json gives no notice of the default log target". `addBoxRuntime` gave the logs `warning` before that write, thus that test showed an error after the merge. The merge moves the logs `warning` of `add runtime` to after the write, with the `defaultLogTargetNotices` of `box-integration`. `create` also gives each `warning` after the write.
…e.json stops with an error A comment of Leo on this pull request (aws#2860 (comment)) tells that `add runtime` gave the logs `warning` of the new Box gateway before the write of agentcore.json. When that write stopped with an error, the user saw the `warning` for a gateway that agentcore.json did not have. `create` gives its `warning` only after the write. The merge before this commit moves the `warning` of `add runtime` to after the write. This commit adds a test for that sequence. The test gives `addResource` a JSON writer that refuses the write of agentcore.json, thus the test does not use file modes, and root gets the same result. `refusingSpecWrites` holds that writer. The test of the default log target from `box-integration` also uses it. Tests: in `manager.box.test.ts`, the new test makes sure that the add wrote the box profile of the runtime, and then gave no logs `warning`. It also makes sure that agentcore.json did not change. With the `warning` in `addBoxRuntime`, the new test and the test of the default log target show an error. With the `warning` in `addResource` immediately before the write, the two tests show an error. With no `warning` from `add runtime`, the test that `add runtime` gives the `warning` shows an error.
|
This branch has a merge of |
leo237
left a comment
There was a problem hiding this comment.
Re-review of #2860 at b05116c8 (since our approval at fd93daaf)
Scope. Of the 36 commits in fd93daaf...b05116c8, the PR's own new work is the merge d9c52306 and the test commit b05116c8. The rest are box-integration commits (#2854, #2862, #2865, #2866, #2867 and others) that were reviewed separately, so I did not re-review them.
The merge d9c52306. It brings in box-integration at e5a5ddf5 (#2854), which is the current base head, so the branch is up to date. I compared the PR's net diff against 1405932a at fd93daaf with its net diff against e5a5ddf5 at b05116c8:
git range-diffshows the five PR commits unchanged (=).cdk.ts,cdk.test.ts,gateway.ts,gateway.test.ts,project.tsandmanager.boxNetwork.test.tsdiffer only in hunk offsets and import context.- In
manager.tsx, the merge moves one thing. Theadd runtimewarning is no longer yielded inaddBoxRuntime, afterwriteBoxProfile. It is now yielded inaddResourceafterthis.json.write(agentCoreSpecPath, ...), next todefaultLogTargetNoticesfrombox-integration. The filter isagentCoreGateways.filter(({ boundRuntime }) => boundRuntime === added). Because of this move, theaddBoxRuntimepush is now unchanged from base. Thecreatewarning (isBoxProject→boxGatewayLogsWarnings) stays where it was. - The lines the PR removes from base are the same set as before. The only differences are the moved
addBoxRuntimeline, theruntimes.filter(... input.resourceConfig.name)line (now throughadded) and the inline JSON writer that becamerefusingSpecWrites. Nothing from base is dropped.
Must-survive fixes. Against box-integration, the PR still touches only its own eight files (cdk.ts/cdk.test.ts, manager.tsx, manager.box.test.ts, manager.boxNetwork.test.ts, gateway.ts/gateway.test.ts, project.ts). In manager.tsx, the only lines it removes are the ones listed above. So none of these is touched:
- boxProfileCredentials /
ENV_LOCAL_RELATIVE_PATH,writesBedrockRoute/tomlKey, Dockerfilecurl --retry 3/tar --no-same-owner, xray grants runtimeRunsInBox/assertBoxRuntimesHaveBoxVersion,${{ inputs.gateway.url }}/${{ inputs.aws.region }}, per-runtime.box/<name>/- dev secrets,
boxStartFolder,.venv/bin/python,EnvLocalFile.upsert,publishInstall - runtimeProfile/*, ffi shim removal,
BOX_OTHER_MACHINE_HINT - the box pin
0.1.11-mquang.preview.9(noSHA256SUMS.txt, norefuseOldShippedNames) - #2854
--containment
ENV_LOCAL_RELATIVE_PATH and the envFile?.rollback() cleanup in addResource are still in place.
b05116c8. It adds refusingSpecWrites, which refuses the agentcore.json write through an injected ReadWriteJson rather than file modes, so it also works as root on Linux CI. The default-log-target test now uses it as well. The new test checks three things:
addreachedwriting box profile <.box/search/local/profile.toml>.- No
boxGatewayLogsNoticewas yielded. agentcore.jsonis unchanged.
The paths go through join, the test spawns nothing and uses no POSIX modes. The comments ("After the write, so a failed write gives no notice ..." and the boxGatewayLogsWarnings doc naming create and add runtime) match the code.
Earlier comments
- Our nit on the order of the
add runtimenotice (r4638058352). Addressed. The notice now comes after the spec write, andb05116c8tests that order. The author first planned this for PR 5, but it landed here. - Everything else from our earlier reviews was already addressed at
fd93daaf.
Blocking
None.
Non-blocking
- The new test's warning assertion is partly covered by the sibling test just above it, which already checks for no
warningof any kind on the same failedadd runtime. What the new test adds is the box-profile-written check, which shows the failure happens after scaffolding, and the spec-unchanged check. It is fine to keep both. See the inline comment. - Dependency, already known, status update. aws/agentcore-l3-cdk-constructs#470 is still open, not merged. Its head has moved to
2f01972e. This PR still needs #470 merged and released and a CDK pin bump past 1.1.0 before the:-qualified export names and the gatewayenableApplicationLogs/enableTracesfields work end to end.
CI
All checks pass at b05116c8: verify / Linux, verify / Windows, verify / macOS, CodeQL/Analyze and CodeBuild e2e. The GitHub e2e job is skipped, as is usual for this repo.
tejaskash
left a comment
There was a problem hiding this comment.
Thanks, this addresses everything from my review: the lookup now picks one export name from the shared-name count with no fallback, a target under a gateway that isn't deployed shows as not deployed, and create and add runtime say when logs are on. The pair with #470 agrees on names, types, defaults and export names.
Please merge this together with or after aws/agentcore-l3-cdk-constructs#470, not before. And one sentence for the release note: add runtime and export harness also turn logs on for the new Box gateway, so an older Box project that adds a runtime ends up with one gateway logging and one not.
Description
From
sa/gateway-telemetry-fieldsintobox-integration. This PR is the CLI partner ofaws/agentcore-l3-cdk-constructs#470. The plan tells us to
merge each CDK PR "no later than its CLI partner". Thus merge
aws/agentcore-l3-cdk-constructs#470 before this PR, or
at the same time.
This PR has ten commits:
the two new gateway fields.
id of a target name that two gateways have.
enableApplicationLogs: truein the Box gateway of a new Box project.gateway target id only by the export name that the CDK library writes. This is from the review.
test of zod and a comment. This is from the review.
createwarning that a new Box gateway sends its logs. This is from the review.box-integration, because of a conflict in the imports ofcdk.test.ts.box-integrationagain, with no conflict.same warning from
add runtime. This is from the review.target id test with a
_in a gateway name. This is from the review.The CLI does not accept the two new gateway fields
Problem. aws/agentcore-l3-cdk-constructs#470 adds
two optional fields to a gateway entry. When
enableApplicationLogsistrue, the gateway sends itsAPPLICATION_LOGSto CloudWatch Logs. WhenenableTracesistrue, the gateway sends itsTRACESto X-Ray. The CLIgateway schema,
AgentCoreGatewaySchemainsrc/projectSchemas/gateway.ts, is.strict(). Thus the CLI does notaccept a project that sets one of the two fields. A user cannot send the logs or the
TRACESof a gateway, and cannotstop the logs of a Box gateway.
Change.
AgentCoreGatewaySchemahasenableApplicationLogsandenableTracesas optional booleans. Each field hasthe same doc comment as the CDK library schema. The CDK library applies these defaults:
enableApplicationLogs, each gatewayenableTraces, each gatewayTRACEStrueTRACESsentfalseTRACESA new Box gateway sends no logs
Problem. In
aws/agentcore-l3-cdk-constructs#470, the default of
enableApplicationLogsisfalsefor each gateway, also for a gateway withboundRuntime. Thus a Box gateway without the field sends noAPPLICATION_LOGS. The logs areoptional in the CDK library, but they must be on by default for a Box gateway.
Change.
boxGatewaySpecwritesenableApplicationLogs: true.agentcore createuses it for the Box gateway of anew Box project.
agentcore buildchanges only the targets of a Box gateway. Thus afalsethat a user writes stays.Each command that writes a new Box gateway gives a warning for it:
agentcore create, andagentcore add runtimein aBox project. The two use one helper,
boxGatewayLogsWarnings. The warning says that the logs can hold the request andresponse bodies of its calls, prompts and completions included. It also says that CloudWatch Logs keeps them for 90
days, and that
"enableApplicationLogs": falsestops them.A Box project can have one Box gateway with logs and one without.
aws/agentcore-cli#2859 lets
add runtimeadd a box runtime to a Boxproject, and
addBoxRuntimewrites its Box gateway withboxGatewaySpec. Thus, in a Box project from a previous CLI,a runtime that
add runtimeadds gets a Box gateway withenableApplicationLogs: true, and the first Box gateway has nofield. The new gateway has no log group to collide with, and the warning tells the user about the logs.
A Box project from a previous CLI gets no logs. Its Box gateway has no
enableApplicationLogs, andagentcore builddoes not add the field. We accept this for the integration branch. The decision is below, and therelease note tells the user how to get the logs.
Status shows the targets of two Box gateways as
local-onlyProblem. A project with two Box runtimes has two Box gateways. Each Box gateway has a
bedrocktarget, and usuallyan
agentcoretarget. Beforeaws/agentcore-l3-cdk-constructs#470, such a project does
not synthesize. After it, the CDK library adds the gateway name to the export name of a target name that two or more
gateways have:
GatewayTarget-<gateway>:<target>-Id. A target name that only one gateway has keepsGatewayTarget-<target>-Id.identifierOfinsrc/core/project/backends/cdk.tslooks forGatewayTarget-<target>-Idonly. Thus, after a deploy,agentcore project statusshows each shared target aslocal-only.Change.
identifierOfcounts the gateways inspec.agentCoreGatewaysthat have each target name, as the CDKlibrary does. For a target name that two or more gateways have, it looks only for
GatewayTarget-<gateway>:<target>-Id. For a different target name, it looks only forGatewayTarget-<target>-Id.A colon is not in a gateway name or in a target name, thus each export name has one gateway and one target. When the
gateway itself has no deployed id, each of its targets is
local-only.The second commit looked for
GatewayTarget-<gateway>-<target>-Idfirst, and then forGatewayTarget-<target>-Id.Thus a target could get the id of a different target when a name had a hyphen. An example is the gateway
awith thetarget
b, and the gatewaytoolswith the targeta-b. This occurred also with one gateway:toolswith the targetssearchandtools-search. Also, a target of a gateway that was not deployed got the id of a target of a differentgateway with that name. The fourth commit removes these problems.
When a second gateway gets a target name of a deployed gateway, the two targets are
local-onlyuntil the next deploy.The stack has only
GatewayTarget-<target>-Id, and the CLI gives no id rather than the id of a different gateway.Decisions that the diff does not show:
agentcore.json, and a schema defaultadds the field to each project file.
agentcore builddoes not addenableApplicationLogsto a Box gateway that does not have it. Thus a Box project froma previous CLI version gets no new resources from an update of the CDK library. If the build adds the field, the first
deploy after the update makes the log group. When an operator added a console log delivery to that gateway, the log
group exists, and that deploy fails. To get the logs, the user adds
"enableApplicationLogs": trueto the Box gateway.src/projectSchemas/v0is a frozen copy, and this PR does not change it.agentcore add gateway. A user sets the two fields inagentcore.json.Base. This PR starts from
box-integrationat71051b42, the merge of
aws/agentcore-cli#2852. The seventh commit merges
box-integrationat f5503f02, the merge of aws/agentcore-cli#2857,
with aws/agentcore-cli#2853. The fourth commit and that PR changed the
imports of
cdk.test.ts, thus the branch had a conflict. That merge keeps the two imports. The eighth commit mergesbox-integrationat 1405932a, withaws/agentcore-cli#2858 and
aws/agentcore-cli#2859, with no conflict. I did not rebase.
Merge order. Merge aws/agentcore-l3-cdk-constructs#470
before this PR, or at the same time. A release of
@aws/agentcore-cdkwith that change, and an increase of the pin insrc/assets/cdk/package.json(now1.1.0, which does not have that change), must follow. The cause is the gateway schema of the CDK library onbox-integration. It is also.strict(), and it does not have the two fields. Thus, before that change, a project thatsets one of the fields gets through the CLI, but the synth stops. A new Box project has
enableApplicationLogs: true,thus its synth also stops with the CDK library before that change. With the CDK library before that change, the status
of a target name that two or more gateways have is
local-only, because no stack has an export name with a colon.Related Issue
None.
Documentation PR
None. The doc comments in
AgentCoreGatewaySchemagive the two fields. TheREADME.mdofaws/agentcore-l3-cdk-constructs#470 gives the
CloudWatch Transaction Search prerequisite for
enableTraces.Type of Change
Testing
How have you tested the change?
bun teston the head, after the second merge ofbox-integration: 5504 tests in 346 files, with5497 pass,7 skipand0 fail. With nobunonPATH, one test fails before and after the review commits:SourceResolver bytes > waits for delayed process stdin under bun after importing InkstartsbunfromPATH.bun run test:packageon the head: the four npm installations pass.bun run test:e2e, or explained why they are not applicable(CI does not run them for you). I did not do these tests. I did not deploy, and I made no AWS call.
bun run typecheckbun run lint:check: 0 warnings and 0 errors.bun run format:checkbun run audit: 0 vulnerabilities.bun run secrets:checkbun run buildsrc/assets/, I updated affected snapshots withbun test <test-file> --update-snapshotsandcommitted them. I did not change
src/assets/.not record fixtures.
command.md(the release workflow regenerates it)bun.lockdoes not change.Gateway fields.
src/projectSchemas/gateway.test.ts, ingateway application logs and traces, has these tests:trueandfalsefor each field. Each value stays after the CLI writes the spec to JSON and readsit again.
Box gateway logs.
src/core/project/manager.box.test.ts, inagentcore create, makes sure that a Box templatewrites
enableApplicationLogs: truein each Box gateway.src/core/project/manager.boxNetwork.test.ts, in "buildwrites the Box network of the box profile", has the test "keeps the enableApplicationLogs of the Box gateway as the user
wrote it".
agentcore buildkeeps afalse. When the user removes the field, a build that changes the targets doesnot add the field again. The test "create says that the Box gateway sends its logs, and how to stop them" makes sure that
creategives the warning. Inmanager.box.test.ts, eachcreate --templatetest makes sure that a Box template givesthe warning and that a different template does not. The test "add runtime says that the new Box gateway sends its logs,
and how to stop them" makes sure that
add runtimegives the warning for its new gateway only.Target ids.
src/core/project/backends/cdk.test.ts, inCdkBackend.resolveProjectResources, has these tests:One
test.each, with the gateway names ofboxGatewaySpec, has eight tests:bedrocktarget, and one gateway also has anegress-githubtarget. Eachbedrocktarget getsthe id of its own gateway.
egress-githubgets the id from the export name without the gateway.bedrocktarget. The target gets the id from the export name without the gateway.ahas the targetb, and the gatewaytoolshas the targeta-b. Each target gets its own id.toolshas the targetssearchandtools-search. Each target gets its own id.aandxhave the targetb-c, and the gatewaya-bhas the targetc. Each target gets its own id.my_toolsandotherhave the targetsearch. Each target gets its own id, and the export name hasmy-tools.bedrock, and the stack has onlyGatewayTarget-bedrock-Id. No target gets an id.I changed the code to make it incorrect. Each time, the related tests showed an error:
enableApplicationLogsand noenableTracesin the schema: 57 tests.enableApplicationLogs: 1 test.enableApplicationLogs: trueinboxGatewaySpec: 2 tests.agentcore buildwritesenableApplicationLogs: truein the Box gateway at each run: 1 test.agentcore buildwritesenableApplicationLogs: truewhen the Box gateway does not have the field: 1 test.createwarning: 3 tests.add runtimewarning: 1 test.boxGatewayLogsWarnings: 4 tests._to-instackExportName: 2 tests.Checklist
aws/agentcore-l3-cdk-constructs#470 is open.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the
terms of your choice.
Release note
A Box project that an earlier CLI made has a Box gateway with no
enableApplicationLogsfield, so the gateway sends noAPPLICATION_LOGS. To send them, add"enableApplicationLogs": trueto the Box gateway inagentcore/agentcore.json, then deploy.