From e796d443527f297f151947a5d4f873b907983b7f Mon Sep 17 00:00:00 2001 From: duanliguo Date: Tue, 12 Mar 2024 18:43:17 +0800 Subject: [PATCH] Support setting response header timeout --- bce/config.go | 2 +- http/client.go | 19 +++++++++++++++++++ services/cfc/api/cfc.go | 1 + services/cfc/api/model.go | 2 ++ services/scs/model.go | 6 +++--- 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/bce/config.go b/bce/config.go index 38a4ae63..73b082f2 100644 --- a/bce/config.go +++ b/bce/config.go @@ -26,7 +26,7 @@ import ( // Constants and default values for the package bce const ( - SDK_VERSION = "0.9.168" + SDK_VERSION = "0.9.169" URI_PREFIX = "/" // now support uri without prefix "v1" so just set root path DEFAULT_DOMAIN = "baidubce.com" DEFAULT_PROTOCOL = "http" diff --git a/http/client.go b/http/client.go index b036a403..fe0fa4db 100644 --- a/http/client.go +++ b/http/client.go @@ -172,3 +172,22 @@ func Execute(request *Request) (*Response, error) { response := &Response{httpResponse, end.Sub(start)} return response, nil } +func SetResponseHeaderTimeout(t int) { + transport = &http.Transport{ + MaxIdleConnsPerHost: defaultMaxIdleConnsPerHost, + ResponseHeaderTimeout: time.Duration(t) * time.Second, + Dial: func(network, address string) (net.Conn, error) { + conn, err := net.DialTimeout(network, address, defaultDialTimeout) + if err != nil { + return nil, err + } + tc := &timeoutConn{conn, defaultSmallInterval, defaultLargeInterval} + err = tc.SetReadDeadline(time.Now().Add(defaultLargeInterval)) + if err != nil { + return nil, err + } + return tc, nil + }, + } + httpClient.Transport = transport +} diff --git a/services/cfc/api/cfc.go b/services/cfc/api/cfc.go index b8c3de06..76bd14a1 100644 --- a/services/cfc/api/cfc.go +++ b/services/cfc/api/cfc.go @@ -260,6 +260,7 @@ func Invocations(cli bce.Client, args *InvocationsArgs) (*InvocationsResult, err } req := &bce.BceRequest{} + http.SetResponseHeaderTimeout(DefaultMaxFunctionTimeout) req.SetRequestId(args.RequestId) req.SetUri(getInvocationsUri(args.FunctionName)) req.SetMethod(http.POST) diff --git a/services/cfc/api/model.go b/services/cfc/api/model.go index e39520c7..82ac96bf 100644 --- a/services/cfc/api/model.go +++ b/services/cfc/api/model.go @@ -27,6 +27,8 @@ const ( InvocationTypeEvent InvocationType = "Event" InvocationTypeRequestResponse InvocationType = "RequestResponse" InvocationTypeDryRun InvocationType = "DryRun" + // 同步调用函数最大超时时间 + DefaultMaxFunctionTimeout = 300 LogTypeTail LogType = "Tail" LogTypeNone LogType = "None" diff --git a/services/scs/model.go b/services/scs/model.go index db84c2f6..91873fef 100644 --- a/services/scs/model.go +++ b/services/scs/model.go @@ -168,7 +168,7 @@ type UpdateInstanceNameArgs struct { } type NodeType struct { - InstanceFlavor int `json:"instanceFlavor"` + InstanceFlavor float64 `json:"instanceFlavor"` NodeType string `json:"nodeType"` CPUNum int `json:"cpuNum"` NetworkThroughputInGbps float64 `json:"networkThroughputInGbps"` @@ -596,7 +596,7 @@ type GroupLeaderInfo struct { TotalCapacityInGB float64 `json:"totalCapacityInGB"` UsedCapacityInGB int `json:"usedCapacityInGB"` ShardNum int `json:"shardNum"` - Flavor int `json:"flavor"` + Flavor float64 `json:"flavor"` QpsWrite int64 `json:"qpsWrite"` QpsRead int64 `json:"qpsRead"` StableReadable bool `json:"stableReadable"` @@ -612,7 +612,7 @@ type GroupFollowerInfo struct { TotalCapacityInGB float64 `json:"totalCapacityInGB"` UsedCapacityInGB int `json:"usedCapacityInGB"` ShardNum int `json:"shardNum"` - Flavor int `json:"flavor"` + Flavor float64 `json:"flavor"` QpsWrite int64 `json:"qpsWrite"` QpsRead int64 `json:"qpsRead"` StableReadable bool `json:"stableReadable"`