From 8d9eb1e53442449bb184266100b40329dc15d787 Mon Sep 17 00:00:00 2001 From: Larvan2 <78135608+Larvan2@users.noreply.github.com> Date: Sat, 24 Feb 2024 14:52:42 +0800 Subject: [PATCH] chore: get HealCheckURL from pd if groupOption URL is empty --- adapter/outboundgroup/parser.go | 19 +++++++++++++------ adapter/provider/provider.go | 8 ++++++++ constant/provider/interface.go | 1 + 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/adapter/outboundgroup/parser.go b/adapter/outboundgroup/parser.go index 2fa8d4ec81..96b23eb271 100644 --- a/adapter/outboundgroup/parser.go +++ b/adapter/outboundgroup/parser.go @@ -119,20 +119,27 @@ func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, provide } if len(groupOption.Use) != 0 { - if groupOption.URL == "" { - groupOption.URL = C.DefaultTestURL - } list, err := getProviders(providersMap, groupOption.Use) if err != nil { return nil, fmt.Errorf("%s: %w", groupName, err) } + if groupOption.URL == "" { + for _, p := range list { + if p.HealthCheckURL() != "" { + groupOption.URL = p.HealthCheckURL() + } + break + } + + if groupOption.URL == "" { + groupOption.URL = C.DefaultTestURL + } + } + // different proxy groups use different test URL addTestUrlToProviders(list, groupOption.URL, expectedStatus, groupOption.Filter, uint(groupOption.Interval)) - providers = append(providers, list...) - } else { - groupOption.Filter = "" } var group C.ProxyAdapter diff --git a/adapter/provider/provider.go b/adapter/provider/provider.go index b591538be4..b1209d224a 100644 --- a/adapter/provider/provider.go +++ b/adapter/provider/provider.go @@ -106,6 +106,10 @@ func (pp *proxySetProvider) Touch() { pp.healthCheck.touch() } +func (pp *proxySetProvider) HealthCheckURL() string { + return pp.healthCheck.url +} + func (pp *proxySetProvider) RegisterHealthCheckTask(url string, expectedStatus utils.IntRanges[uint16], filter string, interval uint) { pp.healthCheck.registerHealthCheckTask(url, expectedStatus, filter, interval) } @@ -271,6 +275,10 @@ func (cp *compatibleProvider) Touch() { cp.healthCheck.touch() } +func (cp *compatibleProvider) HealthCheckURL() string { + return cp.healthCheck.url +} + func (cp *compatibleProvider) RegisterHealthCheckTask(url string, expectedStatus utils.IntRanges[uint16], filter string, interval uint) { cp.healthCheck.registerHealthCheckTask(url, expectedStatus, filter, interval) } diff --git a/constant/provider/interface.go b/constant/provider/interface.go index 809db9c512..f2b6939e81 100644 --- a/constant/provider/interface.go +++ b/constant/provider/interface.go @@ -73,6 +73,7 @@ type ProxyProvider interface { HealthCheck() Version() uint32 RegisterHealthCheckTask(url string, expectedStatus utils.IntRanges[uint16], filter string, interval uint) + HealthCheckURL() string } // RuleProvider interface