Skip to content

Commit

Permalink
NH-87394: ensure url is formed when port is appended
Browse files Browse the repository at this point in the history
  • Loading branch information
cleverchuk committed Jul 29, 2024
1 parent 9b4aab9 commit 2fcb5f0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ static void configOtelLogExport(ConfigContainer container) {
String collectorEndpoint = (String) container.get(ConfigProperty.AGENT_COLLECTOR);

if (collectorEndpoint != null) {
collectorEndpoint = collectorEndpoint.split(":")[0];
String[] fragments = collectorEndpoint.split("\\.");
if (fragments.length > 2) {
// This is based on knowledge of the SWO url format where the third name from the left in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.solarwinds.opentelemetry.extensions.SpanAttributeNamingScheme;
import com.solarwinds.opentelemetry.extensions.TransactionNameManager;
import java.io.File;
import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -215,6 +216,42 @@ void verifyOtelLogExportEndpointIsProperlyFormed() throws InvalidConfigException
System.getProperty("otel.exporter.otlp.logs.endpoint"));
}

@Test
@ClearSystemProperty(key = "otel.logs.exporter")
@ClearSystemProperty(key = "otel.exporter.otlp.protocol")
@ClearSystemProperty(key = "otel.exporter.otlp.logs.headers")
@ClearSystemProperty(key = "otel.exporter.otlp.logs.endpoint")
void verifyOtelLogExportEndpointIsProperlyFormedWithPort() throws InvalidConfigException {
ConfigContainer configContainer = new ConfigContainer();
configContainer.putByStringValue(ConfigProperty.AGENT_SERVICE_KEY, "token:service");
configContainer.putByStringValue(
ConfigProperty.AGENT_COLLECTOR, "otel.collector.na-01.cloud.solarwinds.com:443");

configContainer.putByStringValue(ConfigProperty.AGENT_EXPORT_LOGS_ENABLED, "true");
ConfigurationLoader.configOtelLogExport(configContainer);

assertEquals(
"https://otel.collector.na-01.cloud.solarwinds.com",
System.getProperty("otel.exporter.otlp.logs.endpoint"));
}

@Test
@ClearSystemProperty(key = "otel.logs.exporter")
@ClearSystemProperty(key = "otel.exporter.otlp.protocol")
@ClearSystemProperty(key = "otel.exporter.otlp.logs.headers")
@ClearSystemProperty(key = "otel.exporter.otlp.logs.endpoint")
void verifyOtelLogExportEndpointIsProperlyFormedForPortAndAO() throws InvalidConfigException {
ConfigContainer configContainer = new ConfigContainer();
configContainer.putByStringValue(ConfigProperty.AGENT_SERVICE_KEY, "token:service");
configContainer.putByStringValue(ConfigProperty.AGENT_COLLECTOR, "collector.appoptics.com:443");

configContainer.putByStringValue(ConfigProperty.AGENT_EXPORT_LOGS_ENABLED, "true");
ConfigurationLoader.configOtelLogExport(configContainer);

assertNotNull(System.getProperty("otel.exporter.otlp.logs.endpoint"));
assertDoesNotThrow(() -> new URL(System.getProperty("otel.exporter.otlp.logs.endpoint")));
}

@Test
@ClearSystemProperty(key = "otel.logs.exporter")
@ClearSystemProperty(key = "otel.exporter.otlp.protocol")
Expand Down

0 comments on commit 2fcb5f0

Please sign in to comment.