Skip to content

Commit 98973e7

Browse files
Add the rest of V2 factories and interfaces (#626)
- Added V2 metric factories and interfaces for receivers and exporters. - Added V2 factories and interfaces for processors. - Creation methods in V2 factories accept a CreationParams struct to allow for easier addition of new parameters in the future without breaking the interface. All changes are uniform with previously introduced initial batch of V2 factories and interfaces (except introduction of CreationParams). Issue: #478
1 parent e4bcd35 commit 98973e7

File tree

9 files changed

+87
-14
lines changed

9 files changed

+87
-14
lines changed

consumer/consumer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type MetricsConsumer interface {
3333
// MetricsConsumerV2 is the new metrics consumer interface that receives data.MetricData, processes it
3434
// as needed, and sends it to the next processing node if any or to the destination.
3535
type MetricsConsumerV2 interface {
36-
ConsumeMetricsData(ctx context.Context, md data.MetricData) error
36+
ConsumeMetricsV2(ctx context.Context, md data.MetricData) error
3737
}
3838

3939
// BaseTraceConsumer defines a common interface for TraceConsumer and TraceConsumerV2.

exporter/exporter.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,9 @@ type MetricsExporter interface {
4242
consumer.MetricsConsumer
4343
Exporter
4444
}
45+
46+
// MetricsExporterV2 is a MetricsConsumerV2 that is also an Exporter.
47+
type MetricsExporterV2 interface {
48+
consumer.MetricsConsumerV2
49+
Exporter
50+
}

exporter/factory.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package exporter
1616

1717
import (
18+
"context"
1819
"fmt"
1920

2021
"go.uber.org/zap"
@@ -32,7 +33,7 @@ type BaseFactory interface {
3233
// configuration and should not cause side-effects that prevent the creation
3334
// of multiple instances of the Exporter.
3435
// The object returned by this method needs to pass the checks implemented by
35-
// 'conifgcheck.ValidateConfig'. It is recommended to have such check in the
36+
// 'configcheck.ValidateConfig'. It is recommended to have such check in the
3637
// tests of any implementation of the Factory interface.
3738
CreateDefaultConfig() configmodels.Exporter
3839
}
@@ -48,6 +49,13 @@ type Factory interface {
4849
CreateMetricsExporter(logger *zap.Logger, cfg configmodels.Exporter) (MetricsExporter, error)
4950
}
5051

52+
// CreationParams is passed to Create* functions in FactoryV2.
53+
type CreationParams struct {
54+
// Logger that the factory can use during creation and can pass to the created
55+
// component to be used later as well.
56+
Logger *zap.Logger
57+
}
58+
5159
// FactoryV2 can create TraceExporterV2 and MetricsExporterV2. This is the
5260
// new factory type that can create new style exporters.
5361
type FactoryV2 interface {
@@ -56,9 +64,12 @@ type FactoryV2 interface {
5664
// CreateTraceReceiverV2 creates a trace receiver based on this config.
5765
// If the receiver type does not support tracing or if the config is not valid
5866
// error will be returned instead.
59-
CreateTraceExporterV2(logger *zap.Logger, cfg configmodels.Exporter) (TraceExporterV2, error)
67+
CreateTraceExporterV2(ctx context.Context, params CreationParams, cfg configmodels.Exporter) (TraceExporterV2, error)
6068

61-
// TODO: Add CreateMetricsExporterV2.
69+
// CreateMetricsExporterV2 creates a metrics receiver based on this config.
70+
// If the receiver type does not support metrics or if the config is not valid
71+
// error will be returned instead.
72+
CreateMetricsExporterV2(ctx context.Context, params CreationParams, cfg configmodels.Exporter) (MetricsExporterV2, error)
6273
}
6374

6475
// Build takes a list of exporter factories and returns a map of type map[string]Factory

extension/factory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type Factory interface {
3232
// configuration and should not cause side-effects that prevent the creation
3333
// of multiple instances of the Extension.
3434
// The object returned by this method needs to pass the checks implemented by
35-
// 'conifgcheck.ValidateConfig'. It is recommended to have such check in the
35+
// 'configcheck.ValidateConfig'. It is recommended to have such check in the
3636
// tests of any implementation of the Factory interface.
3737
CreateDefaultConfig() configmodels.Extension
3838

processor/factory.go

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package processor
1616

1717
import (
18+
"context"
1819
"fmt"
1920

2021
"go.uber.org/zap"
@@ -23,8 +24,8 @@ import (
2324
"github.com/open-telemetry/opentelemetry-collector/consumer"
2425
)
2526

26-
// Factory is factory interface for processors.
27-
type Factory interface {
27+
// BaseFactory defines the common functions for all processor factories.
28+
type BaseFactory interface {
2829
// Type gets the type of the Processor created by this factory.
2930
Type() string
3031

@@ -33,9 +34,14 @@ type Factory interface {
3334
// configuration and should not cause side-effects that prevent the creation
3435
// of multiple instances of the Processor.
3536
// The object returned by this method needs to pass the checks implemented by
36-
// 'conifgcheck.ValidateConfig'. It is recommended to have such check in the
37+
// 'configcheck.ValidateConfig'. It is recommended to have such check in the
3738
// tests of any implementation of the Factory interface.
3839
CreateDefaultConfig() configmodels.Processor
40+
}
41+
42+
// Factory is factory interface for processors.
43+
type Factory interface {
44+
BaseFactory
3945

4046
// CreateTraceProcessor creates a trace processor based on this config.
4147
// If the processor type does not support tracing or if the config is not valid
@@ -50,6 +56,31 @@ type Factory interface {
5056
cfg configmodels.Processor) (MetricsProcessor, error)
5157
}
5258

59+
// CreationParams is passed to Create* functions in FactoryV2.
60+
type CreationParams struct {
61+
// Logger that the factory can use during creation and can pass to the created
62+
// component to be used later as well.
63+
Logger *zap.Logger
64+
}
65+
66+
// FactoryV2 is factory interface for processors. This is the
67+
// new factory type that can create new style processors.
68+
type FactoryV2 interface {
69+
BaseFactory
70+
71+
// CreateTraceProcessorV2 creates a trace processor based on this config.
72+
// If the processor type does not support tracing or if the config is not valid
73+
// error will be returned instead.
74+
CreateTraceProcessorV2(ctx context.Context, params CreationParams,
75+
nextConsumer consumer.TraceConsumerV2, cfg configmodels.Processor) (TraceProcessorV2, error)
76+
77+
// CreateMetricsProcessorV2 creates a metrics processor based on this config.
78+
// If the processor type does not support metrics or if the config is not valid
79+
// error will be returned instead.
80+
CreateMetricsProcessorV2(ctx context.Context, params CreationParams,
81+
nextConsumer consumer.MetricsConsumerV2, cfg configmodels.Processor) (MetricsProcessorV2, error)
82+
}
83+
5384
// Build takes a list of processor factories and returns a map of type map[string]Factory
5485
// with factory type as keys. It returns a non-nil error when more than one factories
5586
// have the same type.

processor/processor.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ type MetricsProcessor interface {
4141
Processor
4242
}
4343

44+
// TraceProcessorV2 composes TraceConsumerV2 with some additional processor-specific functions.
45+
type TraceProcessorV2 interface {
46+
consumer.TraceConsumerV2
47+
Processor
48+
}
49+
50+
// MetricsProcessorV2 composes MetricsConsumerV2 with some additional processor-specific functions.
51+
type MetricsProcessorV2 interface {
52+
consumer.MetricsConsumerV2
53+
Processor
54+
}
55+
4456
type DualTypeProcessor interface {
4557
consumer.TraceConsumer
4658
consumer.MetricsConsumer

receiver/factory.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ type Factory interface {
7676
consumer consumer.MetricsConsumer) (MetricsReceiver, error)
7777
}
7878

79+
// CreationParams is passed to Create* functions in FactoryV2.
80+
type CreationParams struct {
81+
// Logger that the factory can use during creation and can pass to the created
82+
// component to be used later as well.
83+
Logger *zap.Logger
84+
}
85+
7986
// FactoryV2 can create TraceReceiverV2 and MetricsReceiverV2. This is the
8087
// new factory type that can create new style receivers.
8188
type FactoryV2 interface {
@@ -84,10 +91,14 @@ type FactoryV2 interface {
8491
// CreateTraceReceiverV2 creates a trace receiver based on this config.
8592
// If the receiver type does not support tracing or if the config is not valid
8693
// error will be returned instead.
87-
CreateTraceReceiverV2(ctx context.Context, logger *zap.Logger, cfg configmodels.Receiver,
94+
CreateTraceReceiverV2(ctx context.Context, params CreationParams, cfg configmodels.Receiver,
8895
nextConsumer consumer.TraceConsumerV2) (TraceReceiver, error)
8996

90-
// TODO: add CreateMetricsReceiverV2.
97+
// CreateMetricsReceiverV2 creates a metrics receiver based on this config.
98+
// If the receiver type does not support metrics or if the config is not valid
99+
// error will be returned instead.
100+
CreateMetricsReceiverV2(ctx context.Context, params CreationParams, cfg configmodels.Receiver,
101+
nextConsumer consumer.MetricsConsumerV2) (MetricsReceiver, error)
91102
}
92103

93104
// Build takes a list of receiver factories and returns a map of type map[string]Factory

service/builder/receivers_builder.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,17 +320,18 @@ func createTraceReceiver(
320320
nextConsumer consumer.BaseTraceConsumer,
321321
) (receiver.TraceReceiver, error) {
322322
if factoryV2, ok := factory.(receiver.FactoryV2); ok {
323+
creationParams := receiver.CreationParams{Logger: logger}
323324

324325
// If both receiver and consumer are of the new type (can manipulate on internal data structure),
325326
// use FactoryV2.CreateTraceReceiverV2.
326327
if nextConsumerV2, ok := nextConsumer.(consumer.TraceConsumerV2); ok {
327-
return factoryV2.CreateTraceReceiverV2(ctx, logger, cfg, nextConsumerV2)
328+
return factoryV2.CreateTraceReceiverV2(ctx, creationParams, cfg, nextConsumerV2)
328329
}
329330

330331
// If receiver is of the new type, but downstream consumer is of the old type,
331332
// use internalToOCTraceConverter compatibility shim.
332333
traceConverter := consumer.NewInternalToOCTraceConverter(nextConsumer.(consumer.TraceConsumer))
333-
return factoryV2.CreateTraceReceiverV2(ctx, logger, cfg, traceConverter)
334+
return factoryV2.CreateTraceReceiverV2(ctx, creationParams, cfg, traceConverter)
334335
}
335336

336337
// If both receiver and consumer are of the old type (can manipulate on OC traces only),

service/builder/receivers_builder_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,15 +400,16 @@ func (b *newStyleReceiverFactory) CustomUnmarshaler() receiver.CustomUnmarshaler
400400

401401
func (b *newStyleReceiverFactory) CreateTraceReceiverV2(
402402
ctx context.Context,
403-
logger *zap.Logger,
403+
params receiver.CreationParams,
404404
cfg configmodels.Receiver,
405405
nextConsumer consumer.TraceConsumerV2,
406406
) (receiver.TraceReceiver, error) {
407407
return &config.ExampleReceiverProducer{}, nil
408408
}
409409

410410
func (b *newStyleReceiverFactory) CreateMetricsReceiverV2(
411-
logger *zap.Logger,
411+
ctx context.Context,
412+
params receiver.CreationParams,
412413
cfg configmodels.Receiver,
413414
consumer consumer.MetricsConsumerV2,
414415
) (receiver.MetricsReceiver, error) {

0 commit comments

Comments
 (0)