Skip to content

Commit 8713ece

Browse files
authored
Merge branch 'develop' into worktree-fix-service-listeners-lock
2 parents 43c5aea + 01e36da commit 8713ece

26 files changed

Lines changed: 473 additions & 1656 deletions

client/client.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,12 @@ func generateInvocation(ctx context.Context, methodName string, reqs []any, resp
277277
invocation.WithAttachments(attachments),
278278
)
279279
inv.SetAttribute(constant.CallTypeKey, callType)
280+
if opts.ResponseHeader != nil {
281+
inv.SetAttribute(constant.ResponseHeaderKey, opts.ResponseHeader)
282+
}
283+
if opts.ResponseTrailer != nil {
284+
inv.SetAttribute(constant.ResponseTrailerKey, opts.ResponseTrailer)
285+
}
280286

281287
return inv, nil
282288
}

client/client_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package client
2020
import (
2121
"context"
2222
"errors"
23+
"net/http"
2324
"testing"
2425
"time"
2526
)
@@ -146,7 +147,19 @@ func TestConnectionCallPassesOptions(t *testing.T) {
146147
conn := &Connection{refOpts: &ReferenceOptions{invoker: invoker}}
147148

148149
var resp string
149-
res, err := conn.call(context.Background(), []any{"req"}, &resp, "Ping", constant.CallUnary, WithCallRequestTimeout(1500*time.Millisecond), WithCallRetries(3))
150+
var responseHeader http.Header
151+
var responseTrailer http.Header
152+
res, err := conn.call(
153+
context.Background(),
154+
[]any{"req"},
155+
&resp,
156+
"Ping",
157+
constant.CallUnary,
158+
WithCallRequestTimeout(1500*time.Millisecond),
159+
WithCallRetries(3),
160+
WithResponseHeader(&responseHeader),
161+
WithResponseTrailer(&responseTrailer),
162+
)
150163
require.NoError(t, err)
151164
require.Equal(t, invRes, res)
152165

@@ -158,6 +171,14 @@ func TestConnectionCallPassesOptions(t *testing.T) {
158171

159172
requireCallType(t, inv, constant.CallUnary)
160173
require.Equal(t, []any{"req", &resp}, inv.ParameterRawValues())
174+
175+
headerTarget, ok := inv.GetAttribute(constant.ResponseHeaderKey)
176+
require.True(t, ok)
177+
require.Same(t, &responseHeader, headerTarget)
178+
179+
trailerTarget, ok := inv.GetAttribute(constant.ResponseTrailerKey)
180+
require.True(t, ok)
181+
require.Same(t, &responseTrailer, trailerTarget)
161182
}
162183

163184
func TestCallUnary(t *testing.T) {

client/options.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package client
1919

2020
import (
21+
"net/http"
2122
"strconv"
2223
"time"
2324
)
@@ -999,8 +1000,10 @@ func SetClientRouters(routers []*global.RouterConfig) ClientOption {
9991000

10001001
// todo: need to be consistent with MethodConfig
10011002
type CallOptions struct {
1002-
RequestTimeout string
1003-
Retries string
1003+
RequestTimeout string
1004+
Retries string
1005+
ResponseHeader *http.Header
1006+
ResponseTrailer *http.Header
10041007
}
10051008

10061009
type CallOption func(*CallOptions)
@@ -1022,3 +1025,21 @@ func WithCallRetries(retries int) CallOption {
10221025
opts.Retries = strconv.Itoa(retries)
10231026
}
10241027
}
1028+
1029+
// WithResponseHeader configures a target to receive response headers.
1030+
// Currently, only Triple unary calls populate this option (including error
1031+
// responses when metadata is available).
1032+
func WithResponseHeader(header *http.Header) CallOption {
1033+
return func(opts *CallOptions) {
1034+
opts.ResponseHeader = header
1035+
}
1036+
}
1037+
1038+
// WithResponseTrailer configures a target to receive response trailers.
1039+
// Currently, only Triple unary calls populate this option (including error
1040+
// responses when metadata is available).
1041+
func WithResponseTrailer(trailer *http.Header) CallOption {
1042+
return func(opts *CallOptions) {
1043+
opts.ResponseTrailer = trailer
1044+
}
1045+
}

common/constant/key.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ const (
157157
CycleReportKey = "cycle.report"
158158
DefaultBlackListRecoverBlock = 16
159159
CallTypeKey = "call-type"
160+
ResponseHeaderKey = "response-header"
161+
ResponseTrailerKey = "response-trailer"
160162
CallUnary = "unary"
161163
CallClientStream = "client-stream"
162164
CallServerStream = "server-stream"
Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,16 @@
1515
* limitations under the License.
1616
*/
1717

18-
package graceful_shutdown
18+
package constant
1919

2020
import (
21-
"go.uber.org/atomic"
21+
"time"
2222
)
2323

24-
import (
25-
"dubbo.apache.org/dubbo-go/v3/config"
26-
"dubbo.apache.org/dubbo-go/v3/global"
24+
const (
25+
DefaultShutdownConfigTimeout = 60 * time.Second
26+
DefaultShutdownConfigStepTimeout = 3 * time.Second
27+
DefaultShutdownConfigNotifyTimeout = 5 * time.Second
28+
DefaultShutdownConfigConsumerUpdateWaitTime = 3 * time.Second
29+
DefaultShutdownConfigOfflineRequestWindowTimeout = 3 * time.Second
2730
)
28-
29-
func compatGlobalShutdownConfig(c *config.ShutdownConfig) *global.ShutdownConfig {
30-
if c == nil {
31-
return nil
32-
}
33-
cfg := &global.ShutdownConfig{
34-
Timeout: c.Timeout,
35-
StepTimeout: c.StepTimeout,
36-
NotifyTimeout: c.NotifyTimeout,
37-
ConsumerUpdateWaitTime: c.ConsumerUpdateWaitTime,
38-
RejectRequestHandler: c.RejectRequestHandler,
39-
InternalSignal: c.InternalSignal,
40-
OfflineRequestWindowTimeout: c.OfflineRequestWindowTimeout,
41-
RejectRequest: atomic.Bool{},
42-
}
43-
cfg.RejectRequest.Store(c.RejectRequest.Load())
44-
45-
return cfg
46-
}

0 commit comments

Comments
 (0)