fix(gateway): fix Caddyfile audit config and metrics deprecation#381
fix(gateway): fix Caddyfile audit config and metrics deprecation#381
Conversation
- 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)
WalkthroughThe Caddyfile template is modified to conditionally include Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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.
| {{- /* 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 }} |
There was a problem hiding this comment.
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.
| {{- /* 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.
Summary
topic_nameoption conditional for Gateway >= v2.2.0 (older versions don't support this option and generate topic automatically via$STACK-audit)metricsdirective fromserversblock to global level (servers.metrics is deprecated and will be removed in the next major Caddy version)Context
topic_nameunrecognizedmetricsdeprecatedChanges
internal/resources/gateways/Caddyfile.gotpl: Added version check fortopic_nameand movedmetricsto global levelTest plan
topic_nameerrortopic_nameoption