Skip to content

Commit

Permalink
[QE] Extension point for transport used to send events in upgrade tes…
Browse files Browse the repository at this point in the history
…ts (#4815)

* EventSender interface to enable customisation of sending events

* Clean ups

* Basic extendability of wathola sender

* Updating boilerplate

* Testing sender services

* Allow of customization of wathola test images on downstream

* Waiting until test port is open

* Switch to v2 of pelletier/toml to support reading string/map[string]interface{} for interface{} typed field.

* LogLevel is settable

* Logging received event

* Changes after review
  • Loading branch information
cardil authored May 20, 2021
1 parent cf5b0eb commit 5af518d
Show file tree
Hide file tree
Showing 84 changed files with 6,838 additions and 5,420 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ require (
github.com/kelseyhightower/envconfig v1.4.0
github.com/mitchellh/go-homedir v1.1.0
github.com/openzipkin/zipkin-go v0.2.5
github.com/pelletier/go-toml v1.8.0
github.com/pelletier/go-toml/v2 v2.0.0-beta.2
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
github.com/pkg/errors v0.9.1
github.com/rickb777/date v1.13.0
github.com/robfig/cron/v3 v3.0.1
github.com/rogpeppe/fastuuid v1.2.0
github.com/stretchr/testify v1.6.1
github.com/stretchr/testify v1.7.0
github.com/tsenart/vegeta/v12 v12.8.4
github.com/wavesoftware/go-ensure v1.0.0
go.opencensus.io v0.23.0
Expand Down
8 changes: 5 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,10 @@ github.com/openzipkin/zipkin-go v0.2.5/go.mod h1:KpXfKdgRDnnhsxw4pNIH9Md5lyFqKUa
github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pelletier/go-toml v1.8.0 h1:Keo9qb7iRJs2voHvunFtuuYFsbWeOBh8/P9v/kVMFtw=
github.com/pelletier/go-toml v1.8.0/go.mod h1:D6yutnOGMveHEPV7VQOuvI/gXY61bv+9bAOTRnLElKs=
github.com/pelletier/go-toml/v2 v2.0.0-beta.2 h1:f/g66OWmYXmVnYL3UAhqpM9YuWKFR2vjYfFNSDQcHPQ=
github.com/pelletier/go-toml/v2 v2.0.0-beta.2/go.mod h1:+X+aW6gUj6Hda43TeYHVCIvYNG/jqY/8ZFXAeXXHl+Q=
github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac=
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2 h1:JhzVVoYvbOACxoUmOs6V/G4D5nPVUW73rKvXxP4XUJc=
Expand Down Expand Up @@ -620,8 +621,9 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
Expand Down
2 changes: 1 addition & 1 deletion test/test_images/wathola-forwarder/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

func TestForwarderMain(t *testing.T) {
port := freeport.GetPort()
config.Instance.LogLevel = zapcore.DebugLevel
config.Instance.LogLevel = zapcore.DebugLevel.String()
config.Instance.Forwarder.Port = port
go main()
time.Sleep(time.Millisecond)
Expand Down
2 changes: 1 addition & 1 deletion test/test_images/wathola-receiver/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

func TestReceiverMain(t *testing.T) {
port := freeport.GetPort()
config.Instance.LogLevel = zapcore.DebugLevel
config.Instance.LogLevel = zapcore.DebugLevel.String()
config.Instance.Receiver.Port = port
go main()
time.Sleep(time.Millisecond)
Expand Down
2 changes: 1 addition & 1 deletion test/upgrade/prober/config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# logLevel = 5 # DEBUG(5)
# logLevel = 'DEBUG'
[sender]
address = '{{- .BrokerURL -}}'
interval = {{ .Config.Interval.Nanoseconds }}
Expand Down
6 changes: 6 additions & 0 deletions test/upgrade/prober/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"knative.dev/eventing/test/lib/duck"
"knative.dev/eventing/test/lib/resources"
"knative.dev/pkg/apis"
pkgTest "knative.dev/pkg/test"
)

const (
Expand Down Expand Up @@ -70,11 +71,15 @@ type Config struct {
// Wathola represents options related strictly to wathola testing tool.
type Wathola struct {
ConfigMap
ImageResolver
EventsTypePrefix string
HealthEndpoint string
BrokerName string
}

// ImageResolver will resolve the container image for given component.
type ImageResolver func(component string) string

// ConfigMap represents options of wathola config toml file.
type ConfigMap struct {
// ConfigTemplate is a template file that will be compiled to the configmap
Expand Down Expand Up @@ -106,6 +111,7 @@ func NewConfig(namespace string) *Config {
ScaleToZero: true,
},
Wathola: Wathola{
ImageResolver: pkgTest.ImagePath,
ConfigMap: ConfigMap{
ConfigTemplate: defaultConfigFilename,
ConfigMapName: defaultConfigName,
Expand Down
5 changes: 2 additions & 3 deletions test/upgrade/prober/forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
testlib "knative.dev/eventing/test/lib"
"knative.dev/eventing/test/lib/duck"
"knative.dev/eventing/test/lib/resources"
pkgTest "knative.dev/pkg/test"
)

var (
Expand Down Expand Up @@ -75,8 +74,8 @@ func (p *prober) forwarderKService(name, namespace string) *unstructured.Unstruc
"template": map[string]interface{}{
"spec": map[string]interface{}{
"containers": []map[string]interface{}{{
"name": "forwarder",
"image": pkgTest.ImagePath(forwarderName),
"name": forwarderName,
"image": p.config.ImageResolver(forwarderName),
"volumeMounts": []map[string]interface{}{{
"name": p.config.ConfigMapName,
"mountPath": p.config.ConfigMountPoint,
Expand Down
2 changes: 1 addition & 1 deletion test/upgrade/prober/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (p *prober) createReceiverDeployment() *appsv1.Deployment {
}},
Containers: []corev1.Container{{
Name: "receiver",
Image: pkgTest.ImagePath(receiverName),
Image: p.config.ImageResolver(receiverName),
VolumeMounts: []corev1.VolumeMount{{
Name: p.config.ConfigMapName,
ReadOnly: true,
Expand Down
2 changes: 1 addition & 1 deletion test/upgrade/prober/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (p *prober) deploySender(ctx context.Context) {
}},
Containers: []corev1.Container{{
Name: "sender",
Image: pkgTest.ImagePath(senderName),
Image: p.config.ImageResolver(senderName),
VolumeMounts: []corev1.VolumeMount{{
Name: p.config.ConfigMapName,
ReadOnly: true,
Expand Down
2 changes: 1 addition & 1 deletion test/upgrade/prober/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (p *prober) deployFetcher(ctx context.Context) *batchv1.Job {
}},
Containers: []corev1.Container{{
Name: fetcherName,
Image: pkgTest.ImagePath(fetcherName),
Image: p.config.ImageResolver(fetcherName),
VolumeMounts: []corev1.VolumeMount{{
Name: p.config.ConfigMapName,
ReadOnly: true,
Expand Down
2 changes: 1 addition & 1 deletion test/upgrade/prober/wathola/config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ func defaultValues() *Config {
Message: "OK",
Status: nethttp.StatusOK,
},
LogLevel: zap.InfoLevel,
LogLevel: zap.InfoLevel.String(),
}
}
26 changes: 19 additions & 7 deletions test/upgrade/prober/wathola/config/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
package config

import (
"github.com/mitchellh/go-homedir"
"github.com/pelletier/go-toml"
"github.com/wavesoftware/go-ensure"

"os"

"github.com/mitchellh/go-homedir"
"github.com/pelletier/go-toml/v2"
)

var location = "~/.config/wathola/config.toml"
Expand All @@ -29,16 +28,21 @@ var logFatal = Log.Fatal
// ReadIfPresent read a configuration file if it exists
func ReadIfPresent() {
configFile, err := homedir.Expand(location)
ensure.NoError(err)
if err != nil {
logFatal(err)
}
if fileExists(configFile) {
Log.Infof("Reading config file: %v", configFile)
err := Read(configFile)
err = Read(configFile)
if err != nil {
logFatal(err)
}
} else {
Log.Infof("Define config file to be taken into account: %v", configFile)
}
if err = setLogLevel(); err != nil {
logFatal(err)
}
}

// Read a config file and update configuration object
Expand All @@ -48,9 +52,17 @@ func Read(configFile string) error {
return err
}
d := toml.NewDecoder(r)
d.SetStrict(true)
err = d.Decode(Instance)
return err
}

func setLogLevel() error {
err := logConfig.Level.UnmarshalText([]byte(Instance.LogLevel))
if err == nil {
logConfig.Level.SetLevel(Instance.LogLevel)
Instance.LogLevel = logConfig.Level.String()
} else {
Instance.LogLevel = defaultValues().LogLevel
}
return err
}
Expand Down
Loading

0 comments on commit 5af518d

Please sign in to comment.