Skip to content

fix(apisix): use req_headers for active health checks - #541

Open
xiaocanglan1 wants to merge 1 commit into
api7:mainfrom
xiaocanglan1:fix/apisix-health-check-req-headers
Open

fix(apisix): use req_headers for active health checks#541
xiaocanglan1 wants to merge 1 commit into
api7:mainfrom
xiaocanglan1:fix/apisix-health-check-req-headers

Conversation

@xiaocanglan1

@xiaocanglan1 xiaocanglan1 commented Jul 29, 2026

Copy link
Copy Markdown

Description

Apache APISIX defines custom request headers for active upstream health checks as checks.active.req_headers, but ADC currently defines the field as http_request_headers in both its configuration schema and APISIX standalone typing.

Because these schemas use z.strictObject, a valid APISIX configuration containing req_headers is rejected by adc lint, adc sync, and other commands that run the local lint stage. Conversely, the ADC-only field name cannot be accepted by the APISIX upstream schema.

The canonical APISIX field is defined in apisix/schema_def.lua and documented as upstream.checks.active.req_headers.

Environment

  • Affected ADC image: ghcr.io/api7/adc:0.27.1
  • Image digest: sha256:f65f53dd966827ff485471d00b9ce8ca146f7aba187519817b7453e476a274b8
  • ADC base commit tested before the fix: 99142525450f
  • Host: macOS 26.5.1, arm64
  • Docker client/server: 29.5.2 / 28.4.0
  • Node.js: 22.22.3
  • pnpm: 11.17.0

The reproduction only uses adc lint, so it does not require a running APISIX instance.

Why this update is needed

APISIX has used req_headers for active health-check request headers across its supported upstream schema. ADC's http_request_headers name does not match the Admin API/standalone configuration contract.

This mismatch currently requires downstream users to patch the compiled /main.cjs bundle with sed. Fixing the source schemas removes that image-level workaround and keeps ADC configuration validation aligned with APISIX.

How to reproduce

Create adc.yaml:

services:
  - name: health-check-service
    upstream:
      nodes:
        - host: 127.0.0.1
          port: 8080
          weight: 1
      checks:
        active:
          type: http
          http_path: /health
          req_headers:
            - "User-Agent: adc-health-check"

Run ADC 0.27.1:

docker run --rm \
  -v "$PWD/adc.yaml:/work/adc.yaml:ro" \
  ghcr.io/api7/adc:0.27.1 \
  lint -f /work/adc.yaml

Actual result before this change (exit status 1):

The following errors were found in configuration:
✖ Unrecognized key: "req_headers"
  → at services[0].upstream.checks.active

Expected result:

All is well, see you next time!

The locally built CLI with this change returns exit status 0 for the same file.

Changes

  • Rename http_request_headers to req_headers in the SDK upstream schema.
  • Rename the field in APISIX standalone upstream typing.
  • Regenerate schema.json so both inline and referenced upstream definitions expose req_headers.
  • Add a CLI linter regression test that validates an active health check with req_headers.

Verification

pnpm exec vitest run apps/cli/src/linter/specs/upstream.spec.ts \
  --config apps/cli/vitest.config.ts
pnpm exec nx run cli:test --skip-nx-cache
pnpm exec nx run sdk:test --skip-nx-cache
pnpm exec nx run-many --target=typecheck --all --skip-nx-cache
pnpm exec nx run-many --target=lint --all --skip-nx-cache
pnpm exec nx run cli:build --configuration=production --skip-nx-cache

Results:

  • Targeted upstream linter tests: 8 passed.
  • CLI unit tests: 29 passed.
  • SDK unit tests: 11 passed.
  • Type checking: all 7 projects passed.
  • Lint: all targets passed with pre-existing warnings only and no errors.
  • Production CLI build: passed.
  • Built dist/apps/cli/main.cjs: 2 occurrences of req_headers: and 0 occurrences of http_request_headers:.
  • ADC 0.27.1 reproduction: failed as expected with exit status 1.
  • Fixed local build: passed the same configuration with exit status 0.

Compatibility

This intentionally replaces the incorrect ADC-only field name. Configurations using http_request_headers must rename it to req_headers; the old name is not valid in the APISIX upstream schema and cannot be synchronized successfully to APISIX.

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the generated schema documentation to reflect this change
  • I have verified that this change is backward compatible (see compatibility note above)

Summary by CodeRabbit

  • New Features

    • Added support for configuring request headers on HTTPS active health checks using the req_headers setting.
  • Bug Fixes

    • Updated configuration validation to consistently recognize req_headers for services and upstreams.
    • Added validation coverage to ensure valid request-header configurations pass linting.

@xiaocanglan1
xiaocanglan1 requested a review from bzp2010 as a code owner July 29, 2026 11:18
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


chenbowen seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Jul 29, 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 Plus

Run ID: 0ae23dc7-2465-4f3f-ace7-cb6bcf0fd581

📥 Commits

Reviewing files that changed from the base of the PR and between 9914252 and 23e730c.

📒 Files selected for processing (4)
  • apps/cli/src/linter/specs/upstream.spec.ts
  • libs/backend-apisix-standalone/src/typing.ts
  • libs/sdk/src/core/schema.ts
  • schema.json

📝 Walkthrough

Walkthrough

The active health-check request header property is renamed from http_request_headers to req_headers in TypeScript and JSON schemas, with a linter test covering HTTPS upstream configurations.

Changes

Upstream header configuration

Layer / File(s) Summary
Update active health-check schemas
libs/backend-apisix-standalone/src/typing.ts, libs/sdk/src/core/schema.ts, schema.json
The active health-check schemas now define the optional request-header array as req_headers.
Validate req_headers configuration
apps/cli/src/linter/specs/upstream.spec.ts
Adds linter coverage confirming req_headers is accepted for an HTTPS active health check.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: bzp2010

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
E2e Test Quality Review ⚠️ Warning FAIL: the change only adds a unit-style linter case plus schema updates; it doesn't exercise the full CLI/APISIX flow or invalid/edge req_headers cases. Add an end-to-end test that runs the CLI against a real fixture/config path, and include negative/edge req_headers scenarios so the new schema is validated beyond the happy path.
✅ 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 matches the main change: renaming the active health-check header field to req_headers in APISIX-related validation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Security Check ✅ Passed No security-sensitive code paths changed; only schema names/tests were updated, with no logging, auth, DB, or secret-handling logic introduced.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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.

2 participants