fix(service): preserve L4 service type on export#70
Conversation
`a7 config dump` deserializes each service into the typed `api.Service` struct, which acts as a field whitelist: any JSON key not modeled is silently dropped. The struct had no `type` field, so L4 (stream) services, marked by `type: stream`, exported as ordinary L7 services. On sync/import the service was reclassified as HTTP, so its stream routes could no longer bind and its L4 plugin behavior was lost. Model `type` on `api.Service` so it survives the export round-trip. Fixes #69
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds a ChangesL4 Service Type Preservation
Estimated code review effort: 1 (Trivial) | ~5 minutes 🚥 Pre-merge checks | ✅ 5 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
This PR fixes a config export round-trip issue in a7 config dump where L4 (stream) services were losing their "type": "stream" field during (de)serialization, causing them to re-import as L7 (HTTP) services and break stream-route bindings.
Changes:
- Added
Typetoapi.Serviceso the servicetypefield is preserved during export. - Added a regression test ensuring
type: streamservices keep bothtypeandpluginsin dumped output.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/api/types_service.go | Models the type field on api.Service to prevent JSON export from dropping stream service type. |
| pkg/cmd/config/dump/dump_test.go | Adds regression coverage asserting dumped services preserve type and plugins for L4/stream services. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Problem
Fixes #69. When exporting services with
a7 config dumpand syncing them into another gateway group, L4 (stream) service configuration was not carried over completely.Root cause
config dumpdeserializes every service into the typedapi.Servicestruct and re-serializes it. Go'sencoding/jsonsilently drops any JSON field not declared on the struct, so the struct acts as a field whitelist.api.Servicehad notypefield.API7 EE marks L4 services with
"type": "stream"(stream routes can only bind to stream-typed services). Becausetypewas not modeled, an exported L4 service lost itstype, so on sync/import API7 EE reclassified it as an HTTP (L7) service. Its stream routes could then no longer bind and its L4 plugin behavior was effectively lost, which surfaced as "plugin and related configuration missing".Fix
Add the
Typefield toapi.Servicesotypesurvives the export round-trip.Test
Added
TestConfigDump_L4ServiceKeepsTypeAndPluginsinpkg/cmd/config/dump/dump_test.go, which dumps atype: streamservice carrying a plugin and asserts bothtypeandpluginsare preserved. Verified it fails before the fix (exportedtypeisnil) and passes after.Verification
All pass.
Summary by CodeRabbit