Skip to content

Commit dca4dfb

Browse files
mgencurknative-prow-robot
authored andcommitted
Wathola Tracing for upgrade tests (knative#6219)
* wathola exposing trace information * Run update-deps.sh * Fix license * Fix import * Ensure backwards compatibility * Assert ParentID not nil in test * Separate old and new events sender APIs * Make loggingCfg in client private * Wait only 1 second for flushing tracing info The Reporter is created with a default batch interval 1 second. So, it should be enough to wait just 1 second because the data is flushed every 1 second. * Increase the sleep time to 1.5 seconds to be safe * The ticker runs every 100ms so it could be 1100 ms until the buffer really flushes. * Use Log.Fatal when tracing is not set up properly * Increase the sleep time to 5 seconds and reference knative/pkg issue
1 parent 4de10c9 commit dca4dfb

File tree

21 files changed

+409
-109
lines changed

21 files changed

+409
-109
lines changed

test/lib/client.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import (
4242

4343
eventing "knative.dev/eventing/pkg/client/clientset/versioned"
4444
"knative.dev/eventing/test/lib/duck"
45-
ti "knative.dev/eventing/test/test_images"
4645
)
4746

4847
// Client holds instances of interfaces for making requests to Knative.
@@ -61,8 +60,8 @@ type Client struct {
6160

6261
podsCreated []string
6362

64-
tracingEnv corev1.EnvVar
65-
loggingEnv *corev1.EnvVar
63+
TracingCfg string
64+
loggingCfg string
6665

6766
cleanup func()
6867
}
@@ -105,12 +104,12 @@ func NewClient(namespace string, t *testing.T) (*Client, error) {
105104
client.EventListener = NewEventListener(client.Kube, client.Namespace, client.T.Logf)
106105
client.Cleanup(client.EventListener.Stop)
107106

108-
client.tracingEnv, err = getTracingConfig(client.Kube)
107+
client.TracingCfg, err = getTracingConfig(client.Kube)
109108
if err != nil {
110109
return nil, err
111110
}
112111

113-
client.loggingEnv, err = getLoggingConfig(client.Kube)
112+
client.loggingCfg, err = getLoggingConfig(client.Kube)
114113
if err != nil {
115114
t.Log("Cannot retrieve the logging config map: ", err)
116115
}
@@ -161,40 +160,40 @@ func getGenericResource(tm metav1.TypeMeta) runtime.Object {
161160
return &duckv1.KResource{}
162161
}
163162

164-
func getTracingConfig(c kubernetes.Interface) (corev1.EnvVar, error) {
163+
func getTracingConfig(c kubernetes.Interface) (string, error) {
165164
cm, err := c.CoreV1().ConfigMaps(system.Namespace()).Get(context.Background(), configtracing.ConfigName, metav1.GetOptions{})
166165
if err != nil {
167-
return corev1.EnvVar{}, fmt.Errorf("error while retrieving the %s config map: %+v", configtracing.ConfigName, errors.WithStack(err))
166+
return "", fmt.Errorf("error while retrieving the %s config map: %+v", configtracing.ConfigName, errors.WithStack(err))
168167
}
169168

170169
config, err := configtracing.NewTracingConfigFromConfigMap(cm)
171170
if err != nil {
172-
return corev1.EnvVar{}, fmt.Errorf("error while parsing the %s config map: %+v", configtracing.ConfigName, errors.WithStack(err))
171+
return "", fmt.Errorf("error while parsing the %s config map: %+v", configtracing.ConfigName, errors.WithStack(err))
173172
}
174173

175174
configSerialized, err := configtracing.TracingConfigToJSON(config)
176175
if err != nil {
177-
return corev1.EnvVar{}, fmt.Errorf("error while serializing the %s config map: %+v", configtracing.ConfigName, errors.WithStack(err))
176+
return "", fmt.Errorf("error while serializing the %s config map: %+v", configtracing.ConfigName, errors.WithStack(err))
178177
}
179178

180-
return corev1.EnvVar{Name: ti.ConfigTracingEnv, Value: configSerialized}, nil
179+
return configSerialized, nil
181180
}
182181

183-
func getLoggingConfig(c kubernetes.Interface) (*corev1.EnvVar, error) {
182+
func getLoggingConfig(c kubernetes.Interface) (string, error) {
184183
cm, err := c.CoreV1().ConfigMaps(system.Namespace()).Get(context.Background(), logging.ConfigMapName(), metav1.GetOptions{})
185184
if err != nil {
186-
return nil, fmt.Errorf("error while retrieving the %s config map: %+v", logging.ConfigMapName(), errors.WithStack(err))
185+
return "", fmt.Errorf("error while retrieving the %s config map: %+v", logging.ConfigMapName(), errors.WithStack(err))
187186
}
188187

189188
config, err := logging.NewConfigFromMap(cm.Data)
190189
if err != nil {
191-
return nil, fmt.Errorf("error while parsing the %s config map: %+v", logging.ConfigMapName(), errors.WithStack(err))
190+
return "", fmt.Errorf("error while parsing the %s config map: %+v", logging.ConfigMapName(), errors.WithStack(err))
192191
}
193192

194193
configSerialized, err := logging.ConfigToJSON(config)
195194
if err != nil {
196-
return nil, fmt.Errorf("error while serializing the %s config map: %+v", logging.ConfigMapName(), errors.WithStack(err))
195+
return "", fmt.Errorf("error while serializing the %s config map: %+v", logging.ConfigMapName(), errors.WithStack(err))
197196
}
198197

199-
return &corev1.EnvVar{Name: ti.ConfigLoggingEnv, Value: configSerialized}, nil
198+
return configSerialized, nil
200199
}

test/lib/creation.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141
"knative.dev/eventing/pkg/utils"
4242
"knative.dev/eventing/test/lib/duck"
4343
"knative.dev/eventing/test/lib/resources"
44+
ti "knative.dev/eventing/test/test_images"
4445
)
4546

4647
// TODO(chizhg): break this file into multiple files when it grows too large.
@@ -566,9 +567,9 @@ func (c *Client) CreateClusterRoleBindingOrFail(saName, crName, crbName string)
566567

567568
func (c *Client) applyAdditionalEnv(pod *corev1.PodSpec) {
568569
for i := 0; i < len(pod.Containers); i++ {
569-
pod.Containers[i].Env = append(pod.Containers[i].Env, c.tracingEnv)
570-
if c.loggingEnv != nil {
571-
pod.Containers[i].Env = append(pod.Containers[i].Env, *c.loggingEnv)
570+
pod.Containers[i].Env = append(pod.Containers[i].Env, corev1.EnvVar{Name: ti.ConfigTracingEnv, Value: c.TracingCfg})
571+
if c.loggingCfg != "" {
572+
pod.Containers[i].Env = append(pod.Containers[i].Env, corev1.EnvVar{Name: ti.ConfigLoggingEnv, Value: c.loggingCfg})
572573
}
573574
}
574575
}

test/upgrade/prober/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# logLevel = 'DEBUG'
2+
tracingConfig = '{{- .TracingConfig -}}'
23
[sender]
34
address = '{{- .Endpoint -}}'
45
interval = {{ .Config.Interval.Nanoseconds }}

test/upgrade/prober/configuration.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package prober
1818
import (
1919
"bytes"
2020
"context"
21-
"errors"
2221
"fmt"
2322
"io/ioutil"
2423
"path"
@@ -27,8 +26,11 @@ import (
2726
"time"
2827

2928
"github.com/kelseyhightower/envconfig"
29+
"github.com/pkg/errors"
3030
"knative.dev/eventing/test/lib/resources"
3131
"knative.dev/eventing/test/upgrade/prober/sut"
32+
"knative.dev/eventing/test/upgrade/prober/wathola/forwarder"
33+
"knative.dev/eventing/test/upgrade/prober/wathola/receiver"
3234
duckv1 "knative.dev/pkg/apis/duck/v1"
3335
pkgTest "knative.dev/pkg/test"
3436
pkgupgrade "knative.dev/pkg/test/upgrade"
@@ -141,9 +143,9 @@ func (p *prober) deployConfiguration() {
141143
Log: p.log,
142144
Client: p.client,
143145
}
144-
ref := resources.KnativeRefForService(receiverName, p.client.Namespace)
146+
ref := resources.KnativeRefForService(receiver.Name, p.client.Namespace)
145147
if p.config.Serving.Use {
146-
ref = resources.KnativeRefForKservice(forwarderName, p.client.Namespace)
148+
ref = resources.KnativeRefForKservice(forwarder.Name, p.client.Namespace)
147149
}
148150
dest := duckv1.Destination{Ref: ref}
149151
s := p.config.SystemUnderTest
@@ -153,19 +155,20 @@ func (p *prober) deployConfiguration() {
153155
tr.Teardown(sc)
154156
}
155157
})
158+
156159
p.deployConfigToml(endpoint)
157160
}
158161

159162
func (p *prober) deployConfigToml(endpoint interface{}) {
160163
name := p.config.ConfigMapName
161164
p.log.Infof("Deploying config map: \"%s/%s\"", p.client.Namespace, name)
162-
configData := p.compileTemplate(p.config.ConfigTemplate, endpoint)
165+
configData := p.compileTemplate(p.config.ConfigTemplate, endpoint, p.client.TracingCfg)
163166
p.client.CreateConfigMapOrFail(name, p.client.Namespace, map[string]string{
164167
p.config.ConfigFilename: configData,
165168
})
166169
}
167170

168-
func (p *prober) compileTemplate(templateName string, endpoint interface{}) string {
171+
func (p *prober) compileTemplate(templateName string, endpoint interface{}, tracingConfig string) string {
169172
_, filename, _, _ := runtime.Caller(0)
170173
templateFilepath := path.Join(path.Dir(filename), templateName)
171174
templateBytes, err := ioutil.ReadFile(templateFilepath)
@@ -177,13 +180,15 @@ func (p *prober) compileTemplate(templateName string, endpoint interface{}) stri
177180
*Config
178181
Namespace string
179182
// Deprecated: use Endpoint
180-
BrokerURL string
181-
Endpoint interface{}
183+
BrokerURL string
184+
Endpoint interface{}
185+
TracingConfig string
182186
}{
183187
p.config,
184188
p.client.Namespace,
185189
fmt.Sprintf("%v", endpoint),
186190
endpoint,
191+
tracingConfig,
187192
}
188193
p.ensureNoError(tmpl.Execute(&buff, data))
189194
return buff.String()

test/upgrade/prober/forwarder.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,35 @@ import (
2323
testlib "knative.dev/eventing/test/lib"
2424
"knative.dev/eventing/test/lib/duck"
2525
"knative.dev/eventing/test/lib/resources"
26-
)
27-
28-
var (
29-
forwarderName = "wathola-forwarder"
26+
"knative.dev/eventing/test/upgrade/prober/wathola/forwarder"
3027
)
3128

3229
func (p *prober) deployForwarder() {
33-
p.log.Infof("Deploy forwarder knative service: %v", forwarderName)
30+
p.log.Infof("Deploy forwarder knative service: %v", forwarder.Name)
3431
serving := p.client.Dynamic.Resource(resources.KServicesGVR).Namespace(p.client.Namespace)
35-
service := p.forwarderKService(forwarderName, p.client.Namespace)
32+
service := p.forwarderKService(forwarder.Name, p.client.Namespace)
3633
if _, err := serving.Create(p.config.Ctx, service, metav1.CreateOptions{}); err != nil {
3734
p.client.T.Fatal(err)
3835
}
3936

4037
sc := p.servingClient()
41-
testlib.WaitFor(fmt.Sprintf("forwarder ksvc be ready: %v", forwarderName), func() error {
42-
return duck.WaitForKServiceReady(sc, forwarderName, p.client.Namespace)
38+
testlib.WaitFor(fmt.Sprintf("forwarder ksvc be ready: %v", forwarder.Name), func() error {
39+
return duck.WaitForKServiceReady(sc, forwarder.Name, p.client.Namespace)
4340
})
4441

4542
if p.config.Serving.ScaleToZero {
46-
testlib.WaitFor(fmt.Sprintf("forwarder scales to zero: %v", forwarderName), func() error {
47-
return duck.WaitForKServiceScales(p.config.Ctx, sc, forwarderName, p.client.Namespace, func(scale int) bool {
43+
testlib.WaitFor(fmt.Sprintf("forwarder scales to zero: %v", forwarder.Name), func() error {
44+
return duck.WaitForKServiceScales(p.config.Ctx, sc, forwarder.Name, p.client.Namespace, func(scale int) bool {
4845
return scale == 0
4946
})
5047
})
5148
}
5249
}
5350

5451
func (p *prober) removeForwarder() {
55-
p.log.Infof("Remove forwarder knative service: %v", forwarderName)
52+
p.log.Infof("Remove forwarder knative service: %v", forwarder.Name)
5653
serving := p.client.Dynamic.Resource(resources.KServicesGVR).Namespace(p.client.Namespace)
57-
err := serving.Delete(p.config.Ctx, forwarderName, metav1.DeleteOptions{})
54+
err := serving.Delete(p.config.Ctx, forwarder.Name, metav1.DeleteOptions{})
5855
p.ensureNoError(err)
5956
}
6057

@@ -73,8 +70,8 @@ func (p *prober) forwarderKService(name, namespace string) *unstructured.Unstruc
7370
"template": map[string]interface{}{
7471
"spec": map[string]interface{}{
7572
"containers": []map[string]interface{}{{
76-
"name": forwarderName,
77-
"image": p.config.ImageResolver(forwarderName),
73+
"name": forwarder.Name,
74+
"image": p.config.ImageResolver(forwarder.Name),
7875
"volumeMounts": []map[string]interface{}{{
7976
"name": p.config.ConfigMapName,
8077
"mountPath": p.config.ConfigMountPoint,

test/upgrade/prober/receiver.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ import (
2222
corev1 "k8s.io/api/core/v1"
2323
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2424
"k8s.io/apimachinery/pkg/util/intstr"
25-
testlib "knative.dev/eventing/test/lib"
26-
watholaconfig "knative.dev/eventing/test/upgrade/prober/wathola/config"
2725
pkgTest "knative.dev/pkg/test"
28-
)
2926

30-
var (
31-
receiverName = "wathola-receiver"
27+
testlib "knative.dev/eventing/test/lib"
28+
watholaconfig "knative.dev/eventing/test/upgrade/prober/wathola/config"
29+
"knative.dev/eventing/test/upgrade/prober/wathola/receiver"
3230
)
3331

3432
func (p *prober) deployReceiver() {
@@ -37,22 +35,22 @@ func (p *prober) deployReceiver() {
3735
}
3836

3937
func (p *prober) deployReceiverDeployment() {
40-
p.log.Info("Deploy of receiver deployment: ", receiverName)
38+
p.log.Info("Deploy of receiver deployment: ", receiver.Name)
4139
deployment := p.createReceiverDeployment()
4240
p.client.CreateDeploymentOrFail(deployment)
4341

44-
testlib.WaitFor(fmt.Sprint("receiver deployment be ready: ", receiverName), func() error {
42+
testlib.WaitFor(fmt.Sprint("receiver deployment be ready: ", receiver.Name), func() error {
4543
return pkgTest.WaitForDeploymentScale(
46-
p.config.Ctx, p.client.Kube, receiverName, p.client.Namespace, 1,
44+
p.config.Ctx, p.client.Kube, receiver.Name, p.client.Namespace, 1,
4745
)
4846
})
4947
}
5048

5149
func (p *prober) deployReceiverService() {
52-
p.log.Infof("Deploy of receiver service: %v", receiverName)
50+
p.log.Infof("Deploy of receiver service: %v", receiver.Name)
5351
service := &corev1.Service{
5452
ObjectMeta: metav1.ObjectMeta{
55-
Name: receiverName,
53+
Name: receiver.Name,
5654
Namespace: p.client.Namespace,
5755
},
5856
Spec: corev1.ServiceSpec{
@@ -68,7 +66,7 @@ func (p *prober) deployReceiverService() {
6866
},
6967
},
7068
Selector: map[string]string{
71-
"app": receiverName,
69+
"app": receiver.Name,
7270
},
7371
Type: corev1.ServiceTypeClusterIP,
7472
},
@@ -80,20 +78,20 @@ func (p *prober) createReceiverDeployment() *appsv1.Deployment {
8078
var replicas int32 = 1
8179
return &appsv1.Deployment{
8280
ObjectMeta: metav1.ObjectMeta{
83-
Name: receiverName,
81+
Name: receiver.Name,
8482
Namespace: p.client.Namespace,
8583
},
8684
Spec: appsv1.DeploymentSpec{
8785
Replicas: &replicas,
8886
Selector: &metav1.LabelSelector{
8987
MatchLabels: map[string]string{
90-
"app": receiverName,
88+
"app": receiver.Name,
9189
},
9290
},
9391
Template: corev1.PodTemplateSpec{
9492
ObjectMeta: metav1.ObjectMeta{
9593
Labels: map[string]string{
96-
"app": receiverName,
94+
"app": receiver.Name,
9795
},
9896
},
9997
Spec: corev1.PodSpec{
@@ -109,7 +107,7 @@ func (p *prober) createReceiverDeployment() *appsv1.Deployment {
109107
}},
110108
Containers: []corev1.Container{{
111109
Name: "receiver",
112-
Image: p.config.ImageResolver(receiverName),
110+
Image: p.config.ImageResolver(receiver.Name),
113111
VolumeMounts: []corev1.VolumeMount{{
114112
Name: p.config.ConfigMapName,
115113
ReadOnly: true,

0 commit comments

Comments
 (0)