Skip to content

fix(gateway): fix Caddyfile audit config and metrics deprecation#381

Merged
flemzord merged 1 commit intomainfrom
fix/gateway-caddyfile-audit-config
Jan 27, 2026
Merged

fix(gateway): fix Caddyfile audit config and metrics deprecation#381
flemzord merged 1 commit intomainfrom
fix/gateway-caddyfile-audit-config

Conversation

@flemzord
Copy link
Member

Summary

  • Make topic_name option conditional for Gateway >= v2.2.0 (older versions don't support this option and generate topic automatically via $STACK-audit)
  • Move metrics directive from servers block to global level (servers.metrics is deprecated and will be removed in the next major Caddy version)

Context

Problem Minimum Gateway Version Solution
topic_name unrecognized v2.2.0 Make option conditional based on version
metrics deprecated N/A Move to global Caddyfile level

Changes

  • internal/resources/gateways/Caddyfile.gotpl: Added version check for topic_name and moved metrics to global level
  • Updated golden test files to reflect the new Caddyfile structure

Test plan

  • Verify Gateway < v2.2.0 starts without topic_name error
  • Verify Gateway >= v2.2.0 works with topic_name option
  • Verify metrics deprecation warning is resolved
  • CI tests pass

- Make topic_name option conditional for Gateway >= v2.2.0
  (older versions don't support this option and generate topic automatically)
- Move metrics directive from servers block to global level
  (servers.metrics is deprecated and will be removed in next major version)
@flemzord flemzord requested a review from a team as a code owner January 23, 2026 16:12
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 23, 2026

Walkthrough

The Caddyfile template is modified to conditionally include topic_name in the audit block based on gateway version, and the metrics endpoint configuration is relocated from the servers block to a global block.

Changes

Cohort / File(s) Summary
Caddyfile Template Configuration
internal/resources/gateways/Caddyfile.gotpl
Conditional topic_name emission in audit block (v2.2.0+); metrics endpoint moved from servers block to global level

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 Hoppy refactoring day!
Templates now dance with conditions bright,
Metrics leap to global sight,
Version checks guard our audit block right,
Caddyfile prances with delight! 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes both main changes: fixing the Caddyfile audit config (topic_name conditional logic) and addressing metrics deprecation, directly matching the changeset.
Description check ✅ Passed The description is well-structured, directly addresses the changeset with clear explanations of both changes, provides context and rationale, and includes a test plan—fully related to the pull request.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/gateway-caddyfile-audit-config

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@internal/resources/gateways/Caddyfile.gotpl`:
- Around line 15-18: The current template condition emits "topic_name
{$TOPIC_NAME}" when semver_is_valid($values.Gateway.Version) is false, which can
break older/non‑semver Gateways; change the guard so topic_name is only emitted
when semver_is_valid($values.Gateway.Version) is true AND
semver_compare($values.Gateway.Version "v2.2.0") >= 0 (or alternatively add an
explicit opt‑in flag check) — update the conditional around the topic_name block
(the if using semver_is_valid, semver_compare and $values.Gateway.Version) to
require both validity and >= v2.2.0 before rendering topic_name.

Comment on lines +15 to +18
{{- /* topic_name option is only available in Gateway >= v2.2.0 */}}
{{- if or (not (semver_is_valid $values.Gateway.Version)) (ge (semver_compare $values.Gateway.Version "v2.2.0") 0) }}
topic_name {$TOPIC_NAME}
{{- end }}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Fix version gate to avoid breaking non‑semver / older gateways.

Line 16 currently includes topic_name when the version is invalid, which can reintroduce the startup error for older (< v2.2.0) gateways running non‑semver tags. Consider only emitting when the version is valid and ≥ v2.2.0 (or add an explicit opt‑in flag for unknown versions).

🔧 Suggested adjustment
-		{{- if or (not (semver_is_valid $values.Gateway.Version)) (ge (semver_compare $values.Gateway.Version "v2.2.0") 0) }}
+		{{- if and (semver_is_valid $values.Gateway.Version) (ge (semver_compare $values.Gateway.Version "v2.2.0") 0) }}
 		topic_name {$TOPIC_NAME}
 		{{- end }}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{{- /* topic_name option is only available in Gateway >= v2.2.0 */}}
{{- if or (not (semver_is_valid $values.Gateway.Version)) (ge (semver_compare $values.Gateway.Version "v2.2.0") 0) }}
topic_name {$TOPIC_NAME}
{{- end }}
{{- /* topic_name option is only available in Gateway >= v2.2.0 */}}
{{- if and (semver_is_valid $values.Gateway.Version) (ge (semver_compare $values.Gateway.Version "v2.2.0") 0) }}
topic_name {$TOPIC_NAME}
{{- end }}
🤖 Prompt for AI Agents
In `@internal/resources/gateways/Caddyfile.gotpl` around lines 15 - 18, The
current template condition emits "topic_name {$TOPIC_NAME}" when
semver_is_valid($values.Gateway.Version) is false, which can break
older/non‑semver Gateways; change the guard so topic_name is only emitted when
semver_is_valid($values.Gateway.Version) is true AND
semver_compare($values.Gateway.Version "v2.2.0") >= 0 (or alternatively add an
explicit opt‑in flag check) — update the conditional around the topic_name block
(the if using semver_is_valid, semver_compare and $values.Gateway.Version) to
require both validity and >= v2.2.0 before rendering topic_name.

@flemzord flemzord merged commit e04dbba into main Jan 27, 2026
6 checks passed
@flemzord flemzord deleted the fix/gateway-caddyfile-audit-config branch January 27, 2026 09:02
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