Skip to content
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

fix(grpc-exporter): use non-normalized URL to determine channel security #3019

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ All notable changes to experimental packages in this project will be documented

### :bug: (Bug Fix)

* fix(grpc-exporter): use non-normalized URL to determine channel security #3019 @pichlermarc

### :books: (Refine Doc)

### :house: (Internal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,7 @@ export class OTLPTraceExporter
}

getDefaultUrl(config: OTLPGRPCExporterConfigNode) {
return typeof config.url === 'string'
? validateAndNormalizeUrl(config.url)
: getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0
? validateAndNormalizeUrl(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT)
: getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0
? validateAndNormalizeUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT)
: validateAndNormalizeUrl(DEFAULT_COLLECTOR_URL);
return validateAndNormalizeUrl(this.getUrlFromConfig(config));
}

getServiceClientType() {
Expand All @@ -64,4 +58,16 @@ export class OTLPTraceExporter
getServiceProtoPath(): string {
return 'opentelemetry/proto/collector/trace/v1/trace_service.proto';
}

getUrlFromConfig(config: OTLPGRPCExporterConfigNode): string {
if (typeof config.url === 'string') {
return config.url;
} else if (getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0) {
pichlermarc marked this conversation as resolved.
Show resolved Hide resolved
return getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT;
} else if (getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0) {
return getEnv().OTEL_EXPORTER_OTLP_ENDPOINT;
} else {
return DEFAULT_COLLECTOR_URL;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,24 @@ class OTLPMetricExporterProxy extends OTLPGRPCExporterNodeBase<ResourceMetrics,
}

getDefaultUrl(config: OTLPGRPCExporterConfigNode): string {
return typeof config.url === 'string'
? validateAndNormalizeUrl(config.url)
: getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT.length > 0
? validateAndNormalizeUrl(getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT)
: getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0
? validateAndNormalizeUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT)
: validateAndNormalizeUrl(DEFAULT_COLLECTOR_URL);
return validateAndNormalizeUrl(this.getUrlFromConfig(config));
}

convert(metrics: ResourceMetrics[]): IExportMetricsServiceRequest {
return createExportMetricsServiceRequest(metrics);
}

getUrlFromConfig(config: OTLPGRPCExporterConfigNode): string {
if (typeof config.url === 'string') {
return config.url;
} else if (getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT.length > 0) {
return getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT;
} else if (getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0) {
return getEnv().OTEL_EXPORTER_OTLP_ENDPOINT;
} else {
return DEFAULT_COLLECTOR_URL;
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,5 @@ export abstract class OTLPGRPCExporterNodeBase<

abstract getServiceProtoPath(): string;
abstract getServiceClientType(): ServiceClientType;
abstract getUrlFromConfig(config: OTLPGRPCExporterConfigNode): string;
}
8 changes: 4 additions & 4 deletions experimental/packages/otlp-grpc-exporter-base/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function onInit<ExportItem, ServiceRequest>(
): void {
collector.grpcQueue = [];

const credentials: grpc.ChannelCredentials = configureSecurity(config.credentials, collector.url);
const credentials: grpc.ChannelCredentials = configureSecurity(config.credentials, collector.getUrlFromConfig(config));

const includeDirs = [path.resolve(__dirname, '..', 'protos')];

Expand Down Expand Up @@ -92,7 +92,7 @@ export function send<ExportItem, ServiceRequest>(
collector.serviceClient.export(
serviceRequest,
collector.metadata || new grpc.Metadata(),
{deadline: deadline},
{ deadline: deadline },
(err: ExportServiceError) => {
if (err) {
diag.error('Service request', serviceRequest);
Expand Down Expand Up @@ -225,7 +225,7 @@ function retrieveCertChain(): Buffer | undefined {
}

function toGrpcCompression(compression: CompressionAlgorithm): GrpcCompressionAlgorithm {
if(compression === CompressionAlgorithm.NONE)
if (compression === CompressionAlgorithm.NONE)
return GrpcCompressionAlgorithm.NONE;
else if (compression === CompressionAlgorithm.GZIP)
return GrpcCompressionAlgorithm.GZIP;
Expand All @@ -246,6 +246,6 @@ export function configureCompression(compression: CompressionAlgorithm | undefin
} else {
const definedCompression = getEnv().OTEL_EXPORTER_OTLP_TRACES_COMPRESSION || getEnv().OTEL_EXPORTER_OTLP_COMPRESSION;

return definedCompression === 'gzip' ? GrpcCompressionAlgorithm.GZIP: GrpcCompressionAlgorithm.NONE;
return definedCompression === 'gzip' ? GrpcCompressionAlgorithm.GZIP : GrpcCompressionAlgorithm.NONE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class MockCollectorExporter extends OTLPGRPCExporterNodeBase<
getServiceProtoPath(): string {
return 'opentelemetry/proto/collector/trace/v1/trace_service.proto';
}

getUrlFromConfig(config: OTLPGRPCExporterConfigNode): string {
return '';
}
}

// Mocked _send which just saves the callbacks for later
Expand Down