Skip to content

Commit

Permalink
Add tracing to GCP-PubSub Channels, by watching the config-tracing Co…
Browse files Browse the repository at this point in the history
…nfigMap. (#1231)
  • Loading branch information
Harwayne authored and knative-prow-robot committed May 14, 2019
1 parent 226f815 commit d123d12
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
33 changes: 33 additions & 0 deletions contrib/gcppubsub/config/gcppubsub.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,39 @@ roleRef:

---

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: gcp-pubsub-channel-dispatcher
namespace: knative-eventing
rules:
- apiGroups:
- "" # Core API group.
resources:
- configmaps
verbs:
- get
- list
- watch

---

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: gcp-pubsub-channel-dispatcher
namespace: knative-eventing
subjects:
- kind: ServiceAccount
name: gcp-pubsub-channel-dispatcher
namespace: knative-eventing
roleRef:
kind: Role
name: gcp-pubsub-channel-dispatcher
apiGroup: rbac.authorization.k8s.io

---

apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down
16 changes: 16 additions & 0 deletions contrib/gcppubsub/pkg/dispatcher/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ import (
"github.com/knative/eventing/contrib/gcppubsub/pkg/util"
eventingv1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1"
"github.com/knative/eventing/pkg/provisioners"
"github.com/knative/eventing/pkg/tracing"
"github.com/knative/pkg/configmap"
"github.com/knative/pkg/signals"
"github.com/knative/pkg/system"
"go.uber.org/zap"
"k8s.io/client-go/kubernetes"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
Expand Down Expand Up @@ -59,6 +63,13 @@ func main() {
logger.Fatal("Error adding the eventingv1alpha1 scheme", zap.Error(err))
}

// Zipkin tracing.
kc := kubernetes.NewForConfigOrDie(mgr.GetConfig())
configMapWatcher := configmap.NewInformedWatcher(kc, system.Namespace())
if err = tracing.SetupDynamicZipkinPublishing(logger, configMapWatcher, "gcp-pubsub-dispatcher"); err != nil {
logger.Fatal("Error setting up Zipkin publishing", zap.Error(err))
}

// We are running both the receiver (takes messages in from the cluster and writes them to
// PubSub) and the dispatcher (takes messages in PubSub and sends them in cluster) in this
// binary.
Expand Down Expand Up @@ -88,6 +99,11 @@ func main() {
// set up signals so we handle the first shutdown signal gracefully
stopCh := signals.SetupSignalHandler()

// configMapWatcher does not block, so start it first.
if err = configMapWatcher.Start(stopCh); err != nil {
logger.Fatal("Failed to start ConfigMap watcher", zap.Error(err))
}

// Start blocks forever.
logger.Info("Manager starting...")
err = mgr.Start(stopCh)
Expand Down

0 comments on commit d123d12

Please sign in to comment.