Skip to content

Commit 8fcba13

Browse files
upgrade to latest dependencies (#24)
Signed-off-by: Knative Automation <automation@knative.team>
1 parent e4ca3b2 commit 8fcba13

6 files changed

Lines changed: 118 additions & 41 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
k8s.io/api v0.18.8
1313
k8s.io/apimachinery v0.18.8
1414
k8s.io/client-go v11.0.1-0.20190805182717-6502b5e7b1b5+incompatible
15-
knative.dev/eventing v0.18.1-0.20201103183104-b1706b6c2ddf
15+
knative.dev/eventing v0.18.1-0.20201105172507-a6fc5408cb44
1616
knative.dev/hack v0.0.0-20201103151104-3d5abc3a0075
1717
knative.dev/pkg v0.0.0-20201103163404-5514ab0c1fdf
1818
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,8 +1160,8 @@ k8s.io/kube-openapi v0.0.0-20200410145947-bcb3869e6f29/go.mod h1:F+5wygcW0wmRTnM
11601160
k8s.io/utils v0.0.0-20200324210504-a9aa75ae1b89/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
11611161
k8s.io/utils v0.0.0-20200603063816-c1c6865ac451 h1:v8ud2Up6QK1lNOKFgiIVrZdMg7MpmSnvtrOieolJKoE=
11621162
k8s.io/utils v0.0.0-20200603063816-c1c6865ac451/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
1163-
knative.dev/eventing v0.18.1-0.20201103183104-b1706b6c2ddf h1:OHHyNK24URG8feO/TFedPzNt/8mHDJUI2p1G3hRW/DE=
1164-
knative.dev/eventing v0.18.1-0.20201103183104-b1706b6c2ddf/go.mod h1:jwhDgDvoscWE4jWF8cXh7yHfxJcK0mTawVKVfrSjnvg=
1163+
knative.dev/eventing v0.18.1-0.20201105172507-a6fc5408cb44 h1:vgz108o3Br0WfDysXMSD10lcVOl1ZIjkDQa8uFyaeq0=
1164+
knative.dev/eventing v0.18.1-0.20201105172507-a6fc5408cb44/go.mod h1:jwhDgDvoscWE4jWF8cXh7yHfxJcK0mTawVKVfrSjnvg=
11651165
knative.dev/hack v0.0.0-20201103151104-3d5abc3a0075 h1:YAgWplKIy4O5e3F5vUUECmXAAyZ0M5ymo6fCt1jeZhs=
11661166
knative.dev/hack v0.0.0-20201103151104-3d5abc3a0075/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
11671167
knative.dev/pkg v0.0.0-20201103163404-5514ab0c1fdf h1:QwULgRwcv6R3Ya1GZlf/E1atcaGUNw4DKjxSQUfcR6U=

vendor/knative.dev/eventing/pkg/adapter/v2/main_message.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func MainMessageAdapterWithContext(ctx context.Context, component string, ector
108108
logger.Error("Error setting up trace publishing", zap.Error(err))
109109
}
110110

111-
httpBindingsSender, err := kncloudevents.NewHTTPMessageSender(nil, env.GetSink())
111+
httpBindingsSender, err := kncloudevents.NewHTTPMessageSenderWithTarget(env.GetSink())
112112
if err != nil {
113113
logger.Fatal("error building cloud event client", zap.Error(err))
114114
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
Copyright 2020 The Knative Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package kncloudevents
18+
19+
import (
20+
nethttp "net/http"
21+
"sync"
22+
"time"
23+
24+
"go.opencensus.io/plugin/ochttp"
25+
"knative.dev/pkg/tracing/propagation/tracecontextb3"
26+
)
27+
28+
const (
29+
defaultRetryWaitMin = 1 * time.Second
30+
defaultRetryWaitMax = 30 * time.Second
31+
)
32+
33+
type holder struct {
34+
clientMutex sync.Mutex
35+
connectionArgs *ConnectionArgs
36+
client **nethttp.Client
37+
}
38+
39+
var clientHolder = holder{}
40+
41+
// The used HTTP client is a singleton, so the same http client is reused across all the application.
42+
// If connection args is modified, client is cleaned and a new one is created.
43+
func getClient() *nethttp.Client {
44+
clientHolder.clientMutex.Lock()
45+
defer clientHolder.clientMutex.Unlock()
46+
47+
if clientHolder.client == nil {
48+
// Add connection options to the default transport.
49+
var base = nethttp.DefaultTransport.(*nethttp.Transport).Clone()
50+
clientHolder.connectionArgs.configureTransport(base)
51+
c := &nethttp.Client{
52+
// Add output tracing.
53+
Transport: &ochttp.Transport{
54+
Base: base,
55+
Propagation: tracecontextb3.TraceContextEgress,
56+
},
57+
}
58+
clientHolder.client = &c
59+
}
60+
61+
return *clientHolder.client
62+
}
63+
64+
// ConfigureConnectionArgs configures the new connection args.
65+
// The existing client won't be affected, but a new one will be created.
66+
// Use sparingly, because it might lead to creating a lot of clients, none of them sharing their connection pool!
67+
func ConfigureConnectionArgs(ca *ConnectionArgs) {
68+
clientHolder.clientMutex.Lock()
69+
defer clientHolder.clientMutex.Unlock()
70+
71+
// Check if same config
72+
if clientHolder.connectionArgs != nil &&
73+
ca != nil &&
74+
ca.MaxIdleConns == clientHolder.connectionArgs.MaxIdleConns &&
75+
ca.MaxIdleConnsPerHost == clientHolder.connectionArgs.MaxIdleConnsPerHost {
76+
return
77+
}
78+
79+
if clientHolder.client != nil {
80+
// Let's try to clean up a bit the existing client
81+
// Note: this won't remove it nor close it
82+
(*clientHolder.client).CloseIdleConnections()
83+
84+
// Setting client to nil
85+
clientHolder.client = nil
86+
}
87+
88+
clientHolder.connectionArgs = ca
89+
}
90+
91+
// ConnectionArgs allow to configure connection parameters to the underlying
92+
// HTTP Client transport.
93+
type ConnectionArgs struct {
94+
// MaxIdleConns refers to the max idle connections, as in net/http/transport.
95+
MaxIdleConns int
96+
// MaxIdleConnsPerHost refers to the max idle connections per host, as in net/http/transport.
97+
MaxIdleConnsPerHost int
98+
}
99+
100+
func (ca *ConnectionArgs) configureTransport(transport *nethttp.Transport) {
101+
if ca == nil {
102+
return
103+
}
104+
transport.MaxIdleConns = ca.MaxIdleConns
105+
transport.MaxIdleConnsPerHost = ca.MaxIdleConnsPerHost
106+
}

vendor/knative.dev/eventing/pkg/kncloudevents/message_sender.go

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,10 @@ import (
2525

2626
"github.com/hashicorp/go-retryablehttp"
2727
"github.com/rickb777/date/period"
28-
"go.opencensus.io/plugin/ochttp"
29-
"knative.dev/pkg/tracing/propagation/tracecontextb3"
3028

3129
duckv1 "knative.dev/eventing/pkg/apis/duck/v1"
3230
)
3331

34-
const (
35-
defaultRetryWaitMin = 1 * time.Second
36-
defaultRetryWaitMax = 30 * time.Second
37-
)
38-
3932
var noRetries = RetryConfig{
4033
RetryMax: 0,
4134
CheckRetry: func(ctx context.Context, resp *nethttp.Response, err error) (bool, error) {
@@ -46,41 +39,19 @@ var noRetries = RetryConfig{
4639
},
4740
}
4841

49-
// ConnectionArgs allow to configure connection parameters to the underlying
50-
// HTTP Client transport.
51-
type ConnectionArgs struct {
52-
// MaxIdleConns refers to the max idle connections, as in net/http/transport.
53-
MaxIdleConns int
54-
// MaxIdleConnsPerHost refers to the max idle connections per host, as in net/http/transport.
55-
MaxIdleConnsPerHost int
56-
}
57-
58-
func (ca *ConnectionArgs) ConfigureTransport(transport *nethttp.Transport) {
59-
if ca == nil {
60-
return
61-
}
62-
transport.MaxIdleConns = ca.MaxIdleConns
63-
transport.MaxIdleConnsPerHost = ca.MaxIdleConnsPerHost
64-
}
65-
6642
type HTTPMessageSender struct {
6743
Client *nethttp.Client
6844
Target string
6945
}
7046

71-
func NewHTTPMessageSender(connectionArgs *ConnectionArgs, target string) (*HTTPMessageSender, error) {
72-
// Add connection options to the default transport.
73-
var base = nethttp.DefaultTransport.(*nethttp.Transport).Clone()
74-
connectionArgs.ConfigureTransport(base)
75-
// Add output tracing.
76-
client := &nethttp.Client{
77-
Transport: &ochttp.Transport{
78-
Base: base,
79-
Propagation: tracecontextb3.TraceContextEgress,
80-
},
81-
}
47+
// Deprecated: Don't use this anymore, now it has the same effect of NewHTTPMessageSenderWithTarget
48+
// If you need to modify the connection args, use ConfigureConnectionArgs sparingly.
49+
func NewHTTPMessageSender(ca *ConnectionArgs, target string) (*HTTPMessageSender, error) {
50+
return NewHTTPMessageSenderWithTarget(target)
51+
}
8252

83-
return &HTTPMessageSender{Client: client, Target: target}, nil
53+
func NewHTTPMessageSenderWithTarget(target string) (*HTTPMessageSender, error) {
54+
return &HTTPMessageSender{Client: getClient(), Target: target}, nil
8455
}
8556

8657
func (s *HTTPMessageSender) NewCloudEventRequest(ctx context.Context) (*nethttp.Request, error) {

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ k8s.io/utils/buffer
855855
k8s.io/utils/integer
856856
k8s.io/utils/pointer
857857
k8s.io/utils/trace
858-
# knative.dev/eventing v0.18.1-0.20201103183104-b1706b6c2ddf
858+
# knative.dev/eventing v0.18.1-0.20201105172507-a6fc5408cb44
859859
## explicit
860860
knative.dev/eventing/pkg/adapter/v2
861861
knative.dev/eventing/pkg/adapter/v2/test

0 commit comments

Comments
 (0)