From 89bb1173975d7041fbba24bcfee4751af36c1662 Mon Sep 17 00:00:00 2001 From: yusing Date: Wed, 3 Sep 2025 10:32:26 +0800 Subject: [PATCH] feat(route): add ExcludedReason field --- internal/route/route.go | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/internal/route/route.go b/internal/route/route.go index 4c0c762f..31a52a63 100644 --- a/internal/route/route.go +++ b/internal/route/route.go @@ -68,7 +68,8 @@ type ( LisURL *nettypes.URL `json:"lurl,omitempty" swaggertype:"string" extensions:"x-nullable"` ProxyURL *nettypes.URL `json:"purl,omitempty" swaggertype:"string"` - Excluded *bool `json:"excluded"` + Excluded bool `json:"excluded,omitempty" extensions:"x-nullable"` + ExcludedReason string `json:"excluded_reason,omitempty" extensions:"x-nullable"` impl types.Route task *task.Task @@ -258,8 +259,10 @@ func (r *Route) Validate() gperr.Error { } r.impl = impl - excluded := r.ShouldExclude() - r.Excluded = &excluded + r.Excluded = r.ShouldExclude() + if r.Excluded { + r.ExcludedReason = r.GetExcludedReason() + } return nil } @@ -438,8 +441,8 @@ func (r *Route) ShouldExclude() bool { if r.lastError != nil { return true } - if r.Excluded != nil { - return *r.Excluded + if r.Excluded { + return true } if r.Container != nil { switch { @@ -461,6 +464,33 @@ func (r *Route) ShouldExclude() bool { return false } +func (r *Route) GetExcludedReason() string { + if r.lastError != nil { + return string(gperr.Plain(r.lastError)) + } + if r.ExcludedReason != "" { + return r.ExcludedReason + } + if r.Container != nil { + switch { + case r.Container.IsExcluded: + return "Manual exclusion" + case r.IsZeroPort() && !r.UseIdleWatcher(): + return "No port exposed in container" + case !r.Container.IsExplicit && docker.IsBlacklisted(r.Container): + return "Blacklisted (backend service or database)" + case strings.HasPrefix(r.Container.ContainerName, "buildx_"): + return "Buildx" + } + } else if r.IsZeroPort() && r.Scheme != route.SchemeFileServer { + return "No port specified" + } + if strings.HasSuffix(r.Alias, "-old") { + return "Container renaming intermediate state" + } + return "" +} + func (r *Route) UseLoadBalance() bool { return r.LoadBalance != nil && r.LoadBalance.Link != "" }