Skip to content

Commit c5cfb2c

Browse files
author
Alex Boten
committed
validate otlp config compression for grpc
Signed-off-by: Alex Boten <[email protected]>
1 parent e33e748 commit c5cfb2c

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

service/internal/proctelemetry/config.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,14 @@ func initOTLPgRPCExporter(ctx context.Context, otlpConfig *telemetry.OtlpMetric)
280280
}
281281

282282
if otlpConfig.Compression != nil {
283-
opts = append(opts, otlpmetricgrpc.WithCompressor(*otlpConfig.Compression))
283+
switch *otlpConfig.Compression {
284+
case "gzip":
285+
opts = append(opts, otlpmetricgrpc.WithCompressor(*otlpConfig.Compression))
286+
case "none":
287+
break
288+
default:
289+
return nil, fmt.Errorf("unsupported compression %q", *otlpConfig.Compression)
290+
}
284291
}
285292
if otlpConfig.Timeout != nil {
286293
opts = append(opts, otlpmetricgrpc.WithTimeout(time.Millisecond*time.Duration(*otlpConfig.Timeout)))
@@ -344,7 +351,14 @@ func initOTLPgRPCSpanExporter(ctx context.Context, otlpConfig *telemetry.Otlp) (
344351
}
345352

346353
if otlpConfig.Compression != nil {
347-
opts = append(opts, otlptracegrpc.WithCompressor(*otlpConfig.Compression))
354+
switch *otlpConfig.Compression {
355+
case "gzip":
356+
opts = append(opts, otlptracegrpc.WithCompressor(*otlpConfig.Compression))
357+
case "none":
358+
break
359+
default:
360+
return nil, fmt.Errorf("unsupported compression %q", *otlpConfig.Compression)
361+
}
348362
}
349363
if otlpConfig.Timeout != nil && *otlpConfig.Timeout > 0 {
350364
opts = append(opts, otlptracegrpc.WithTimeout(time.Millisecond*time.Duration(*otlpConfig.Timeout)))

service/internal/proctelemetry/config_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func TestMetricReader(t *testing.T) {
162162
Otlp: &telemetry.OtlpMetric{
163163
Protocol: "grpc/protobuf",
164164
Endpoint: "http://localhost:4317",
165-
Compression: strPtr("gzip"),
165+
Compression: strPtr("none"),
166166
Timeout: intPtr(1000),
167167
Headers: map[string]string{
168168
"test": "test1",
@@ -226,6 +226,7 @@ func TestMetricReader(t *testing.T) {
226226
},
227227
},
228228
},
229+
err: errors.New("unsupported compression \"invalid\""),
229230
},
230231
{
231232
name: "periodic/otlp-http-exporter",
@@ -442,7 +443,7 @@ func TestSpanProcessor(t *testing.T) {
442443
},
443444
},
444445
},
445-
err: errors.New("unsupported protocol http/invalid"),
446+
err: errors.New("unsupported protocol \"http/invalid\""),
446447
},
447448
{
448449
name: "batch/otlp-grpc-exporter-no-endpoint",
@@ -553,6 +554,7 @@ func TestSpanProcessor(t *testing.T) {
553554
},
554555
},
555556
},
557+
err: errors.New("unsupported compression \"invalid\""),
556558
},
557559
{
558560
name: "batch/otlp-http-exporter",

0 commit comments

Comments
 (0)