From bd0bba43b5a1edb1da059760462fa15d81ff7cd9 Mon Sep 17 00:00:00 2001 From: Louis DeLosSantos Date: Mon, 8 Mar 2021 13:00:56 -0500 Subject: [PATCH] exporter: swap pusher for exporter (#1656) to provide consistent naming across the code base, deprecate pusher in favor of exporter naming convention. Signed-off-by: ldelossa Co-authored-by: Tyler Yahn --- CHANGELOG.md | 2 +- example/otel-collector/main.go | 2 +- example/prom-collector/main.go | 2 +- exporters/otlp/internal/otlptest/otlptest.go | 2 +- exporters/otlp/otlpgrpc/example_test.go | 2 +- exporters/stdout/exporter.go | 2 +- sdk/metric/controller/basic/config.go | 18 +++++++++--------- sdk/metric/controller/basic/controller.go | 14 +++++++------- sdk/metric/controller/basic/controller_test.go | 4 ++-- sdk/metric/controller/basic/push_test.go | 8 ++++---- 10 files changed, 28 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e70598495d..0a1605210d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Changed - The SimpleSpanProcessor will now shut down the enclosed `SpanExporter` and gracefully ignore subsequent calls to `OnEnd` after `Shutdown` is called. (#1612) +- `"go.opentelemetry.io/sdk/metric/controller.basic".WithPusher` is replaced with `WithExporter` to provide consistent naming across project. (#1656) - Added non-empty string check for trace `Attribute` keys. (#1659) - Add `description` to SpanStatus only when `StatusCode` is set to error. (#1662) @@ -76,7 +77,6 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm "otel/sdk/trace".ReadOnlySpan "otel/sdk/trace".ReadWriteSpan ``` - ### Removed - Removed attempt to resample spans upon changing the span name with `span.SetName()`. (#1545) diff --git a/example/otel-collector/main.go b/example/otel-collector/main.go index 073d7e974fd..df1829bc502 100644 --- a/example/otel-collector/main.go +++ b/example/otel-collector/main.go @@ -79,7 +79,7 @@ func initProvider() func() { simple.NewWithExactDistribution(), exp, ), - controller.WithPusher(exp), + controller.WithExporter(exp), controller.WithCollectPeriod(2*time.Second), ) diff --git a/example/prom-collector/main.go b/example/prom-collector/main.go index 349b2d8c0e4..4300845a2c1 100644 --- a/example/prom-collector/main.go +++ b/example/prom-collector/main.go @@ -69,7 +69,7 @@ func initMeter() { processor.WithMemory(true), ), controller.WithResource(res), - controller.WithPusher(otlpExporter), + controller.WithExporter(otlpExporter), ) if err := cont.Start(context.Background()); err != nil { diff --git a/exporters/otlp/internal/otlptest/otlptest.go b/exporters/otlp/internal/otlptest/otlptest.go index ac21f893750..56643ec2555 100644 --- a/exporters/otlp/internal/otlptest/otlptest.go +++ b/exporters/otlp/internal/otlptest/otlptest.go @@ -76,7 +76,7 @@ func RunEndToEndTest(ctx context.Context, t *testing.T, exp *otlp.Exporter, mcTr selector := simple.NewWithInexpensiveDistribution() processor := processor.New(selector, exportmetric.StatelessExportKindSelector()) - cont := controller.New(processor, controller.WithPusher(exp)) + cont := controller.New(processor, controller.WithExporter(exp)) require.NoError(t, cont.Start(ctx)) meter := cont.MeterProvider().Meter("test-meter") diff --git a/exporters/otlp/otlpgrpc/example_test.go b/exporters/otlp/otlpgrpc/example_test.go index d2e7785fa42..8e666235be6 100644 --- a/exporters/otlp/otlpgrpc/example_test.go +++ b/exporters/otlp/otlpgrpc/example_test.go @@ -185,7 +185,7 @@ func Example_withDifferentSignalCollectors() { simple.NewWithExactDistribution(), exp, ), - controller.WithPusher(exp), + controller.WithExporter(exp), controller.WithCollectPeriod(2*time.Second), ) global.SetMeterProvider(pusher.MeterProvider()) diff --git a/exporters/stdout/exporter.go b/exporters/stdout/exporter.go index 485e1358b77..44808e1e619 100644 --- a/exporters/stdout/exporter.go +++ b/exporters/stdout/exporter.go @@ -67,7 +67,7 @@ func NewExportPipeline(exportOpts []Option, pushOpts []controller.Option) (trace ), append( pushOpts, - controller.WithPusher(exporter), + controller.WithExporter(exporter), )..., ) err = pusher.Start(context.Background()) diff --git a/sdk/metric/controller/basic/config.go b/sdk/metric/controller/basic/config.go index 4ccd3a68c5f..803dd9c9fd8 100644 --- a/sdk/metric/controller/basic/config.go +++ b/sdk/metric/controller/basic/config.go @@ -46,13 +46,13 @@ type Config struct { // Default value is 10s. If zero, no Collect timeout is applied. CollectTimeout time.Duration - // Pusher is used for exporting metric data. + // Exporter is used for exporting metric data. // // Note: Exporters such as Prometheus that pull data do not implement // export.Exporter. These will directly call Collect() and ForEach(). - Pusher export.Exporter + Exporter export.Exporter - // PushTimeout is the timeout of the Context when a Pusher is configured. + // PushTimeout is the timeout of the Context when a exporter is configured. // // Default value is 10s. If zero, no Export timeout is applied. PushTimeout time.Duration @@ -97,15 +97,15 @@ func (o collectTimeoutOption) Apply(config *Config) { config.CollectTimeout = time.Duration(o) } -// WithPusher sets the Pusher configuration option of a Config. -func WithPusher(pusher export.Exporter) Option { - return pusherOption{pusher} +// WithExporter sets the exporter configuration option of a Config. +func WithExporter(exporter export.Exporter) Option { + return exporterOption{exporter} } -type pusherOption struct{ pusher export.Exporter } +type exporterOption struct{ exporter export.Exporter } -func (o pusherOption) Apply(config *Config) { - config.Pusher = o.pusher +func (o exporterOption) Apply(config *Config) { + config.Exporter = o.exporter } // WithPushTimeout sets the PushTimeout configuration option of a Config. diff --git a/sdk/metric/controller/basic/controller.go b/sdk/metric/controller/basic/controller.go index 38ed50219db..9a2e12777b4 100644 --- a/sdk/metric/controller/basic/controller.go +++ b/sdk/metric/controller/basic/controller.go @@ -44,7 +44,7 @@ var ErrControllerStarted = fmt.Errorf("controller already started") // both "pull" and "push" configurations. This supports two distinct // modes: // -// - Push and Pull: Start() must be called to begin calling the pusher; +// - Push and Pull: Start() must be called to begin calling the exporter; // Collect() is called periodically by a background thread after starting // the controller. // - Pull-Only: Start() is optional in this case, to call Collect periodically. @@ -59,7 +59,7 @@ type Controller struct { accumulator *sdk.Accumulator provider *registry.MeterProvider checkpointer export.Checkpointer - pusher export.Exporter + exporter export.Exporter wg sync.WaitGroup stopCh chan struct{} clock controllerTime.Clock @@ -70,12 +70,12 @@ type Controller struct { pushTimeout time.Duration // collectedTime is used only in configurations with no - // pusher, when ticker != nil. + // exporter, when ticker != nil. collectedTime time.Time } // New constructs a Controller using the provided checkpointer and -// options (including optional Pusher) to configure a metric +// options (including optional exporter) to configure a metric // export pipeline. func New(checkpointer export.Checkpointer, opts ...Option) *Controller { c := &Config{ @@ -98,7 +98,7 @@ func New(checkpointer export.Checkpointer, opts ...Option) *Controller { provider: registry.NewMeterProvider(impl), accumulator: impl, checkpointer: checkpointer, - pusher: c.Pusher, + exporter: c.Exporter, stopCh: nil, clock: controllerTime.RealClock{}, @@ -193,7 +193,7 @@ func (c *Controller) collect(ctx context.Context) error { }); err != nil { return err } - if c.pusher == nil { + if c.exporter == nil { return nil } // Note: this is not subject to collectTimeout. This blocks the next @@ -259,7 +259,7 @@ func (c *Controller) export(ctx context.Context) error { defer cancel() } - return c.pusher.Export(ctx, ckpt) + return c.exporter.Export(ctx, ckpt) } // Foreach gives the caller read-locked access to the current diff --git a/sdk/metric/controller/basic/controller_test.go b/sdk/metric/controller/basic/controller_test.go index bc334fee6ea..447b831f8f4 100644 --- a/sdk/metric/controller/basic/controller_test.go +++ b/sdk/metric/controller/basic/controller_test.go @@ -284,7 +284,7 @@ func TestExportTimeout(t *testing.T) { ), controller.WithCollectPeriod(time.Second), controller.WithPushTimeout(time.Millisecond), - controller.WithPusher(exporter), + controller.WithExporter(exporter), controller.WithResource(resource.Empty()), ) mock := controllertest.NewMockClock() @@ -340,7 +340,7 @@ func TestCollectAfterStopThenStartAgain(t *testing.T) { exp, ), controller.WithCollectPeriod(time.Second), - controller.WithPusher(exp), + controller.WithExporter(exp), controller.WithResource(resource.Empty()), ) mock := controllertest.NewMockClock() diff --git a/sdk/metric/controller/basic/push_test.go b/sdk/metric/controller/basic/push_test.go index d1bf3be8482..8dd58ded46d 100644 --- a/sdk/metric/controller/basic/push_test.go +++ b/sdk/metric/controller/basic/push_test.go @@ -85,7 +85,7 @@ func TestPushDoubleStop(t *testing.T) { ctx := context.Background() exporter := newExporter() checkpointer := newCheckpointer() - p := controller.New(checkpointer, controller.WithPusher(exporter)) + p := controller.New(checkpointer, controller.WithExporter(exporter)) require.NoError(t, p.Start(ctx)) require.NoError(t, p.Stop(ctx)) require.NoError(t, p.Stop(ctx)) @@ -95,7 +95,7 @@ func TestPushDoubleStart(t *testing.T) { ctx := context.Background() exporter := newExporter() checkpointer := newCheckpointer() - p := controller.New(checkpointer, controller.WithPusher(exporter)) + p := controller.New(checkpointer, controller.WithExporter(exporter)) require.NoError(t, p.Start(ctx)) err := p.Start(ctx) require.Error(t, err) @@ -108,7 +108,7 @@ func TestPushTicker(t *testing.T) { checkpointer := newCheckpointer() p := controller.New( checkpointer, - controller.WithPusher(exporter), + controller.WithExporter(exporter), controller.WithCollectPeriod(time.Second), controller.WithResource(testResource), ) @@ -188,7 +188,7 @@ func TestPushExportError(t *testing.T) { checkpointer := processor.New(processortest.AggregatorSelector(), exporter) p := controller.New( checkpointer, - controller.WithPusher(exporter), + controller.WithExporter(exporter), controller.WithCollectPeriod(time.Second), controller.WithResource(testResource), )