mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/yunionio/cloudpods.git
synced 2026-09-20 08:03:53 +08:00
fix(aiproxy): detect listen address (#25679)
This commit is contained in:
@@ -20,10 +20,12 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/rbacscope"
|
||||
"yunion.io/x/sqlchemy"
|
||||
@@ -35,6 +37,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/netutils2"
|
||||
"yunion.io/x/onecloud/pkg/util/stringutils2"
|
||||
)
|
||||
|
||||
@@ -162,6 +165,10 @@ func aiProxyNodeDisplayName(address string) string {
|
||||
return u.Host
|
||||
}
|
||||
|
||||
// detectLocalAdvertiseIP resolves a non-loopback local IP for advertise address.
|
||||
// Overridable in tests.
|
||||
var detectLocalAdvertiseIP = netutils2.MyIPSmart
|
||||
|
||||
// AdvertiseAddressFromOptions returns the service URL advertised by this instance.
|
||||
func AdvertiseAddressFromOptions(opts *options.SAiProxyOptions) (string, error) {
|
||||
if opts == nil {
|
||||
@@ -175,10 +182,16 @@ func AdvertiseAddressFromOptions(opts *options.SAiProxyOptions) (string, error)
|
||||
scheme = "https"
|
||||
}
|
||||
host := strings.TrimSpace(opts.Address)
|
||||
if host == "" || host == "0.0.0.0" {
|
||||
host = "127.0.0.1"
|
||||
if host == "" || host == "0.0.0.0" || host == "::" {
|
||||
ip, err := detectLocalAdvertiseIP()
|
||||
if err != nil || strings.TrimSpace(ip) == "" {
|
||||
log.Warningf("detect local advertise IP failed, fallback to 127.0.0.1: %v", err)
|
||||
host = "127.0.0.1"
|
||||
} else {
|
||||
host = ip
|
||||
}
|
||||
}
|
||||
return normalizeAiProxyNodeAddress(fmt.Sprintf("%s://%s:%d", scheme, host, opts.Port))
|
||||
return normalizeAiProxyNodeAddress(fmt.Sprintf("%s://%s", scheme, net.JoinHostPort(host, strconv.Itoa(opts.Port))))
|
||||
}
|
||||
|
||||
// AccessAddressFromApiServer derives ai_proxy_node.access_address from --api-server.
|
||||
|
||||
@@ -22,7 +22,7 @@ type SAiProxyOptions struct {
|
||||
common_options.CommonOptions
|
||||
common_options.DBOptions
|
||||
|
||||
AdvertiseAddress string `help:"Standby node address advertised to clients, e.g. http://10.0.0.2:30889; default derives from bind address and port" default:""`
|
||||
AdvertiseAddress string `help:"Standby node address advertised to clients, e.g. http://10.0.0.2:30889; default derives from bind address or local NIC IP and port" default:""`
|
||||
NodeHeartbeatIntervalSeconds int `help:"Interval in seconds for standby node registration heartbeat" default:"60"`
|
||||
|
||||
APILogEnabled bool `help:"Enable OpenAI API request JSONL logs" default:"true"`
|
||||
|
||||
Reference in New Issue
Block a user