@@ -16,6 +16,7 @@ import (
16
16
"go.opentelemetry.io/collector/client"
17
17
"go.opentelemetry.io/collector/component"
18
18
"go.opentelemetry.io/collector/component/componenttest"
19
+ "go.opentelemetry.io/collector/consumer/consumererror"
19
20
"go.opentelemetry.io/collector/exporter/exportertest"
20
21
"go.opentelemetry.io/collector/pdata/pcommon"
21
22
"go.opentelemetry.io/collector/pdata/plog"
@@ -123,6 +124,27 @@ func TestTracesPusher_err(t *testing.T) {
123
124
assert .EqualError (t , err , expErr .Error ())
124
125
}
125
126
127
+ func TestTracesPusher_conf_err (t * testing.T ) {
128
+ t .Run ("should return permanent err on config error" , func (t * testing.T ) {
129
+ expErr := sarama .ConfigurationError ("configuration error" )
130
+ prodErrs := sarama.ProducerErrors {
131
+ & sarama.ProducerError {Err : expErr },
132
+ }
133
+ host := extensionsHost {
134
+ component .MustNewID ("trace_encoding" ): ptraceMarshalerFuncExtension (func (ptrace.Traces ) ([]byte , error ) {
135
+ return nil , prodErrs
136
+ }),
137
+ }
138
+ config := createDefaultConfig ().(* Config )
139
+ config .Traces .Encoding = "trace_encoding"
140
+ exp , _ := newMockTracesExporter (t , * config , host )
141
+
142
+ err := exp .exportData (context .Background (), testdata .GenerateTraces (2 ))
143
+
144
+ assert .True (t , consumererror .IsPermanent (err ))
145
+ })
146
+ }
147
+
126
148
func TestTracesPusher_marshal_error (t * testing.T ) {
127
149
marshalErr := errors .New ("failed to marshal" )
128
150
host := extensionsHost {
@@ -349,6 +371,27 @@ func TestMetricsPusher_err(t *testing.T) {
349
371
assert .EqualError (t , err , expErr .Error ())
350
372
}
351
373
374
+ func TestMetricsPusher_conf_err (t * testing.T ) {
375
+ t .Run ("should return permanent err on config error" , func (t * testing.T ) {
376
+ expErr := sarama .ConfigurationError ("configuration error" )
377
+ prodErrs := sarama.ProducerErrors {
378
+ & sarama.ProducerError {Err : expErr },
379
+ }
380
+ host := extensionsHost {
381
+ component .MustNewID ("metric_encoding" ): ptraceMarshalerFuncExtension (func (ptrace.Traces ) ([]byte , error ) {
382
+ return nil , prodErrs
383
+ }),
384
+ }
385
+ config := createDefaultConfig ().(* Config )
386
+ config .Traces .Encoding = "metric_encoding"
387
+ exp , _ := newMockTracesExporter (t , * config , host )
388
+
389
+ err := exp .exportData (context .Background (), testdata .GenerateTraces (2 ))
390
+
391
+ assert .True (t , consumererror .IsPermanent (err ))
392
+ })
393
+ }
394
+
352
395
func TestMetricsPusher_marshal_error (t * testing.T ) {
353
396
marshalErr := errors .New ("failed to marshal" )
354
397
host := extensionsHost {
@@ -521,6 +564,27 @@ func TestLogsPusher_err(t *testing.T) {
521
564
assert .EqualError (t , err , expErr .Error ())
522
565
}
523
566
567
+ func TestLogsPusher_conf_err (t * testing.T ) {
568
+ t .Run ("should return permanent err on config error" , func (t * testing.T ) {
569
+ expErr := sarama .ConfigurationError ("configuration error" )
570
+ prodErrs := sarama.ProducerErrors {
571
+ & sarama.ProducerError {Err : expErr },
572
+ }
573
+ host := extensionsHost {
574
+ component .MustNewID ("log_encoding" ): ptraceMarshalerFuncExtension (func (ptrace.Traces ) ([]byte , error ) {
575
+ return nil , prodErrs
576
+ }),
577
+ }
578
+ config := createDefaultConfig ().(* Config )
579
+ config .Traces .Encoding = "log_encoding"
580
+ exp , _ := newMockTracesExporter (t , * config , host )
581
+
582
+ err := exp .exportData (context .Background (), testdata .GenerateTraces (2 ))
583
+
584
+ assert .True (t , consumererror .IsPermanent (err ))
585
+ })
586
+ }
587
+
524
588
func TestLogsPusher_marshal_error (t * testing.T ) {
525
589
marshalErr := errors .New ("failed to marshal" )
526
590
host := extensionsHost {
@@ -808,3 +872,64 @@ func newMockLogsExporter(t *testing.T, cfg Config, host component.Host) (*kafkaE
808
872
})
809
873
return exp , producer
810
874
}
875
+
876
+ func TestWrapKafkaProducerError (t * testing.T ) {
877
+ t .Run ("should return permanent error on configuration error" , func (t * testing.T ) {
878
+ err := sarama .ConfigurationError ("configuration error" )
879
+ prodErrs := sarama.ProducerErrors {
880
+ & sarama.ProducerError {Err : err },
881
+ }
882
+
883
+ got := wrapKafkaProducerError (prodErrs )
884
+
885
+ assert .True (t , consumererror .IsPermanent (got ))
886
+ assert .Contains (t , got .Error (), err .Error ())
887
+ })
888
+
889
+ t .Run ("should return permanent error whne multiple configuration error" , func (t * testing.T ) {
890
+ err := sarama .ConfigurationError ("configuration error" )
891
+ prodErrs := sarama.ProducerErrors {
892
+ & sarama.ProducerError {Err : err },
893
+ & sarama.ProducerError {Err : err },
894
+ }
895
+
896
+ got := wrapKafkaProducerError (prodErrs )
897
+
898
+ assert .True (t , consumererror .IsPermanent (got ))
899
+ assert .Contains (t , got .Error (), err .Error ())
900
+ })
901
+
902
+ t .Run ("should return not permanent error when at least one not configuration error" , func (t * testing.T ) {
903
+ err := sarama .ConfigurationError ("configuration error" )
904
+ prodErrs := sarama.ProducerErrors {
905
+ & sarama.ProducerError {Err : err },
906
+ & sarama.ProducerError {Err : errors .New ("other producer error" )},
907
+ }
908
+
909
+ got := wrapKafkaProducerError (prodErrs )
910
+
911
+ assert .False (t , consumererror .IsPermanent (got ))
912
+ assert .Contains (t , got .Error (), err .Error ())
913
+ })
914
+
915
+ t .Run ("should return not permanent error on other producer error" , func (t * testing.T ) {
916
+ err := errors .New ("other producer error" )
917
+ prodErrs := sarama.ProducerErrors {
918
+ & sarama.ProducerError {Err : err },
919
+ }
920
+
921
+ got := wrapKafkaProducerError (prodErrs )
922
+
923
+ assert .False (t , consumererror .IsPermanent (got ))
924
+ assert .Contains (t , got .Error (), err .Error ())
925
+ })
926
+
927
+ t .Run ("should return not permanent error when other error" , func (t * testing.T ) {
928
+ err := errors .New ("other error" )
929
+
930
+ got := wrapKafkaProducerError (err )
931
+
932
+ assert .False (t , consumererror .IsPermanent (got ))
933
+ assert .Contains (t , got .Error (), err .Error ())
934
+ })
935
+ }
0 commit comments