Skip to content

Commit 358bed2

Browse files
upgrade to latest dependencies (#157)
Signed-off-by: Knative Automation <[email protected]>
1 parent 51864d4 commit 358bed2

File tree

6 files changed

+118
-41
lines changed

6 files changed

+118
-41
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ require (
2929
k8s.io/client-go v12.0.0+incompatible
3030
k8s.io/code-generator v0.18.8
3131
k8s.io/kube-openapi v0.0.0-20200410145947-bcb3869e6f29
32-
knative.dev/eventing v0.18.1-0.20201103183104-b1706b6c2ddf
32+
knative.dev/eventing v0.18.1-0.20201110092658-746dcf81089c
3333
knative.dev/hack v0.0.0-20201103151104-3d5abc3a0075
3434
knative.dev/pkg v0.0.0-20201103163404-5514ab0c1fdf
3535
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,8 +2048,8 @@ k8s.io/utils v0.0.0-20200603063816-c1c6865ac451 h1:v8ud2Up6QK1lNOKFgiIVrZdMg7Mpm
20482048
k8s.io/utils v0.0.0-20200603063816-c1c6865ac451/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
20492049
knative.dev/caching v0.0.0-20190719140829-2032732871ff/go.mod h1:dHXFU6CGlLlbzaWc32g80cR92iuBSpsslDNBWI8C7eg=
20502050
knative.dev/caching v0.0.0-20200116200605-67bca2c83dfa/go.mod h1:dHXFU6CGlLlbzaWc32g80cR92iuBSpsslDNBWI8C7eg=
2051-
knative.dev/eventing v0.18.1-0.20201103183104-b1706b6c2ddf h1:OHHyNK24URG8feO/TFedPzNt/8mHDJUI2p1G3hRW/DE=
2052-
knative.dev/eventing v0.18.1-0.20201103183104-b1706b6c2ddf/go.mod h1:jwhDgDvoscWE4jWF8cXh7yHfxJcK0mTawVKVfrSjnvg=
2051+
knative.dev/eventing v0.18.1-0.20201110092658-746dcf81089c h1:68sqwFBHltMwtLALmwLSC4O3V5jLvh9jbdAY3fw5d3Q=
2052+
knative.dev/eventing v0.18.1-0.20201110092658-746dcf81089c/go.mod h1:jwhDgDvoscWE4jWF8cXh7yHfxJcK0mTawVKVfrSjnvg=
20532053
knative.dev/eventing-contrib v0.6.1-0.20190723221543-5ce18048c08b/go.mod h1:SnXZgSGgMSMLNFTwTnpaOH7hXDzTFtw0J8OmHflNx3g=
20542054
knative.dev/eventing-contrib v0.11.2/go.mod h1:SnXZgSGgMSMLNFTwTnpaOH7hXDzTFtw0J8OmHflNx3g=
20552055
knative.dev/hack v0.0.0-20201103151104-3d5abc3a0075 h1:YAgWplKIy4O5e3F5vUUECmXAAyZ0M5ymo6fCt1jeZhs=

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
@@ -1025,7 +1025,7 @@ k8s.io/utils/buffer
10251025
k8s.io/utils/integer
10261026
k8s.io/utils/pointer
10271027
k8s.io/utils/trace
1028-
# knative.dev/eventing v0.18.1-0.20201103183104-b1706b6c2ddf
1028+
# knative.dev/eventing v0.18.1-0.20201110092658-746dcf81089c
10291029
## explicit
10301030
knative.dev/eventing/pkg/adapter/v2
10311031
knative.dev/eventing/pkg/adapter/v2/util/crstatusevent

0 commit comments

Comments
 (0)