-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reverseproxy: restore allowing upstream to contain replaceable placeholders #3776
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,8 +129,12 @@ func (h *Handler) Provision(ctx caddy.Context) error { | |
h.ctx = ctx | ||
h.logger = ctx.Logger(h) | ||
|
||
re := regexp.MustCompile(`\{[[:graph:]]+\}`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not gonna lie, I do hate this 😆 Let me think on this for a bit and see if we can come up with something more elegant... This didn't used to be a problem, right? Did we add code that broke this use case? Can we not remove that code? Or at least change it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, the code added to fix the healthcheck on alternate port requires parsing the network address, which errors out for not having a port when using placeholders. I've moved that part into later in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think there's a way we can fix the original health checking bug without requiring host/port information up front? That would simplify the code, rather than complicate it. |
||
// get validation out of the way | ||
for i, v := range h.Upstreams { | ||
if v.Dial != "" && re.MatchString(v.Dial) && h.HealthChecks != nil && h.HealthChecks.Active != nil { | ||
return fmt.Errorf(`upstream: dial address with placeholders is incompatible with active health checks: %d: {"dial": %q}`, i, v.Dial) | ||
} | ||
// Having LookupSRV non-empty conflicts with 2 other config parameters: active health checks, and upstream dial address. | ||
// Therefore if LookupSRV is empty, then there are no immediately apparent config conflicts, and the iteration can be skipped. | ||
if v.LookupSRV == "" { | ||
|
@@ -219,18 +223,6 @@ func (h *Handler) Provision(ctx caddy.Context) error { | |
|
||
// set up upstreams | ||
for _, upstream := range h.Upstreams { | ||
if upstream.LookupSRV == "" { | ||
addr, err := caddy.ParseNetworkAddress(upstream.Dial) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if addr.PortRangeSize() != 1 { | ||
return fmt.Errorf("multiple addresses (upstream must map to only one address): %v", addr) | ||
} | ||
|
||
upstream.networkAddress = addr | ||
} | ||
// create or get the host representation for this upstream | ||
var host Host = new(upstreamHost) | ||
existingHost, loaded := hosts.LoadOrStore(upstream.String(), host) | ||
|
@@ -288,6 +280,19 @@ func (h *Handler) Provision(ctx caddy.Context) error { | |
} | ||
|
||
for _, upstream := range h.Upstreams { | ||
if upstream.LookupSRV == "" { | ||
addr, err := caddy.ParseNetworkAddress(upstream.Dial) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if addr.PortRangeSize() != 1 { | ||
return fmt.Errorf("multiple addresses (upstream must map to only one address): %v", addr) | ||
} | ||
|
||
upstream.networkAddress = addr | ||
} | ||
|
||
// if there's an alternative port for health-check provided in the config, | ||
// then use it, otherwise use the port of upstream. | ||
if h.HealthChecks.Active.Port != 0 { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this logic/check have to be repeated in the Caddyfile adapter?
(If we keep it, this should be brought out into a package-level variable like
var placeholderPattern = ...
or something, then reused...)