Skip to content

Commit 0764365

Browse files
knative-prow-robotmgencurcardil
authored
[release-1.3] Backport upgrade event tracing (#6344)
* Wathola Tracing for upgrade tests (#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 * Process empty tracing config in test images (#6289) * Print traces for missed events in upgrade tests (#6249) * Upgrade tests reporting Trace information for missed events * TMP: Induce missed event * Revert "TMP: Induce missed event" This reverts commit 2fec7c7. * Report trace also for Duplicated events * TMP: Induce missed event * TMP: Simulate duplicate events * Fix readme * Unify path for duplicate and missed events * Revert "TMP: Simulate duplicate events" This reverts commit c126521. * Revert "TMP: Induce missed event" This reverts commit fcd9185. * Do not fail upgrade tests if tracing is not configured (#6299) * Do not fail upgrade tests if tracing is not configured * TMP: Do not deploy Knative Monitoring * Revert "TMP: Do not deploy Knative Monitoring" This reverts commit 086a8f9. * Limit the number of exported traces (#6329) Exporting traces for a large number of events can exceed the timeout of the whole test suite, leading to all upgrade tests being reported as failed. * Cleanup Zipkin tracing only once in upgrade test suite (#6331) * NPE fix (#6343) Co-authored-by: Martin Gencur <[email protected]> Co-authored-by: Chris Suszynski <[email protected]>
1 parent 4de10c9 commit 0764365

File tree

29 files changed

+720
-140
lines changed

29 files changed

+720
-140
lines changed

test/config/monitoring/monitoring.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,13 @@ spec:
5353
fieldRef:
5454
apiVersion: v1
5555
fieldPath: metadata.namespace
56+
- name: JAVA_OPTS
57+
value: '-Xms128m -Xmx5G -XX:+ExitOnOutOfMemoryError'
58+
- name: MEM_MAX_SPANS
59+
value: '10000000'
5660
resources:
5761
limits:
58-
memory: 1000Mi
62+
memory: 6Gi
5963
requests:
6064
memory: 256Mi
6165

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/test_images/utils.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,17 @@ const (
5656
ConfigLoggingEnv = "K_CONFIG_LOGGING"
5757
)
5858

59-
// ConfigureTracing can be used in test-images to configure tracing
59+
// ConfigureTracing can be used in test-images to configure tracing.
6060
func ConfigureTracing(logger *zap.SugaredLogger, serviceName string) error {
6161
tracingEnv := os.Getenv(ConfigTracingEnv)
62-
63-
if tracingEnv == "" {
64-
return tracing.SetupStaticPublishing(logger, serviceName, config.NoopConfig())
65-
}
66-
6762
conf, err := config.JSONToTracingConfig(tracingEnv)
6863
if err != nil {
69-
return err
64+
logger.Warn("Error while trying to read the tracing config, using NoopConfig: ", err)
7065
}
71-
7266
return tracing.SetupStaticPublishing(logger, serviceName, conf)
7367
}
7468

75-
// ConfigureTracing can be used in test-images to configure tracing
69+
// ConfigureLogging can be used in test-images to configure logging.
7670
func ConfigureLogging(ctx context.Context, name string) context.Context {
7771
loggingEnv := os.Getenv(ConfigLoggingEnv)
7872
conf, err := logging.JSONToConfig(loggingEnv)

test/upgrade/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,24 @@ struct can be influenced, by using `EVENTING_UPGRADE_TESTS_XXXXX` environmental
119119
variable prefix (using
120120
[kelseyhightower/envconfig](https://github.com/kelseyhightower/envconfig#usage)
121121
usage).
122+
123+
#### Inspecting Zipkin traces for undelivered events
124+
125+
When tracing is enabled in the `config-tracing` config map in the system namespace
126+
the prober collects traces for undelivered events. The traces are exported as json files
127+
under the artifacts dir. Traces for each event are stored in a separate file.
128+
Step event traces are stored as `$ARTIFACTS/traces/missed-events/step-<step_number>.json`
129+
The finished event traces are stored as `$ARTIFACTS/traces/missed-events/finished.json`
130+
131+
Traces can be viewed as follows:
132+
- Start a Zipkin container on localhost:
133+
```
134+
$ docker run -d -p 9411:9411 ghcr.io/openzipkin/zipkin:2
135+
```
136+
- Send traces to the Zipkin endpoint:
137+
```
138+
$ curl -v -X POST localhost:9411/api/v2/spans \
139+
-H 'Content-Type: application/json' \
140+
-d @$ARTIFACTS/traces/missed-events/step-<step_number>.json
141+
```
142+
- View traces in Zipkin UI at `http://localhost:9411/zipkin`

test/upgrade/prober/config.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# logLevel = 'DEBUG'
2+
tracingConfig = '{{- .TracingConfig -}}'
23
[sender]
34
address = '{{- .Endpoint -}}'
45
interval = {{ .Config.Interval.Nanoseconds }}
56
[forwarder]
6-
target = 'http://wathola-receiver.{{- .Namespace -}}.svc.cluster.local'
7+
target = '{{- .ForwarderTarget -}}'

test/upgrade/prober/configuration.go

Lines changed: 17 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"
@@ -49,6 +51,8 @@ const (
4951
Error DuplicateAction = "error"
5052

5153
prefix = "eventing_upgrade_tests"
54+
55+
forwarderTargetFmt = "http://" + receiver.Name + ".%s.svc.cluster.local"
5256
)
5357

5458
var (
@@ -141,9 +145,9 @@ func (p *prober) deployConfiguration() {
141145
Log: p.log,
142146
Client: p.client,
143147
}
144-
ref := resources.KnativeRefForService(receiverName, p.client.Namespace)
148+
ref := resources.KnativeRefForService(receiver.Name, p.client.Namespace)
145149
if p.config.Serving.Use {
146-
ref = resources.KnativeRefForKservice(forwarderName, p.client.Namespace)
150+
ref = resources.KnativeRefForKservice(forwarder.Name, p.client.Namespace)
147151
}
148152
dest := duckv1.Destination{Ref: ref}
149153
s := p.config.SystemUnderTest
@@ -153,19 +157,20 @@ func (p *prober) deployConfiguration() {
153157
tr.Teardown(sc)
154158
}
155159
})
160+
156161
p.deployConfigToml(endpoint)
157162
}
158163

159164
func (p *prober) deployConfigToml(endpoint interface{}) {
160165
name := p.config.ConfigMapName
161166
p.log.Infof("Deploying config map: \"%s/%s\"", p.client.Namespace, name)
162-
configData := p.compileTemplate(p.config.ConfigTemplate, endpoint)
167+
configData := p.compileTemplate(p.config.ConfigTemplate, endpoint, p.client.TracingCfg)
163168
p.client.CreateConfigMapOrFail(name, p.client.Namespace, map[string]string{
164169
p.config.ConfigFilename: configData,
165170
})
166171
}
167172

168-
func (p *prober) compileTemplate(templateName string, endpoint interface{}) string {
173+
func (p *prober) compileTemplate(templateName string, endpoint interface{}, tracingConfig string) string {
169174
_, filename, _, _ := runtime.Caller(0)
170175
templateFilepath := path.Join(path.Dir(filename), templateName)
171176
templateBytes, err := ioutil.ReadFile(templateFilepath)
@@ -175,15 +180,20 @@ func (p *prober) compileTemplate(templateName string, endpoint interface{}) stri
175180
var buff bytes.Buffer
176181
data := struct {
177182
*Config
183+
// Deprecated: use ForwarderTarget
178184
Namespace string
179185
// Deprecated: use Endpoint
180-
BrokerURL string
181-
Endpoint interface{}
186+
BrokerURL string
187+
Endpoint interface{}
188+
TracingConfig string
189+
ForwarderTarget string
182190
}{
183191
p.config,
184192
p.client.Namespace,
185193
fmt.Sprintf("%v", endpoint),
186194
endpoint,
195+
tracingConfig,
196+
fmt.Sprintf(forwarderTargetFmt, p.client.Namespace),
187197
}
188198
p.ensureNoError(tmpl.Execute(&buff, data))
189199
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,

0 commit comments

Comments
 (0)