-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[exporter/kafkaexporter] ExporterFactory log/metric marshaler options #13433
Closed
bgranetzke
wants to merge
12
commits into
open-telemetry:main
from
bgranetzke:exporter/kafkaexporter_marshaler_options
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3420313
[exporter/kafkaexporter] ExporterFactory log/metric marshaler options
bgranetzke b9c6bbe
Merge branch 'main' into exporter/kafkaexporter_marshaler_options
TylerHelmuth 143a89e
revisit tests
bgranetzke 386952d
Merge branch 'exporter/kafkaexporter_marshaler_options' of github.com…
bgranetzke b315703
Merge branch 'open-telemetry:main' into exporter/kafkaexporter_marsha…
bgranetzke b97ca64
test cleanup; added changelog
bgranetzke 50f62cc
Merge branch 'main' into exporter/kafkaexporter_marshaler_options
bgranetzke 8d6d7fe
Merge branch 'open-telemetry:main' into exporter/kafkaexporter_marsha…
bgranetzke 569713d
Merge branch 'open-telemetry:main' into exporter/kafkaexporter_marsha…
bgranetzke 7c88a4f
fixed release note; expanded new option comments
bgranetzke 4c8f0e3
Merge branch 'open-telemetry:main' into exporter/kafkaexporter_marsha…
bgranetzke 6b36c03
Merge branch 'open-telemetry:main' into exporter/kafkaexporter_marsha…
bgranetzke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,9 @@ const ( | |
// FactoryOption applies changes to kafkaExporterFactory. | ||
type FactoryOption func(factory *kafkaExporterFactory) | ||
|
||
// WithTracesMarshalers adds tracesMarshalers. | ||
// WithTracesMarshalers adds tracesMarshalers to the exporter factory. | ||
// This allows custom-built collectors to configure custom Kafka marshaler(s) for trace data. | ||
// An example use case is keying the message by trace ID so downstream collectors could do tail-based sampling with horizontal scale. | ||
func WithTracesMarshalers(tracesMarshalers ...TracesMarshaler) FactoryOption { | ||
return func(factory *kafkaExporterFactory) { | ||
for _, marshaler := range tracesMarshalers { | ||
|
@@ -62,6 +64,36 @@ func WithTracesMarshalers(tracesMarshalers ...TracesMarshaler) FactoryOption { | |
} | ||
} | ||
|
||
// WithMetricsMarshalers adds metricsMarshalers to the exporter factory. | ||
// This allows custom-built collectors to configure custom Kafka marshaler(s) for metric data. | ||
// An example use case is keying the message by resource attribute values so downstream collectors can be horizontally scaled and still deliver metrics in the correct order to the backend. | ||
// Another use case might be pre-aggregating metrics to reduce backend update throughput. | ||
func WithMetricsMarshalers(metricsMarshalers ...MetricsMarshaler) FactoryOption { | ||
return func(factory *kafkaExporterFactory) { | ||
for _, marshaler := range metricsMarshalers { | ||
factory.metricsMarshalers[marshaler.Encoding()] = marshaler | ||
} | ||
} | ||
} | ||
|
||
// WithLogsMarshalers adds logsMarshalers to the exporter factory. | ||
// This allows custom-built collectors to configure custom Kafka marshaler(s) for log data. | ||
// An example use case is keying the message by resource attribute values so downstream collectors can be horizontally scaled and still deliver logs in the correct order to the backend. | ||
func WithLogsMarshalers(logsMarshalers ...LogsMarshaler) FactoryOption { | ||
return func(factory *kafkaExporterFactory) { | ||
for _, marshaler := range logsMarshalers { | ||
factory.logsMarshalers[marshaler.Encoding()] = marshaler | ||
} | ||
} | ||
} | ||
|
||
// WithProducerFactory sets an alternative producer factory. | ||
func WithProducerFactory(producerFactory ProducerFactoryFunc) FactoryOption { | ||
return func(factory *kafkaExporterFactory) { | ||
factory.producerFactory = producerFactory | ||
} | ||
} | ||
|
||
// NewFactory creates Kafka exporter factory. | ||
func NewFactory(options ...FactoryOption) component.ExporterFactory { | ||
f := &kafkaExporterFactory{ | ||
|
@@ -107,10 +139,13 @@ func createDefaultConfig() config.Exporter { | |
} | ||
} | ||
|
||
type ProducerFactoryFunc func(config Config) (sarama.SyncProducer, error) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment exported types for their intended use. |
||
|
||
type kafkaExporterFactory struct { | ||
tracesMarshalers map[string]TracesMarshaler | ||
metricsMarshalers map[string]MetricsMarshaler | ||
logsMarshalers map[string]LogsMarshaler | ||
producerFactory ProducerFactoryFunc | ||
} | ||
|
||
func (f *kafkaExporterFactory) createTracesExporter( | ||
|
@@ -125,7 +160,10 @@ func (f *kafkaExporterFactory) createTracesExporter( | |
if oCfg.Encoding == "otlp_json" { | ||
set.Logger.Info("otlp_json is considered experimental and should not be used in a production environment") | ||
} | ||
exp, err := newTracesExporter(oCfg, set, f.tracesMarshalers) | ||
if f.producerFactory == nil { | ||
f.producerFactory = newSaramaProducer | ||
} | ||
exp, err := newTracesExporter(oCfg, set, f.producerFactory, f.tracesMarshalers) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -155,7 +193,10 @@ func (f *kafkaExporterFactory) createMetricsExporter( | |
if oCfg.Encoding == "otlp_json" { | ||
set.Logger.Info("otlp_json is considered experimental and should not be used in a production environment") | ||
} | ||
exp, err := newMetricsExporter(oCfg, set, f.metricsMarshalers) | ||
if f.producerFactory == nil { | ||
f.producerFactory = newSaramaProducer | ||
} | ||
exp, err := newMetricsExporter(oCfg, set, f.producerFactory, f.metricsMarshalers) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -185,7 +226,10 @@ func (f *kafkaExporterFactory) createLogsExporter( | |
if oCfg.Encoding == "otlp_json" { | ||
set.Logger.Info("otlp_json is considered experimental and should not be used in a production environment") | ||
} | ||
exp, err := newLogsExporter(oCfg, set, f.logsMarshalers) | ||
if f.producerFactory == nil { | ||
f.producerFactory = newSaramaProducer | ||
} | ||
exp, err := newLogsExporter(oCfg, set, f.producerFactory, f.logsMarshalers) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you expand upon why you would need an alternative producer factory, it isn't clear to me why you would need this and why you'd want to use this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was only to test the custom marshaler option. I did not like it either, but due to how the actual factory is wrapped inside the component.ExporterFactory, I had to inject the mock during NewFactory(). I didn't want to create kafkaExporterFactory directly because then if felt like I wasn't testing the new options I was adding.
Totally open to an alternative approach.