Skip to content

Commit

Permalink
Wrap component opts for exporter and processor
Browse files Browse the repository at this point in the history
  • Loading branch information
punya committed Mar 26, 2021
1 parent d9b2c4b commit a84536e
Show file tree
Hide file tree
Showing 9 changed files with 301 additions and 38 deletions.
16 changes: 4 additions & 12 deletions exporter/exporterhelper/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,11 @@ func fromOptions(options []Option) *baseSettings {
// Option apply changes to baseSettings.
type Option func(*baseSettings)

// WithStart overrides the default Start function for an exporter.
// The default shutdown function does nothing and always returns nil.
func WithStart(start componenthelper.Start) Option {
// WithComponentOptions adds options that apply to a generic component
// (such as start and shutdown hooks).
func WithComponentOptions(opts ...componenthelper.Option) Option {
return func(o *baseSettings) {
o.componentOptions = append(o.componentOptions, componenthelper.WithStart(start))
}
}

// WithShutdown overrides the default Shutdown function for an exporter.
// The default shutdown function does nothing and always returns nil.
func WithShutdown(shutdown componenthelper.Shutdown) Option {
return func(o *baseSettings) {
o.componentOptions = append(o.componentOptions, componenthelper.WithShutdown(shutdown))
o.componentOptions = append(o.componentOptions, opts...)
}
}

Expand Down
7 changes: 5 additions & 2 deletions exporter/jaegerexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"google.golang.org/grpc/metadata"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenthelper"
"go.opentelemetry.io/collector/consumer/consumererror"
"go.opentelemetry.io/collector/consumer/pdata"
"go.opentelemetry.io/collector/exporter/exporterhelper"
Expand Down Expand Up @@ -60,8 +61,10 @@ func newTraceExporter(cfg *Config, logger *zap.Logger) (component.TracesExporter
)
exp, err := exporterhelper.NewTraceExporter(
cfg, logger, s.pushTraceData,
exporterhelper.WithStart(s.start),
exporterhelper.WithShutdown(s.shutdown),
exporterhelper.WithComponentOptions(
componenthelper.WithStart(s.start),
componenthelper.WithShutdown(s.shutdown),
),
exporterhelper.WithTimeout(cfg.TimeoutSettings),
exporterhelper.WithRetry(cfg.RetrySettings),
exporterhelper.WithQueue(cfg.QueueSettings),
Expand Down
5 changes: 3 additions & 2 deletions exporter/kafkaexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"time"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenthelper"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/exporter/exporterhelper"
)
Expand Down Expand Up @@ -115,7 +116,7 @@ func (f *kafkaExporterFactory) createTraceExporter(
exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: 0}),
exporterhelper.WithRetry(oCfg.RetrySettings),
exporterhelper.WithQueue(oCfg.QueueSettings),
exporterhelper.WithShutdown(exp.Close))
exporterhelper.WithComponentOptions(componenthelper.WithShutdown(exp.Close)))
}

func (f *kafkaExporterFactory) createMetricsExporter(
Expand All @@ -140,5 +141,5 @@ func (f *kafkaExporterFactory) createMetricsExporter(
exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: 0}),
exporterhelper.WithRetry(oCfg.RetrySettings),
exporterhelper.WithQueue(oCfg.QueueSettings),
exporterhelper.WithShutdown(exp.Close))
exporterhelper.WithComponentOptions(componenthelper.WithShutdown(exp.Close)))
}
7 changes: 4 additions & 3 deletions exporter/loggingexporter/logging_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"go.uber.org/zap"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenthelper"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/consumer/pdata"
"go.opentelemetry.io/collector/exporter/exporterhelper"
Expand Down Expand Up @@ -420,7 +421,7 @@ func newTraceExporter(config config.Exporter, level string, logger *zap.Logger)
exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: 0}),
exporterhelper.WithRetry(exporterhelper.RetrySettings{Enabled: false}),
exporterhelper.WithQueue(exporterhelper.QueueSettings{Enabled: false}),
exporterhelper.WithShutdown(loggerSync(logger)),
exporterhelper.WithComponentOptions(componenthelper.WithShutdown(loggerSync(logger))),
)
}

Expand All @@ -440,7 +441,7 @@ func newMetricsExporter(config config.Exporter, level string, logger *zap.Logger
exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: 0}),
exporterhelper.WithRetry(exporterhelper.RetrySettings{Enabled: false}),
exporterhelper.WithQueue(exporterhelper.QueueSettings{Enabled: false}),
exporterhelper.WithShutdown(loggerSync(logger)),
exporterhelper.WithComponentOptions(componenthelper.WithShutdown(loggerSync(logger))),
)
}

Expand All @@ -460,7 +461,7 @@ func newLogsExporter(config config.Exporter, level string, logger *zap.Logger) (
exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: 0}),
exporterhelper.WithRetry(exporterhelper.RetrySettings{Enabled: false}),
exporterhelper.WithQueue(exporterhelper.QueueSettings{Enabled: false}),
exporterhelper.WithShutdown(loggerSync(logger)),
exporterhelper.WithComponentOptions(componenthelper.WithShutdown(loggerSync(logger))),
)
}

Expand Down
5 changes: 3 additions & 2 deletions exporter/opencensusexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenthelper"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configgrpc"
"go.opentelemetry.io/collector/exporter/exporterhelper"
Expand Down Expand Up @@ -65,7 +66,7 @@ func createTraceExporter(ctx context.Context, params component.ExporterCreatePar
oce.pushTraceData,
exporterhelper.WithRetry(oCfg.RetrySettings),
exporterhelper.WithQueue(oCfg.QueueSettings),
exporterhelper.WithShutdown(oce.shutdown))
exporterhelper.WithComponentOptions(componenthelper.WithShutdown(oce.shutdown)))
}

func createMetricsExporter(ctx context.Context, params component.ExporterCreateParams, cfg config.Exporter) (component.MetricsExporter, error) {
Expand All @@ -81,5 +82,5 @@ func createMetricsExporter(ctx context.Context, params component.ExporterCreateP
oce.pushMetricsData,
exporterhelper.WithRetry(oCfg.RetrySettings),
exporterhelper.WithQueue(oCfg.QueueSettings),
exporterhelper.WithShutdown(oce.shutdown))
exporterhelper.WithComponentOptions(componenthelper.WithShutdown(oce.shutdown)))
}
7 changes: 4 additions & 3 deletions exporter/otlpexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenthelper"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configgrpc"
"go.opentelemetry.io/collector/exporter/exporterhelper"
Expand Down Expand Up @@ -72,7 +73,7 @@ func createTraceExporter(
exporterhelper.WithTimeout(oCfg.TimeoutSettings),
exporterhelper.WithRetry(oCfg.RetrySettings),
exporterhelper.WithQueue(oCfg.QueueSettings),
exporterhelper.WithShutdown(oce.shutdown))
exporterhelper.WithComponentOptions(componenthelper.WithShutdown(oce.shutdown)))
if err != nil {
return nil, err
}
Expand All @@ -97,7 +98,7 @@ func createMetricsExporter(
exporterhelper.WithTimeout(oCfg.TimeoutSettings),
exporterhelper.WithRetry(oCfg.RetrySettings),
exporterhelper.WithQueue(oCfg.QueueSettings),
exporterhelper.WithShutdown(oce.shutdown),
exporterhelper.WithComponentOptions(componenthelper.WithShutdown(oce.shutdown)),
)
if err != nil {
return nil, err
Expand All @@ -123,7 +124,7 @@ func createLogsExporter(
exporterhelper.WithTimeout(oCfg.TimeoutSettings),
exporterhelper.WithRetry(oCfg.RetrySettings),
exporterhelper.WithQueue(oCfg.QueueSettings),
exporterhelper.WithShutdown(oce.shutdown),
exporterhelper.WithComponentOptions(componenthelper.WithShutdown(oce.shutdown)),
)
if err != nil {
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion exporter/prometheusremotewriteexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"errors"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenthelper"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/exporter/exporterhelper"
Expand Down Expand Up @@ -61,7 +62,7 @@ func createMetricsExporter(_ context.Context, params component.ExporterCreatePar
exporterhelper.WithTimeout(prwCfg.TimeoutSettings),
exporterhelper.WithQueue(prwCfg.QueueSettings),
exporterhelper.WithRetry(prwCfg.RetrySettings),
exporterhelper.WithShutdown(prwe.Shutdown),
exporterhelper.WithComponentOptions(componenthelper.WithShutdown(prwe.Shutdown)),
)

return prwexp, err
Expand Down
Loading

0 comments on commit a84536e

Please sign in to comment.