TUN-4206: Better error message when user is only using one ingress rule
This commit is contained in:
parent
1073f8db40
commit
eed7d7bbc9
|
@ -138,6 +138,11 @@ func (ing Ingress) IsEmpty() bool {
|
||||||
return len(ing.Rules) == 0
|
return len(ing.Rules) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsSingleRule checks if the user only specified a single ingress rule.
|
||||||
|
func (ing Ingress) IsSingleRule() bool {
|
||||||
|
return len(ing.Rules) == 1
|
||||||
|
}
|
||||||
|
|
||||||
// StartOrigins will start any origin services managed by cloudflared, e.g. proxy servers or Hello World.
|
// StartOrigins will start any origin services managed by cloudflared, e.g. proxy servers or Hello World.
|
||||||
func (ing Ingress) StartOrigins(
|
func (ing Ingress) StartOrigins(
|
||||||
wg *sync.WaitGroup,
|
wg *sync.WaitGroup,
|
||||||
|
|
|
@ -19,6 +19,8 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TagHeaderNamePrefix = "Cf-Warp-Tag-"
|
TagHeaderNamePrefix = "Cf-Warp-Tag-"
|
||||||
|
LogFieldCFRay = "cfRay"
|
||||||
|
LogFieldRule = "ingressRule"
|
||||||
)
|
)
|
||||||
|
|
||||||
type proxy struct {
|
type proxy struct {
|
||||||
|
@ -84,7 +86,7 @@ func (p *proxy) Proxy(w connection.ResponseWriter, req *http.Request, sourceConn
|
||||||
|
|
||||||
if sourceConnectionType == connection.TypeHTTP {
|
if sourceConnectionType == connection.TypeHTTP {
|
||||||
if err := p.proxyHTTPRequest(w, req, rule, logFields); err != nil {
|
if err := p.proxyHTTPRequest(w, req, rule, logFields); err != nil {
|
||||||
p.logRequestError(err, cfRay, ruleNum)
|
p.logRequestError(err, cfRay, ruleField(p.ingressRules, ruleNum))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -97,12 +99,19 @@ func (p *proxy) Proxy(w connection.ResponseWriter, req *http.Request, sourceConn
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := p.proxyStreamRequest(serveCtx, w, req, connectionProxy, logFields); err != nil {
|
if err := p.proxyStreamRequest(serveCtx, w, req, connectionProxy, logFields); err != nil {
|
||||||
p.logRequestError(err, cfRay, ruleNum)
|
p.logRequestError(err, cfRay, ruleField(p.ingressRules, ruleNum))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ruleField(ing ingress.Ingress, ruleNum int) string {
|
||||||
|
if ing.IsSingleRule() {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%d", ruleNum)
|
||||||
|
}
|
||||||
|
|
||||||
func (p *proxy) proxyHTTPRequest(w connection.ResponseWriter, req *http.Request, rule *ingress.Rule, fields logFields) error {
|
func (p *proxy) proxyHTTPRequest(w connection.ResponseWriter, req *http.Request, rule *ingress.Rule, fields logFields) error {
|
||||||
// Support for WSGI Servers by switching transfer encoding from chunked to gzip/deflate
|
// Support for WSGI Servers by switching transfer encoding from chunked to gzip/deflate
|
||||||
if rule.Config.DisableChunkedEncoding {
|
if rule.Config.DisableChunkedEncoding {
|
||||||
|
@ -257,13 +266,16 @@ func (p *proxy) logOriginResponse(resp *http.Response, fields logFields) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *proxy) logRequestError(err error, cfRay string, rule interface{}) {
|
func (p *proxy) logRequestError(err error, cfRay string, rule string) {
|
||||||
requestErrors.Inc()
|
requestErrors.Inc()
|
||||||
|
log := p.log.Error().Err(err)
|
||||||
if cfRay != "" {
|
if cfRay != "" {
|
||||||
p.log.Error().Msgf("CF-RAY: %s Proxying to ingress %v error: %v", cfRay, rule, err)
|
log = log.Str(LogFieldCFRay, cfRay)
|
||||||
} else {
|
|
||||||
p.log.Error().Msgf("Proxying to ingress %v error: %v", rule, err)
|
|
||||||
}
|
}
|
||||||
|
if rule != "" {
|
||||||
|
log = log.Str(LogFieldRule, rule)
|
||||||
|
}
|
||||||
|
log.Msg("")
|
||||||
}
|
}
|
||||||
|
|
||||||
func findCfRayHeader(req *http.Request) string {
|
func findCfRayHeader(req *http.Request) string {
|
||||||
|
|
Loading…
Reference in New Issue