Skip to content

Commit

Permalink
validate otlp config compression for grpc
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Boten <[email protected]>
  • Loading branch information
Alex Boten committed Aug 23, 2023
1 parent e33e748 commit c5cfb2c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
18 changes: 16 additions & 2 deletions service/internal/proctelemetry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,14 @@ func initOTLPgRPCExporter(ctx context.Context, otlpConfig *telemetry.OtlpMetric)
}

if otlpConfig.Compression != nil {
opts = append(opts, otlpmetricgrpc.WithCompressor(*otlpConfig.Compression))
switch *otlpConfig.Compression {
case "gzip":
opts = append(opts, otlpmetricgrpc.WithCompressor(*otlpConfig.Compression))
case "none":
break
default:
return nil, fmt.Errorf("unsupported compression %q", *otlpConfig.Compression)
}
}
if otlpConfig.Timeout != nil {
opts = append(opts, otlpmetricgrpc.WithTimeout(time.Millisecond*time.Duration(*otlpConfig.Timeout)))
Expand Down Expand Up @@ -344,7 +351,14 @@ func initOTLPgRPCSpanExporter(ctx context.Context, otlpConfig *telemetry.Otlp) (
}

if otlpConfig.Compression != nil {
opts = append(opts, otlptracegrpc.WithCompressor(*otlpConfig.Compression))
switch *otlpConfig.Compression {
case "gzip":
opts = append(opts, otlptracegrpc.WithCompressor(*otlpConfig.Compression))
case "none":
break

Check warning on line 358 in service/internal/proctelemetry/config.go

View check run for this annotation

Codecov / codecov/patch

service/internal/proctelemetry/config.go#L357-L358

Added lines #L357 - L358 were not covered by tests
default:
return nil, fmt.Errorf("unsupported compression %q", *otlpConfig.Compression)
}
}
if otlpConfig.Timeout != nil && *otlpConfig.Timeout > 0 {
opts = append(opts, otlptracegrpc.WithTimeout(time.Millisecond*time.Duration(*otlpConfig.Timeout)))
Expand Down
6 changes: 4 additions & 2 deletions service/internal/proctelemetry/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func TestMetricReader(t *testing.T) {
Otlp: &telemetry.OtlpMetric{
Protocol: "grpc/protobuf",
Endpoint: "http://localhost:4317",
Compression: strPtr("gzip"),
Compression: strPtr("none"),
Timeout: intPtr(1000),
Headers: map[string]string{
"test": "test1",
Expand Down Expand Up @@ -226,6 +226,7 @@ func TestMetricReader(t *testing.T) {
},
},
},
err: errors.New("unsupported compression \"invalid\""),
},
{
name: "periodic/otlp-http-exporter",
Expand Down Expand Up @@ -442,7 +443,7 @@ func TestSpanProcessor(t *testing.T) {
},
},
},
err: errors.New("unsupported protocol http/invalid"),
err: errors.New("unsupported protocol \"http/invalid\""),
},
{
name: "batch/otlp-grpc-exporter-no-endpoint",
Expand Down Expand Up @@ -553,6 +554,7 @@ func TestSpanProcessor(t *testing.T) {
},
},
},
err: errors.New("unsupported compression \"invalid\""),
},
{
name: "batch/otlp-http-exporter",
Expand Down

0 comments on commit c5cfb2c

Please sign in to comment.