Skip to content

fix(service): preserve L4 service type on export#70

Merged
shreemaan-abhishek merged 1 commit into
masterfrom
fix/l4-service-export-type
Jul 8, 2026
Merged

fix(service): preserve L4 service type on export#70
shreemaan-abhishek merged 1 commit into
masterfrom
fix/l4-service-export-type

Conversation

@shreemaan-abhishek

@shreemaan-abhishek shreemaan-abhishek commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Problem

Fixes #69. When exporting services with a7 config dump and syncing them into another gateway group, L4 (stream) service configuration was not carried over completely.

Root cause

config dump deserializes every service into the typed api.Service struct and re-serializes it. Go's encoding/json silently drops any JSON field not declared on the struct, so the struct acts as a field whitelist. api.Service had no type field.

API7 EE marks L4 services with "type": "stream" (stream routes can only bind to stream-typed services). Because type was not modeled, an exported L4 service lost its type, 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 Type field to api.Service so type survives the export round-trip.

Test

Added TestConfigDump_L4ServiceKeepsTypeAndPlugins in pkg/cmd/config/dump/dump_test.go, which dumps a type: stream service carrying a plugin and asserts both type and plugins are preserved. Verified it fails before the fix (exported type is nil) and passes after.

Verification

go build ./...
go vet ./pkg/api/... ./pkg/cmd/config/...
go test ./pkg/cmd/config/... ./pkg/api/... ./pkg/listutil/...

All pass.

Summary by CodeRabbit

  • New Features
    • Added support for preserving a service’s traffic type in API output, including stream vs. HTTP behavior.
  • Bug Fixes
    • Config export now keeps stream service settings intact, including the service type and associated plugins.
  • Tests
    • Added coverage to verify exported configuration retains stream service details during dump operations.

`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
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8281acaf-f0ac-4835-974c-d233c7152a7f

📥 Commits

Reviewing files that changed from the base of the PR and between c0400ff and 945f47b.

📒 Files selected for processing (2)
  • pkg/api/types_service.go
  • pkg/cmd/config/dump/dump_test.go

📝 Walkthrough

Walkthrough

Adds a Type field to the Service struct to distinguish L4 (stream) and L7 (http) services, and adds a test verifying that config dump preserves the type field and L4 plugin configuration for stream services.

Changes

L4 Service Type Preservation

Layer / File(s) Summary
Add Type field to Service struct
pkg/api/types_service.go
Adds a Type string field with json/yaml tags and comments distinguishing L4 (stream) and L7 (http) services; existing field declarations reformatted.
Test coverage for L4 dump behavior
pkg/cmd/config/dump/dump_test.go
Adds a test that mocks a stream service with L4 plugins and asserts dumped JSON output retains the type field and plugin configuration.

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
E2e Test Quality Review ⚠️ Warning The new case is mock-based (httpmock.Registry + mockConfig), so it doesn’t exercise a real API→service→DB/external flow and isn’t E2E. Add a true E2E/integration test that runs a7 config dump against a live API7 test environment with real backing services.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main fix: preserving L4 service type during export.
Linked Issues check ✅ Passed The change addresses #69 by preserving L4 service type and verifying plugins survive config dump export.
Out of Scope Changes check ✅ Passed The edits are limited to the service model and a targeted export test, with no unrelated changes.
Security Check ✅ Passed No new security issues found; changes only add api.Service.Type and a config-dump test, with no auth, logging, secret-storage, or ownership logic altered.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/l4-service-export-type

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Type to api.Service so the service type field is preserved during export.
  • Added a regression test ensuring type: stream services keep both type and plugins in 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.

Comment thread pkg/api/types_service.go
@shreemaan-abhishek shreemaan-abhishek merged commit f0d71e5 into master Jul 8, 2026
7 checks passed
@shreemaan-abhishek shreemaan-abhishek deleted the fix/l4-service-export-type branch July 8, 2026 05:09
@shreemaan-abhishek shreemaan-abhishek self-assigned this Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

L4 service export misses plugin and related configuration

2 participants