api7 / api7/adc

DifferV3 does not account for non-round-trippable backend fields, causing unnecessary sync events

Open
#427 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Rust
Stars
70
Forks
15
Avg merge
1h 58m
Merged PRs (30d)
42

Description

Problem

When ADC is used with backends that do not support all SDK-level fields (e.g., backend-api7), DifferV3 produces false diffs every sync cycle because some fields sent in the local state cannot round-trip through the backend.

For example, with backend-api7:

  • route.hosts — API7 EE route model does not have hosts (it is a service-level field)
  • route.remote_addrs — not in API7 EE route typing
  • route.filter_func — not in API7 EE route typing
  • stream_route.sni — not in API7 EE stream_route typing

These fields exist in the ADC SDK schema and are correctly supported by backend-apisix, but backend-api7 transformers (ToADC/FromADC) do not map them. As a result, DifferV3 always detects a diff and triggers PUT requests even when no actual change occurred.

Impact

In Ingress Controller deployments, this causes every route and service to be PUT on every sync cycle (default: every 5 minutes), leading to massive audit log growth (customer case: 8 GB / 4.2M records).

Root Cause

DifferV3 is completely backend-agnostic — it only receives defaultValue from the backend and has no mechanism to know which fields a backend cannot round-trip. The diff comparison includes all fields present in either local or remote state, including fields the backend silently drops.

Proposed Solution

Add an optional normalizeForDiff method to the Backend interface:

interface Backend {
  // ... existing methods ...

  /**
   * Normalize a resource before diff comparison.
   * Called on deep copies of both local and remote resources.
   * Backend should strip fields it cannot round-trip.
   */
  normalizeForDiff?: (
    resourceType: ResourceType,
    resource: object,
  ) => object;
}

DifferV3 would call this normalizer on deep copies of both local and remote items before comparison. BackendAPI7 would implement it to strip non-round-trippable fields. BackendAPISIX would not implement it (all fields are supported).

Non-Round-Trippable Fields Audit (backend-api7)
Resource Field Reason
Route hosts Not in API7 EE route model (service-level)
Route remote_addrs Not in API7 EE route typing
Route filter_func Not in API7 EE route typing
StreamRoute sni Not in API7 EE stream_route typing
Notes on Type-Driven Normalization

backend-api7/src/typing.ts already defines typed interfaces that reflect the supported fields (e.g., typing.Route has no hosts), but these are pure TypeScript interfaces erased at compile time. Future evolution could convert them to Zod schemas for runtime field enumeration.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the Backend interface and DifferV3 comparison path to see where local and remote resources are compared. Inspect backend-api7/src/typing.ts and the backend-api7 ToADC/FromADC transformers for the listed unsupported fields. Done means unsupported fields no longer cause repeated diffs or PUT requests, while backend-apisix behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.