Skip to content

Commit a28b2c7

Browse files
k15rnachtmaar
andauthored
deploy event-source-adapter as apps/deployment instead of ksvc (kyma-project#9186)
* replace ksvc by deployment * bump image * update rbac * dd missing files * add simple service test * add more tests * reorder imports * add metrics port * add missing permissions * fix port name must be 15chars or shorter * remove serving from the upgrade test * bump image * fix rbac for upgrade test * add label for podmonitor * update latency dashboard * fix delivery dashboard * fix tracing * Apply suggestions from code review Co-authored-by: Nils Schmidt <[email protected]> * fix comments * remove tracing env var support * dep ensure * fix latency dashboard * fix resources/knative-eventing/charts/event-mesh-dashboard/templates/event-mesh-delivery.yaml * RC from @anishj0shi: Remove dead code and unnecessary type check * Use same cloudevents client in integration test and adapter * Incorporate review comments from sayanh * Incorporate review comments round #2 from sayanh * Remove copy right note in non-autogenerated files * Remove copy right note in autogenerated files (using codegen) * Remove copy right note in resources files * Use Fatal with zap.Error logging * Fix style * Add "Connectivity Validator -> HTTP Source" panel * Incorporate review comments from marcobebway * Add post-upgrade hook to delete orphaned ksvcs * Fix dashboard (order and double graphs in validator->http event source) * Use internal logger * Introduce app label for http source pod for inclusion in pods dashboard * Fix style Co-authored-by: Nils Schmidt <[email protected]> Co-authored-by: Nils Schmidt <[email protected]>
1 parent bde8b99 commit a28b2c7

File tree

102 files changed

+1611
-2177
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+1611
-2177
lines changed

components/event-sources/Gopkg.lock

Lines changed: 13 additions & 85 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/event-sources/Gopkg.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ required = [
1515
revision = "b7391e95e576cacdcdd422573063bc057239113d"
1616

1717
# Direct dependencies
18-
[[constraint]]
19-
name = "knative.dev/serving"
20-
branch = "release-0.12"
2118
[[constraint]]
2219
name = "knative.dev/pkg"
2320
branch = "release-0.12"

components/event-sources/Makefile

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
# Copyright 2019 The Kyma Authors.
2-
#
3-
# Licensed under the Apache License, Version 2.0 (the "License");
4-
# you may not use this file except in compliance with the License.
5-
# You may obtain a copy of the License at
6-
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
8-
#
9-
# Unless required by applicable law or agreed to in writing, software
10-
# distributed under the License is distributed on an "AS IS" BASIS,
11-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
# See the License for the specific language governing permissions and
13-
# limitations under the License.
14-
151
APP_NAME = event-sources
162
APP_PATH = components/event-sources
173
BUILDPACK = eu.gcr.io/kyma-project/test-infra/buildpack-golang-toolbox:v20200423-1d9d6590

components/event-sources/adapter/http/adapter.go

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,32 @@ package http
33
import (
44
"context"
55
"fmt"
6-
"log"
76
"net/http"
7+
"net/url"
88

99
cloudevents "github.com/cloudevents/sdk-go"
10+
cloudeventshttp "github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http"
1011
"github.com/pkg/errors"
1112
"go.opencensus.io/trace"
1213
"go.uber.org/zap"
1314
"knative.dev/eventing/pkg/adapter"
15+
"knative.dev/eventing/pkg/kncloudevents"
1416
"knative.dev/eventing/pkg/utils"
1517
"knative.dev/pkg/logging"
1618
"knative.dev/pkg/source"
17-
"knative.dev/pkg/tracing"
19+
pkgtracing "knative.dev/pkg/tracing"
1820

1921
"github.com/kyma-project/kyma/components/event-sources/apis/sources"
2022
)
2123

24+
var _ adapter.EnvConfigAccessor = (*envConfig)(nil)
25+
2226
type envConfig struct {
2327
adapter.EnvConfig
2428
EventSource string `envconfig:"EVENT_SOURCE" required:"true"`
2529

2630
// PORT as required by knative serving runtime contract
27-
Port int `envconfig:"PORT" required:"true" default:"8080"`
28-
TracingEnabled bool `envconfig:"TRACING_ENABLED" default:"true"`
31+
Port int `envconfig:"PORT" required:"true" default:"8080"`
2932
}
3033

3134
func (e *envConfig) GetSource() string {
@@ -36,10 +39,6 @@ func (e *envConfig) GetPort() int {
3639
return e.Port
3740
}
3841

39-
func (e *envConfig) IsTracingEnabled() bool {
40-
return e.TracingEnabled
41-
}
42-
4342
type httpAdapter struct {
4443
ceClient cloudevents.Client
4544
statsReporter source.StatsReporter
@@ -52,9 +51,13 @@ type AdapterEnvConfigAccessor interface {
5251
adapter.EnvConfigAccessor
5352
GetSource() string
5453
GetPort() int
55-
IsTracingEnabled() bool
5654
}
5755

56+
const (
57+
defaultMaxIdleConnections = 1000
58+
defaultMaxIdleConnectionsPerHost = 1000
59+
)
60+
5861
const resourceGroup = "http." + sources.GroupName
5962

6063
const (
@@ -90,32 +93,49 @@ func NewAdapter(ctx context.Context, processed adapter.EnvConfigAccessor, ceClie
9093
}
9194
}
9295

93-
// Start is the entrypoint for the adapter and is called by sharedmain coming from pkg/adapter
94-
func (h *httpAdapter) Start(_ <-chan struct{}) error {
95-
96-
t, err := cloudevents.NewHTTPTransport(
97-
cloudevents.WithPort(h.accessor.GetPort()),
96+
// NewCloudEventsClient creates a new client for receiving and sending cloud events
97+
func NewCloudEventsClient(port int) (cloudevents.Client, error) {
98+
options := []cloudeventshttp.Option{
99+
cloudevents.WithBinaryEncoding(),
100+
cloudevents.WithMiddleware(pkgtracing.HTTPSpanMiddleware),
101+
cloudevents.WithPort(port),
98102
cloudevents.WithPath(endpointCE),
99103
cloudevents.WithMiddleware(WithReadinessMiddleware),
100-
cloudevents.WithMiddleware(tracing.HTTPSpanMiddleware),
104+
}
105+
106+
httpTransport, err := cloudevents.NewHTTPTransport(
107+
options...,
101108
)
102109
if err != nil {
103-
return errors.Wrap(err, "failed to create transport")
110+
return nil, errors.Wrap(err, "failed to create transport")
104111
}
105112

106-
c, err := cloudevents.NewClient(t)
113+
connectionArgs := kncloudevents.ConnectionArgs{
114+
MaxIdleConns: defaultMaxIdleConnections,
115+
MaxIdleConnsPerHost: defaultMaxIdleConnectionsPerHost,
116+
}
117+
118+
ceClient, err := kncloudevents.NewDefaultClientGivenHttpTransport(
119+
httpTransport,
120+
&connectionArgs)
121+
107122
if err != nil {
108-
return errors.Wrap(err, "failed to create client")
123+
return nil, errors.Wrap(err, "failed to create client")
109124
}
125+
return ceClient, nil
126+
}
127+
128+
// Start is the entrypoint for the adapter and is called by sharedmain coming from pkg/adapter
129+
func (h *httpAdapter) Start(_ <-chan struct{}) error {
110130

111-
log.Printf("listening on :%d%s\n", h.accessor.GetPort(), endpointCE)
131+
h.logger.Info("listening on", zap.String("address", fmt.Sprintf("%d%s", h.accessor.GetPort(), endpointCE)))
112132

113133
// note about graceful shutdown:
114134
// TLDR; StartReceiver unblocks as soon as a stop signal is received
115135
// `StartReceiver` waits internally until `ctx.Done()` does not block anymore
116136
// the context `h.adapterContext` returns a channel (when calling `ctx.Done()`)
117137
// which is closed as soon as a stop signal is received, see https://github.com/knative/pkg/blob/master/signals/signal.go#L37
118-
if err := c.StartReceiver(h.adapterContext, h.serveHTTP); err != nil {
138+
if err := h.ceClient.StartReceiver(h.adapterContext, h.serveHTTP); err != nil {
119139
return errors.Wrap(err, "error occurred while serving")
120140
}
121141
h.logger.Info("adapter stopped")
@@ -176,8 +196,13 @@ func (h *httpAdapter) serveHTTP(ctx context.Context, event cloudevents.Event, re
176196
// Shamelessly copied from https://github.com/knative/eventing/blob/5631d771968bbf00e64988a0e4217c2915ee778e/pkg/broker/ingress/ingress_handler.go#L116
177197
// Due to an issue in utils.ContextFrom, we don't retain the original trace context from ctx, so
178198
// bring it in manually.
179-
sendingCTX := utils.ContextFrom(tctx, nil)
180-
sendingCTX = trace.NewContext(sendingCTX, trace.FromContext(ctx))
199+
uri, err := url.Parse(h.accessor.GetSinkURI())
200+
if err != nil {
201+
return err
202+
}
203+
sendingCTX := utils.ContextFrom(tctx, uri)
204+
trc := trace.FromContext(ctx)
205+
sendingCTX = trace.NewContext(sendingCTX, trc)
181206
rctx, revt, err := h.ceClient.Send(sendingCTX, event)
182207
if err != nil {
183208
h.logger.Error("failed to send cloudevent to sink", zap.Error(err), zap.Any("sink", h.accessor.GetSinkURI()))

components/event-sources/adapter/http/adapter_integration_test.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,11 @@ func TestAdapterShutdown(t *testing.T) {
355355
// used to simulate sending a stop signal
356356
ctx, cancelFunc := context.WithCancel(ctx)
357357

358-
httpAdapter := NewAdapter(ctx, c, nil, nil)
358+
sinkClient, err := kncloudevents.NewDefaultClient(c.GetSinkURI())
359+
if err != nil {
360+
t.Fatal("error building cloud event client", zap.Error(err))
361+
}
362+
httpAdapter := NewAdapter(ctx, c, sinkClient, nil)
359363
stopChannel := make(chan error)
360364

361365
// start adapter
@@ -432,11 +436,12 @@ func waitAdapterReady(t *testing.T, adapterURI string) {
432436
}
433437

434438
// startHttpAdapter starts the adapter with a cloudevents client configured with the test sink as target
435-
func startHttpAdapter(t *testing.T, c adapter.EnvConfigAccessor, ctx context.Context) *adapter.Adapter {
436-
sinkClient, err := kncloudevents.NewDefaultClient(c.GetSinkURI())
439+
func startHttpAdapter(t *testing.T, c *envConfig, ctx context.Context) *adapter.Adapter {
440+
sinkClient, err := NewCloudEventsClient(c.GetPort())
437441
if err != nil {
438-
t.Fatal("error building cloud event client", zap.Error(err))
442+
t.Fatalf("error while creating sinkclient: %+v", err)
439443
}
444+
440445
statsReporter, err := source.NewStatsReporter()
441446
if err != nil {
442447
t.Errorf("error building statsreporter: %v", err)

components/event-sources/apis/sources/register.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
/*
2-
Copyright 2019 The Kyma 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-
171
package sources
182

193
const (

0 commit comments

Comments
 (0)