@@ -52,10 +52,12 @@ var otlpReceiverID = component.NewIDWithName("otlp", otlpReceiverName)
52
52
53
53
func TestJsonHttp (t * testing.T ) {
54
54
tests := []struct {
55
- name string
56
- encoding string
57
- contentType string
58
- err error
55
+ name string
56
+ encoding string
57
+ contentType string
58
+ err error
59
+ expectedStatus * spb.Status
60
+ expectedStatusCode int
59
61
}{
60
62
{
61
63
name : "JSONUncompressed" ,
@@ -83,16 +85,36 @@ func TestJsonHttp(t *testing.T) {
83
85
contentType : "application/json" ,
84
86
},
85
87
{
86
- name : "NotGRPCError" ,
87
- encoding : "" ,
88
- contentType : "application/json" ,
89
- err : errors .New ("my error" ),
88
+ name : "Permanent NotGRPCError" ,
89
+ encoding : "" ,
90
+ contentType : "application/json" ,
91
+ err : consumererror .NewPermanent (errors .New ("my error" )),
92
+ expectedStatus : & spb.Status {Code : int32 (codes .InvalidArgument ), Message : "Permanent error: my error" },
93
+ expectedStatusCode : http .StatusInternalServerError ,
90
94
},
91
95
{
92
- name : "GRPCError" ,
93
- encoding : "" ,
94
- contentType : "application/json" ,
95
- err : status .New (codes .Unavailable , "" ).Err (),
96
+ name : "Retryable NotGRPCError" ,
97
+ encoding : "" ,
98
+ contentType : "application/json" ,
99
+ err : errors .New ("my error" ),
100
+ expectedStatus : & spb.Status {Code : int32 (codes .Unavailable ), Message : "my error" },
101
+ expectedStatusCode : http .StatusServiceUnavailable ,
102
+ },
103
+ {
104
+ name : "Permanent GRPCError" ,
105
+ encoding : "" ,
106
+ contentType : "application/json" ,
107
+ err : status .New (codes .InvalidArgument , "" ).Err (),
108
+ expectedStatus : & spb.Status {Code : int32 (codes .InvalidArgument ), Message : "" },
109
+ expectedStatusCode : http .StatusInternalServerError ,
110
+ },
111
+ {
112
+ name : "Retryable GRPCError" ,
113
+ encoding : "" ,
114
+ contentType : "application/json" ,
115
+ err : status .New (codes .Unavailable , "" ).Err (),
116
+ expectedStatus : & spb.Status {Code : int32 (codes .Unavailable ), Message : "" },
117
+ expectedStatusCode : http .StatusServiceUnavailable ,
96
118
},
97
119
}
98
120
addr := testutil .GetAvailableLocalAddress (t )
@@ -108,7 +130,7 @@ func TestJsonHttp(t *testing.T) {
108
130
109
131
for _ , dr := range generateDataRequests (t ) {
110
132
url := "http://" + addr + dr .path
111
- respBytes := doHTTPRequest (t , url , tt .encoding , tt .contentType , dr .jsonBytes , tt .err != nil )
133
+ respBytes := doHTTPRequest (t , url , tt .encoding , tt .contentType , dr .jsonBytes , tt .expectedStatusCode )
112
134
if tt .err == nil {
113
135
tr := ptraceotlp .NewExportResponse ()
114
136
assert .NoError (t , tr .UnmarshalJSON (respBytes ), "Unable to unmarshal response to Response" )
@@ -120,7 +142,7 @@ func TestJsonHttp(t *testing.T) {
120
142
assert .True (t , proto .Equal (errStatus , s .Proto ()))
121
143
} else {
122
144
fmt .Println (errStatus )
123
- assert .True (t , proto .Equal (errStatus , & spb. Status { Code : int32 ( codes . Unavailable ), Message : "my error" } ))
145
+ assert .True (t , proto .Equal (errStatus , tt . expectedStatus ))
124
146
}
125
147
sink .checkData (t , dr .data , 0 )
126
148
}
@@ -302,9 +324,11 @@ func TestHandleInvalidRequests(t *testing.T) {
302
324
303
325
func TestProtoHttp (t * testing.T ) {
304
326
tests := []struct {
305
- name string
306
- encoding string
307
- err error
327
+ name string
328
+ encoding string
329
+ err error
330
+ expectedStatus * spb.Status
331
+ expectedStatusCode int
308
332
}{
309
333
{
310
334
name : "ProtoUncompressed" ,
@@ -319,14 +343,32 @@ func TestProtoHttp(t *testing.T) {
319
343
encoding : "zstd" ,
320
344
},
321
345
{
322
- name : "NotGRPCError" ,
323
- encoding : "" ,
324
- err : errors .New ("my error" ),
346
+ name : "Permanent NotGRPCError" ,
347
+ encoding : "" ,
348
+ err : consumererror .NewPermanent (errors .New ("my error" )),
349
+ expectedStatus : & spb.Status {Code : int32 (codes .InvalidArgument ), Message : "Permanent error: my error" },
350
+ expectedStatusCode : http .StatusInternalServerError ,
325
351
},
326
352
{
327
- name : "GRPCError" ,
328
- encoding : "" ,
329
- err : status .New (codes .Unavailable , "" ).Err (),
353
+ name : "Retryable NotGRPCError" ,
354
+ encoding : "" ,
355
+ err : errors .New ("my error" ),
356
+ expectedStatus : & spb.Status {Code : int32 (codes .Unavailable ), Message : "my error" },
357
+ expectedStatusCode : http .StatusServiceUnavailable ,
358
+ },
359
+ {
360
+ name : "Permanent GRPCError" ,
361
+ encoding : "" ,
362
+ err : status .New (codes .InvalidArgument , "" ).Err (),
363
+ expectedStatus : & spb.Status {Code : int32 (codes .InvalidArgument ), Message : "" },
364
+ expectedStatusCode : http .StatusInternalServerError ,
365
+ },
366
+ {
367
+ name : "Retryable GRPCError" ,
368
+ encoding : "" ,
369
+ err : status .New (codes .Unavailable , "" ).Err (),
370
+ expectedStatus : & spb.Status {Code : int32 (codes .Unavailable ), Message : "" },
371
+ expectedStatusCode : http .StatusServiceUnavailable ,
330
372
},
331
373
}
332
374
addr := testutil .GetAvailableLocalAddress (t )
@@ -345,7 +387,7 @@ func TestProtoHttp(t *testing.T) {
345
387
346
388
for _ , dr := range generateDataRequests (t ) {
347
389
url := "http://" + addr + dr .path
348
- respBytes := doHTTPRequest (t , url , tt .encoding , "application/x-protobuf" , dr .protoBytes , tt .err != nil )
390
+ respBytes := doHTTPRequest (t , url , tt .encoding , "application/x-protobuf" , dr .protoBytes , tt .expectedStatusCode )
349
391
if tt .err == nil {
350
392
tr := ptraceotlp .NewExportResponse ()
351
393
assert .NoError (t , tr .UnmarshalProto (respBytes ))
@@ -356,7 +398,7 @@ func TestProtoHttp(t *testing.T) {
356
398
if s , ok := status .FromError (tt .err ); ok {
357
399
assert .True (t , proto .Equal (errStatus , s .Proto ()))
358
400
} else {
359
- assert .True (t , proto .Equal (errStatus , & spb. Status { Code : int32 ( codes . Unavailable ), Message : "my error" } ))
401
+ assert .True (t , proto .Equal (errStatus , tt . expectedStatus ))
360
402
}
361
403
sink .checkData (t , dr .data , 0 )
362
404
}
@@ -560,20 +602,30 @@ func TestOTLPReceiverGRPCTracesIngestTest(t *testing.T) {
560
602
// trace receiver.
561
603
func TestOTLPReceiverHTTPTracesIngestTest (t * testing.T ) {
562
604
type ingestionStateTest struct {
563
- okToIngest bool
564
- expectedCode codes.Code
605
+ okToIngest bool
606
+ err error
607
+ expectedCode codes.Code
608
+ expectedStatusCode int
565
609
}
566
610
567
611
expectedReceivedBatches := 2
568
- expectedIngestionBlockedRPCs := 1
612
+ expectedIngestionBlockedRPCs := 2
569
613
ingestionStates := []ingestionStateTest {
570
614
{
571
615
okToIngest : true ,
572
616
expectedCode : codes .OK ,
573
617
},
574
618
{
575
- okToIngest : false ,
576
- expectedCode : codes .Unavailable ,
619
+ okToIngest : false ,
620
+ err : consumererror .NewPermanent (errors .New ("consumer error" )),
621
+ expectedCode : codes .InvalidArgument ,
622
+ expectedStatusCode : http .StatusInternalServerError ,
623
+ },
624
+ {
625
+ okToIngest : false ,
626
+ err : errors .New ("consumer error" ),
627
+ expectedCode : codes .Unavailable ,
628
+ expectedStatusCode : http .StatusServiceUnavailable ,
577
629
},
578
630
{
579
631
okToIngest : true ,
@@ -599,7 +651,7 @@ func TestOTLPReceiverHTTPTracesIngestTest(t *testing.T) {
599
651
if ingestionState .okToIngest {
600
652
sink .SetConsumeError (nil )
601
653
} else {
602
- sink .SetConsumeError (errors . New ( "consumer error" ) )
654
+ sink .SetConsumeError (ingestionState . err )
603
655
}
604
656
605
657
pbMarshaler := ptrace.ProtoMarshaler {}
@@ -620,7 +672,7 @@ func TestOTLPReceiverHTTPTracesIngestTest(t *testing.T) {
620
672
} else {
621
673
errStatus := & spb.Status {}
622
674
assert .NoError (t , proto .Unmarshal (respBytes , errStatus ))
623
- assert .Equal (t , http . StatusInternalServerError , resp .StatusCode )
675
+ assert .Equal (t , ingestionState . expectedStatusCode , resp .StatusCode )
624
676
assert .Equal (t , ingestionState .expectedCode , codes .Code (errStatus .Code ))
625
677
}
626
678
}
@@ -853,7 +905,7 @@ func doHTTPRequest(
853
905
encoding string ,
854
906
contentType string ,
855
907
data []byte ,
856
- expectErr bool ,
908
+ expectStatusCode int ,
857
909
) []byte {
858
910
req := createHTTPRequest (t , url , encoding , contentType , data )
859
911
resp , err := http .DefaultClient .Do (req )
@@ -866,10 +918,10 @@ func doHTTPRequest(
866
918
// For cases like "application/json; charset=utf-8", the response will be only "application/json"
867
919
require .True (t , strings .HasPrefix (strings .ToLower (contentType ), resp .Header .Get ("Content-Type" )))
868
920
869
- if ! expectErr {
921
+ if expectStatusCode == 0 {
870
922
require .Equal (t , http .StatusOK , resp .StatusCode )
871
923
} else {
872
- require .Equal (t , http . StatusInternalServerError , resp .StatusCode )
924
+ require .Equal (t , expectStatusCode , resp .StatusCode )
873
925
}
874
926
875
927
return respBytes
0 commit comments