Skip to content

Commit

Permalink
tracing configuration in apiserversource
Browse files Browse the repository at this point in the history
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
  • Loading branch information
slinkydeveloper committed Apr 21, 2020
1 parent 66186ac commit dad2909
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 14 deletions.
36 changes: 30 additions & 6 deletions pkg/reconciler/apiserversource/apiserversource.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,20 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes"

"knative.dev/eventing/pkg/apis/sources/v1alpha2"
apiserversourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1alpha2/apiserversource"
listers "knative.dev/eventing/pkg/client/listers/sources/v1alpha2"
"knative.dev/eventing/pkg/logging"
"knative.dev/eventing/pkg/reconciler/apiserversource/resources"
"knative.dev/eventing/pkg/utils"
duckv1 "knative.dev/pkg/apis/duck/v1"
"knative.dev/pkg/controller"
pkgLogging "knative.dev/pkg/logging"
"knative.dev/pkg/metrics"
pkgreconciler "knative.dev/pkg/reconciler"
"knative.dev/pkg/resolver"
pkgtracingconfig "knative.dev/pkg/tracing/config"

"knative.dev/eventing/pkg/apis/sources/v1alpha2"
apiserversourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1alpha2/apiserversource"
listers "knative.dev/eventing/pkg/client/listers/sources/v1alpha2"
"knative.dev/eventing/pkg/logging"
"knative.dev/eventing/pkg/reconciler/apiserversource/resources"
"knative.dev/eventing/pkg/utils"
)

const (
Expand Down Expand Up @@ -80,6 +82,7 @@ type Reconciler struct {
loggingContext context.Context
loggingConfig *pkgLogging.Config
metricsConfig *metrics.ExporterOptions
tracingCfg *pkgtracingconfig.Config
}

var _ apiserversourcereconciler.Interface = (*Reconciler)(nil)
Expand Down Expand Up @@ -148,13 +151,19 @@ func (r *Reconciler) createReceiveAdapter(ctx context.Context, src *v1alpha2.Api
logging.FromContext(ctx).Error("error while converting metrics config to json", zap.Any("receiveAdapter", err))
}

tracingCfg, err := pkgtracingconfig.TracingConfigToJson(r.tracingCfg)
if err != nil {
logging.FromContext(ctx).Error("error while converting tracing config to json", zap.Any("receiveAdapter", err))
}

adapterArgs := resources.ReceiveAdapterArgs{
Image: r.receiveAdapterImage,
Source: src,
Labels: resources.Labels(src.Name),
SinkURI: sinkURI,
LoggingConfig: loggingConfig,
MetricsConfig: metricsConfig,
TracingConfig: tracingCfg,
}
expected, err := resources.MakeReceiveAdapter(&adapterArgs)
if err != nil {
Expand Down Expand Up @@ -240,6 +249,21 @@ func (r *Reconciler) UpdateFromMetricsConfigMap(cfg *corev1.ConfigMap) {
logging.FromContext(r.loggingContext).Debug("Update from metrics ConfigMap", zap.Any("ConfigMap", cfg))
}

// TODO determine how to push the updated metrics config to existing data plane Pods.
func (r *Reconciler) UpdateFromTracingConfigMap(cfg *corev1.ConfigMap) {
if cfg != nil {
delete(cfg.Data, "_example")
}

tracingCfg, err := pkgtracingconfig.NewTracingConfigFromMap(cfg.Data)
if err != nil {
logging.FromContext(r.loggingContext).Warn("failed to create tracing config from configmap", zap.String("cfg.Name", cfg.Name))
return
}

r.tracingCfg = tracingCfg
}

func (r *Reconciler) runAccessCheck(src *v1alpha2.ApiServerSource) error {
if src.Spec.Resources == nil || len(src.Spec.Resources) == 0 {
src.Status.MarkSufficientPermissions()
Expand Down
7 changes: 5 additions & 2 deletions pkg/reconciler/apiserversource/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ import (
"knative.dev/pkg/logging"
"knative.dev/pkg/metrics"
"knative.dev/pkg/resolver"
pkgtracingconfig "knative.dev/pkg/tracing/config"

"knative.dev/eventing/pkg/apis/sources/v1alpha1"

apiserversourceinformer "knative.dev/eventing/pkg/client/injection/informers/sources/v1alpha2/apiserversource"
apiserversourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1alpha2/apiserversource"
kubeclient "knative.dev/pkg/client/injection/kube/client"
deploymentinformer "knative.dev/pkg/client/injection/kube/informers/apps/v1/deployment"

apiserversourceinformer "knative.dev/eventing/pkg/client/injection/informers/sources/v1alpha2/apiserversource"
apiserversourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1alpha2/apiserversource"
)

// envConfig will be used to extract the required environment variables using
Expand Down Expand Up @@ -79,6 +81,7 @@ func NewController(

cmw.Watch(logging.ConfigMapName(), r.UpdateFromLoggingConfigMap)
cmw.Watch(metrics.ConfigMapName(), r.UpdateFromMetricsConfigMap)
cmw.Watch(pkgtracingconfig.ConfigName, r.UpdateFromTracingConfigMap)

return impl
}
13 changes: 11 additions & 2 deletions pkg/reconciler/apiserversource/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ import (
"knative.dev/pkg/configmap"
. "knative.dev/pkg/reconciler/testing"

// Fake injection informers
_ "knative.dev/eventing/pkg/client/injection/informers/sources/v1alpha2/apiserversource/fake"
"knative.dev/pkg/client/injection/ducks/duck/v1/addressable"
_ "knative.dev/pkg/client/injection/kube/informers/apps/v1/deployment/fake"

// Fake injection informers
_ "knative.dev/eventing/pkg/client/injection/informers/sources/v1alpha2/apiserversource/fake"
)

func TestNew(t *testing.T) {
Expand All @@ -56,6 +57,14 @@ func TestNew(t *testing.T) {
"loglevel.controller": "info",
"loglevel.webhook": "info",
},
}, &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "config-tracing",
Namespace: "knative-eventing",
},
Data: map[string]string{
"_example": "test-config",
},
}))

if c == nil {
Expand Down
12 changes: 9 additions & 3 deletions pkg/reconciler/apiserversource/resources/receive_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ import (
v1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/eventing/pkg/adapter/apiserver"
"knative.dev/eventing/pkg/apis/sources/v1alpha2"
"knative.dev/pkg/kmeta"
"knative.dev/pkg/system"

"knative.dev/eventing/pkg/adapter/apiserver"
"knative.dev/eventing/pkg/apis/sources/v1alpha2"
)

// ReceiveAdapterArgs are the arguments needed to create a ApiServer Receive Adapter.
Expand All @@ -41,6 +42,7 @@ type ReceiveAdapterArgs struct {
SinkURI string
MetricsConfig string
LoggingConfig string
TracingConfig string
}

// MakeReceiveAdapter generates (but does not insert into K8s) the Receive Adapter Deployment for
Expand Down Expand Up @@ -151,5 +153,9 @@ func makeEnv(args *ReceiveAdapterArgs) ([]corev1.EnvVar, error) {
}, {
Name: "K_LOGGING_CONFIG",
Value: args.LoggingConfig,
}}, nil
},
{
Name: "K_TRACING_CONFIG",
Value: args.TracingConfig,
}}, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import (
v1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/eventing/pkg/apis/sources/v1alpha2"
"knative.dev/pkg/kmeta"

"knative.dev/eventing/pkg/apis/sources/v1alpha2"

_ "knative.dev/pkg/metrics/testing"
_ "knative.dev/pkg/system/testing"
)
Expand Down Expand Up @@ -152,6 +153,10 @@ func TestMakeReceiveAdapter(t *testing.T) {
Name: "K_LOGGING_CONFIG",
Value: "",
},
{
Name: "K_TRACING_CONFIG",
Value: "",
},
},
},
},
Expand Down

0 comments on commit dad2909

Please sign in to comment.