-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add configuration constants for property names Move constants to a holder class Port HttpClientOptionsConsumer from Quarkus Modify HCOP to use ConfigProperties General code cleanup
- Loading branch information
Showing
10 changed files
with
320 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...exporters/src/main/java/io/smallrye/opentelemetry/implementation/exporters/Constants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.smallrye.opentelemetry.implementation.exporters; | ||
|
||
public class Constants { | ||
private Constants() { | ||
} | ||
|
||
public static final String PROTOCOL_GRPC = "grpc"; | ||
public static final String PROTOCOL_HTTP_PROTOBUF = "http/protobuf"; | ||
|
||
public static final String OTLP_GRPC_ENDPOINT = "http://localhost:4317"; | ||
public static final String OTLP_HTTP_PROTOBUF_ENDPOINT = "http://localhost:4318"; | ||
|
||
public static final String OTEL_EXPORTER_OTLP_ENDPOINT = "otel.exporter.otlp.endpoint"; | ||
public static final String OTEL_EXPORTER_OTLP_TRACES_PROTOCOL = "otel.exporter.otlp.traces.protocol"; | ||
|
||
static final String OTEL_EXPORTER_VERTX_CDI_QUALIFIER = "otel.exporter.vertx.cdi.identifier"; | ||
|
||
static final String OTEL_EXPORTER_OTLP_CERTIFICATE = "otel.exporter.otlp.certificate"; | ||
static final String OTEL_EXPORTER_OTLP_SIGNAL_CERTIFICATE = "otel.exporter.otlp.%s.certificate"; | ||
|
||
static final String OTEL_EXPORTER_OTLP_CLIENT_KEY = "otel.exporter.otlp.client.key"; | ||
static final String OTEL_EXPORTER_OTLP_SIGNAL_CLIENT_KEY = "otel.exporter.otlp.%s.client.key"; | ||
|
||
static final String OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE = "otel.exporter.otlp.client.certificate"; | ||
static final String OTEL_EXPORTER_OTLP_SIGNAL_CLIENT_CERTIFICATE = "otel.exporter.otlp.%s.client.certificate"; | ||
|
||
static final String OTEL_EXPORTER_OTLP_PROTOCOL = "otel.exporter.otlp.protocol"; | ||
static final String OTEL_EXPORTER_OTLP_SIGNAL_PROTOCOL = "otel.exporter.otlp.%s.protocol"; | ||
|
||
static final String OTEL_EXPORTER_OTLP_TIMEOUT = "otel.exporter.otlp.timeout"; | ||
static final String OTEL_EXPORTER_OTLP_SIGNAL_TIMEOUT = "otel.exporter.otlp.%s.timeout"; | ||
|
||
static final String OTEL_EXPORTER_OTLP_SIGNAL_ENDPOINT = "otel.exporter.otlp.%s.endpoint"; | ||
|
||
static final String OTEL_EXPORTER_OTLP_COMPRESSION = "otel.exporter.otlp.compression"; | ||
static final String OTEL_EXPORTER_OTLP_SIGNAL_COMPRESSION = "otel.exporter.otlp.%s.compression"; | ||
|
||
static final String MIMETYPE_PROTOBUF = "application/x-protobuf"; | ||
|
||
static final String SROTEL_TLS_TRUST_ALL = "otel.exporter.tls.trustAll"; | ||
// Proxy options | ||
static final String SROTEL_PROXY_ENABLED = "otel.exporter.proxy.enabled"; | ||
static final String SROTEL_PROXY_USERNAME = "otel.exporter.proxy.username"; | ||
static final String SROTEL_PROXY_PASSWORD = "otel.exporter.proxy.password"; | ||
static final String SROTEL_PROXY_HOST = "otel.exporter.proxy.host"; | ||
static final String SROTEL_PROXY_PORT = "otel.exporter.proxy.port"; | ||
} |
141 changes: 141 additions & 0 deletions
141
...in/java/io/smallrye/opentelemetry/implementation/exporters/HttpClientOptionsConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package io.smallrye.opentelemetry.implementation.exporters; | ||
|
||
import static io.smallrye.opentelemetry.implementation.exporters.Constants.OTEL_EXPORTER_OTLP_CERTIFICATE; | ||
import static io.smallrye.opentelemetry.implementation.exporters.Constants.OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE; | ||
import static io.smallrye.opentelemetry.implementation.exporters.Constants.OTEL_EXPORTER_OTLP_CLIENT_KEY; | ||
import static io.smallrye.opentelemetry.implementation.exporters.Constants.OTEL_EXPORTER_OTLP_SIGNAL_CERTIFICATE; | ||
import static io.smallrye.opentelemetry.implementation.exporters.Constants.OTEL_EXPORTER_OTLP_SIGNAL_CLIENT_CERTIFICATE; | ||
import static io.smallrye.opentelemetry.implementation.exporters.Constants.OTEL_EXPORTER_OTLP_SIGNAL_CLIENT_KEY; | ||
import static io.smallrye.opentelemetry.implementation.exporters.Constants.SROTEL_PROXY_ENABLED; | ||
import static io.smallrye.opentelemetry.implementation.exporters.Constants.SROTEL_PROXY_HOST; | ||
import static io.smallrye.opentelemetry.implementation.exporters.Constants.SROTEL_PROXY_PASSWORD; | ||
import static io.smallrye.opentelemetry.implementation.exporters.Constants.SROTEL_PROXY_PORT; | ||
import static io.smallrye.opentelemetry.implementation.exporters.Constants.SROTEL_PROXY_USERNAME; | ||
import static io.smallrye.opentelemetry.implementation.exporters.Constants.SROTEL_TLS_TRUST_ALL; | ||
import static io.smallrye.opentelemetry.implementation.exporters.OtlpExporterUtil.getConfig; | ||
|
||
import java.net.URI; | ||
import java.util.function.Consumer; | ||
|
||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||
import io.vertx.core.http.HttpClientOptions; | ||
import io.vertx.core.net.PemKeyCertOptions; | ||
import io.vertx.core.net.PemTrustOptions; | ||
import io.vertx.core.net.ProxyOptions; | ||
|
||
class HttpClientOptionsConsumer implements Consumer<HttpClientOptions> { | ||
private final ConfigProperties config; | ||
private final URI baseUri; | ||
private final String signalType; | ||
|
||
public HttpClientOptionsConsumer(ConfigProperties config, URI baseUri, String signalType) { | ||
this.config = config; | ||
this.baseUri = baseUri; | ||
this.signalType = signalType; | ||
} | ||
|
||
@Override | ||
public void accept(HttpClientOptions options) { | ||
configureTLS(options); | ||
|
||
if (Boolean.parseBoolean(getConfig(config, "false", SROTEL_PROXY_ENABLED))) { | ||
configureProxyOptions(options); | ||
} | ||
} | ||
|
||
private void configureTLS(HttpClientOptions options) { | ||
configureKeyCertOptions(options); | ||
configureTrustOptions(options); | ||
|
||
if (OtlpExporterUtil.isHttps(baseUri)) { | ||
options.setSsl(true); | ||
options.setUseAlpn(true); | ||
} | ||
|
||
if (Boolean.parseBoolean(getConfig(config, "false", SROTEL_TLS_TRUST_ALL))) { | ||
options.setTrustAll(true); | ||
options.setVerifyHost(false); | ||
} | ||
} | ||
|
||
private void configureProxyOptions(HttpClientOptions options) { | ||
var proxyHost = getConfig(config, "", SROTEL_PROXY_HOST); | ||
if (!proxyHost.isBlank()) { | ||
ProxyOptions proxyOptions = new ProxyOptions() | ||
.setHost(proxyHost); | ||
var proxyPort = getConfig(config, "", SROTEL_PROXY_PORT); | ||
var proxyUsername = getConfig(config, "", SROTEL_PROXY_USERNAME); | ||
var proxyPassword = getConfig(config, "", SROTEL_PROXY_PASSWORD); | ||
|
||
if (!proxyPort.isBlank()) { | ||
proxyOptions.setPort(Integer.parseInt(proxyPort)); | ||
} | ||
if (!proxyUsername.isBlank()) { | ||
proxyOptions.setUsername(proxyUsername); | ||
} | ||
if (!proxyPassword.isBlank()) { | ||
proxyOptions.setPassword(proxyPassword); | ||
} | ||
options.setProxyOptions(proxyOptions); | ||
} else { | ||
configureProxyOptionsFromJDKSysProps(options); | ||
} | ||
} | ||
|
||
private void configureProxyOptionsFromJDKSysProps(HttpClientOptions options) { | ||
var proxyHost = options.isSsl() | ||
? System.getProperty("https.proxyHost", "none") | ||
: System.getProperty("http.proxyHost", "none"); | ||
var proxyPortAsString = options.isSsl() | ||
? System.getProperty("https.proxyPort", "443") | ||
: System.getProperty("http.proxyPort", "80"); | ||
var proxyPort = Integer.parseInt(proxyPortAsString); | ||
|
||
if (!"none".equals(proxyHost)) { | ||
ProxyOptions proxyOptions = new ProxyOptions().setHost(proxyHost).setPort(proxyPort); | ||
var proxyUser = options.isSsl() | ||
? System.getProperty("https.proxyUser") | ||
: System.getProperty("http.proxyUser"); | ||
if (proxyUser != null && !proxyUser.isBlank()) { | ||
proxyOptions.setUsername(proxyUser); | ||
} | ||
var proxyPassword = options.isSsl() | ||
? System.getProperty("https.proxyPassword") | ||
: System.getProperty("http.proxyPassword"); | ||
if (proxyPassword != null && !proxyPassword.isBlank()) { | ||
proxyOptions.setPassword(proxyPassword); | ||
} | ||
options.setProxyOptions(proxyOptions); | ||
} | ||
} | ||
|
||
private void configureKeyCertOptions(HttpClientOptions options) { | ||
var pemKeyCertOptions = new PemKeyCertOptions(); | ||
|
||
var certificate = getConfig(config, "", | ||
String.format(OTEL_EXPORTER_OTLP_SIGNAL_CLIENT_CERTIFICATE, signalType), | ||
OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE); | ||
var key = getConfig(config, "", | ||
String.format(OTEL_EXPORTER_OTLP_SIGNAL_CLIENT_KEY, signalType), OTEL_EXPORTER_OTLP_CLIENT_KEY); | ||
|
||
if (!certificate.isEmpty()) { | ||
pemKeyCertOptions.addCertPath(certificate); | ||
} | ||
|
||
if (!key.isEmpty()) { | ||
pemKeyCertOptions.addKeyPath(key); | ||
} | ||
options.setKeyCertOptions(pemKeyCertOptions); | ||
} | ||
|
||
private void configureTrustOptions(HttpClientOptions options) { | ||
var certificate = getConfig(config, "", | ||
String.format(OTEL_EXPORTER_OTLP_SIGNAL_CERTIFICATE, signalType), OTEL_EXPORTER_OTLP_CERTIFICATE); | ||
|
||
if (!certificate.isEmpty()) { | ||
var pemTrustOptions = new PemTrustOptions() | ||
.addCertPath(certificate); | ||
options.setPemTrustOptions(pemTrustOptions); | ||
} | ||
} | ||
} |
Oops, something went wrong.