Skip to content

Commit

Permalink
fix(grpc-exporter): use non-normalized URL to determine channel secur…
Browse files Browse the repository at this point in the history
…ity (#3019)

Co-authored-by: Gerhard Stöbich <deb2001-github@yahoo.de>
  • Loading branch information
pichlermarc and Flarna authored Jun 8, 2022
1 parent 1f742e4 commit 0ed21bc
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 18 deletions.
1 change: 1 addition & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ All notable changes to experimental packages in this project will be documented
### :bug: (Bug Fix)

* fix(otlp-transformer): remove type dependency on Long #3022 @legendecas
* fix(grpc-exporter): use non-normalized URL to determine channel security #3019 @pichlermarc

### :books: (Refine Doc)

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,14 @@ 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;
}

return getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ||
getEnv().OTEL_EXPORTER_OTLP_ENDPOINT ||
DEFAULT_COLLECTOR_URL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,22 @@ 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;
}

return getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT ||
getEnv().OTEL_EXPORTER_OTLP_ENDPOINT ||
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

0 comments on commit 0ed21bc

Please sign in to comment.