Skip to content

Commit

Permalink
chore: get HealCheckURL from pd if groupOption URL is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Larvan2 committed Feb 25, 2024
1 parent d2a5376 commit 8d9eb1e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
19 changes: 13 additions & 6 deletions adapter/outboundgroup/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions adapter/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions constant/provider/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8d9eb1e

Please sign in to comment.