Skip to content

Commit d123d12

Browse files
Harwayneknative-prow-robot
authored andcommitted
Add tracing to GCP-PubSub Channels, by watching the config-tracing ConfigMap. (#1231)
1 parent 226f815 commit d123d12

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

contrib/gcppubsub/config/gcppubsub.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,39 @@ roleRef:
182182

183183
---
184184

185+
apiVersion: rbac.authorization.k8s.io/v1
186+
kind: Role
187+
metadata:
188+
name: gcp-pubsub-channel-dispatcher
189+
namespace: knative-eventing
190+
rules:
191+
- apiGroups:
192+
- "" # Core API group.
193+
resources:
194+
- configmaps
195+
verbs:
196+
- get
197+
- list
198+
- watch
199+
200+
---
201+
202+
apiVersion: rbac.authorization.k8s.io/v1
203+
kind: RoleBinding
204+
metadata:
205+
name: gcp-pubsub-channel-dispatcher
206+
namespace: knative-eventing
207+
subjects:
208+
- kind: ServiceAccount
209+
name: gcp-pubsub-channel-dispatcher
210+
namespace: knative-eventing
211+
roleRef:
212+
kind: Role
213+
name: gcp-pubsub-channel-dispatcher
214+
apiGroup: rbac.authorization.k8s.io
215+
216+
---
217+
185218
apiVersion: apps/v1
186219
kind: Deployment
187220
metadata:

contrib/gcppubsub/pkg/dispatcher/cmd/main.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ import (
2626
"github.com/knative/eventing/contrib/gcppubsub/pkg/util"
2727
eventingv1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1"
2828
"github.com/knative/eventing/pkg/provisioners"
29+
"github.com/knative/eventing/pkg/tracing"
30+
"github.com/knative/pkg/configmap"
2931
"github.com/knative/pkg/signals"
32+
"github.com/knative/pkg/system"
3033
"go.uber.org/zap"
34+
"k8s.io/client-go/kubernetes"
3135
"sigs.k8s.io/controller-runtime/pkg/client/config"
3236
"sigs.k8s.io/controller-runtime/pkg/manager"
3337
"sigs.k8s.io/controller-runtime/pkg/reconcile"
@@ -59,6 +63,13 @@ func main() {
5963
logger.Fatal("Error adding the eventingv1alpha1 scheme", zap.Error(err))
6064
}
6165

66+
// Zipkin tracing.
67+
kc := kubernetes.NewForConfigOrDie(mgr.GetConfig())
68+
configMapWatcher := configmap.NewInformedWatcher(kc, system.Namespace())
69+
if err = tracing.SetupDynamicZipkinPublishing(logger, configMapWatcher, "gcp-pubsub-dispatcher"); err != nil {
70+
logger.Fatal("Error setting up Zipkin publishing", zap.Error(err))
71+
}
72+
6273
// We are running both the receiver (takes messages in from the cluster and writes them to
6374
// PubSub) and the dispatcher (takes messages in PubSub and sends them in cluster) in this
6475
// binary.
@@ -88,6 +99,11 @@ func main() {
8899
// set up signals so we handle the first shutdown signal gracefully
89100
stopCh := signals.SetupSignalHandler()
90101

102+
// configMapWatcher does not block, so start it first.
103+
if err = configMapWatcher.Start(stopCh); err != nil {
104+
logger.Fatal("Failed to start ConfigMap watcher", zap.Error(err))
105+
}
106+
91107
// Start blocks forever.
92108
logger.Info("Manager starting...")
93109
err = mgr.Start(stopCh)

0 commit comments

Comments
 (0)