Skip to content

Commit

Permalink
Merge pull request #249 from solarwinds/cc/NH-87394
Browse files Browse the repository at this point in the history
NH-87394: ensure url is formed when port is appended
  • Loading branch information
cleverchuk authored Jul 29, 2024
2 parents 56af6a5 + 2aa851b commit 00b4248
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ static void configOtelLogExport(ConfigContainer container) {
String collectorEndpoint = (String) container.get(ConfigProperty.AGENT_COLLECTOR);

if (collectorEndpoint != null) {
if (collectorEndpoint.contains("appoptics.com")) {
return;
}
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 @@ -215,6 +215,41 @@ 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 verifyOtelLogExportEndpointIsNullForAO() 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);

assertNull(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 00b4248

Please sign in to comment.