Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration for tracing in sources #3026

Merged
merged 4 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/adapter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ type EnvConfig struct {
// TracingConfigJson is a json string of tracing.Config.
// This is used to configure the tracing config, the config is stored in
// a config map inside the controllers namespace and copied here.
TracingConfigJson string `envconfig:"K_TRACING_CONFIG" required:"true"`
// Default is no-op.
TracingConfigJson string `envconfig:"K_TRACING_CONFIG"`
}

// EnvConfigAccessor defines accessors for the minimal
Expand Down
3 changes: 2 additions & 1 deletion pkg/adapter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"knative.dev/pkg/profiling"
"knative.dev/pkg/signals"
"knative.dev/pkg/source"

slinkydeveloper marked this conversation as resolved.
Show resolved Hide resolved
tracingconfig "knative.dev/pkg/tracing/config"

"knative.dev/eventing/pkg/kncloudevents"
Expand Down Expand Up @@ -119,7 +120,7 @@ func MainWithContext(ctx context.Context, component string, ector EnvConfigConst
// Retrieve tracing config
config, err := tracingconfig.JsonToTracingConfig(env.GetTracingConfigJson())
if err != nil {
logger.Warn("failed to create tracing options, using defaults", zap.Error(err))
logger.Warn("Tracing configuration is invalid, using the no-op default", zap.Error(err))
}
if err := tracing.SetupStaticPublishing(logger, component, config); err != nil {
// If tracing doesn't work, we will log an error, but allow the adapter
Expand Down
2 changes: 1 addition & 1 deletion pkg/adapter/main_message_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func MainMessageAdapterWithContext(ctx context.Context, component string, ector
// Retrieve tracing config
config, err := tracingconfig.JsonToTracingConfig(env.GetTracingConfigJson())
if err != nil {
logger.Warn("failed to create tracing options, using defaults", zap.Error(err))
logger.Warn("Tracing configuration is invalid, using the no-op default", zap.Error(err))
}
if err := tracing.SetupStaticPublishing(logger, component, config); err != nil {
// If tracing doesn't work, we will log an error, but allow the adapter
Expand Down
6 changes: 3 additions & 3 deletions pkg/adapter/v2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ type EnvConfig struct {
// TracingConfigJson is a json string of tracing.Config.
// This is used to configure the tracing config, the config is stored in
// a config map inside the controllers namespace and copied here.
TracingConfigJson string `envconfig:"K_TRACING_CONFIG" required:"true"`
// Default is no-op.
TracingConfigJson string `envconfig:"K_TRACING_CONFIG"`
}

// EnvConfigAccessor defines accessors for the minimal
Expand All @@ -89,7 +90,6 @@ type EnvConfigAccessor interface {
// Get the parsed logger.
GetLogger() *zap.SugaredLogger

// Setup tracing
SetupTracing(*zap.SugaredLogger) error

GetCloudEventOverrides() (*duckv1.CloudEventOverrides, error)
Expand Down Expand Up @@ -140,7 +140,7 @@ func (e *EnvConfig) GetName() string {
func (e *EnvConfig) SetupTracing(logger *zap.SugaredLogger) error {
config, err := tracingconfig.JsonToTracingConfig(e.TracingConfigJson)
if err != nil {
logger.Error("Tracing configuration is invalid, using the no-op default", zap.Error(err))
logger.Warn("Tracing configuration is invalid, using the no-op default", zap.Error(err))
}
return tracing.SetupStaticPublishing(logger, e.Component, config)
}
Expand Down
1 change: 0 additions & 1 deletion pkg/adapter/v2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ func MainWithContext(ctx context.Context, component string, ector EnvConfigConst
logger.Error("error building statsreporter", zap.Error(err))
}

// Setup tracing
if err := env.SetupTracing(logger); err != nil {
// If tracing doesn't work, we will log an error, but allow the adapter
// to continue to start.
Expand Down
8 changes: 4 additions & 4 deletions pkg/reconciler/apiserversource/apiserversource.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
"knative.dev/pkg/metrics"
pkgreconciler "knative.dev/pkg/reconciler"
"knative.dev/pkg/resolver"
pkgtracingconfig "knative.dev/pkg/tracing/config"
tracingconfig "knative.dev/pkg/tracing/config"

"knative.dev/eventing/pkg/apis/sources/v1alpha2"
apiserversourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1alpha2/apiserversource"
Expand Down Expand Up @@ -82,7 +82,7 @@ type Reconciler struct {
loggingContext context.Context
loggingConfig *pkgLogging.Config
metricsConfig *metrics.ExporterOptions
tracingCfg *pkgtracingconfig.Config
tracingCfg *tracingconfig.Config
}

var _ apiserversourcereconciler.Interface = (*Reconciler)(nil)
Expand Down Expand Up @@ -151,7 +151,7 @@ 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)
tracingCfg, err := tracingconfig.TracingConfigToJson(r.tracingCfg)
if err != nil {
logging.FromContext(ctx).Error("error while converting tracing config to json", zap.Any("receiveAdapter", err))
}
Expand Down Expand Up @@ -255,7 +255,7 @@ func (r *Reconciler) UpdateFromTracingConfigMap(cfg *corev1.ConfigMap) {
delete(cfg.Data, "_example")
}

tracingCfg, err := pkgtracingconfig.NewTracingConfigFromMap(cfg.Data)
tracingCfg, err := tracingconfig.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
Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciler/apiserversource/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"knative.dev/pkg/logging"
"knative.dev/pkg/metrics"
"knative.dev/pkg/resolver"
pkgtracingconfig "knative.dev/pkg/tracing/config"
tracingconfig "knative.dev/pkg/tracing/config"

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

Expand Down Expand Up @@ -81,7 +81,7 @@ func NewController(

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

return impl
}
8 changes: 4 additions & 4 deletions pkg/reconciler/apiserversource/resources/receive_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ func makeEnv(args *ReceiveAdapterArgs) ([]corev1.EnvVar, error) {
}, {
Name: "K_LOGGING_CONFIG",
Value: args.LoggingConfig,
}, {
Name: "K_TRACING_CONFIG",
Value: args.TracingConfig,
},
{
Name: "K_TRACING_CONFIG",
Value: args.TracingConfig,
}}, nil
}, nil
}