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

Allow setting otlp protocol for profiler with otel.exporter.otlp.protocol #2090

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public class Configuration implements AutoConfigurationCustomizerProvider {
public static final String CONFIG_KEY_RECORDING_DURATION = "splunk.profiler.recording.duration";
public static final String CONFIG_KEY_KEEP_FILES = "splunk.profiler.keep-files";
public static final String CONFIG_KEY_INGEST_URL = "splunk.profiler.logs-endpoint";
public static final String CONFIG_KEY_OTLP_PROTOCOL = "splunk.profiler.otlp.protocol";
public static final String CONFIG_KEY_PROFILER_OTLP_PROTOCOL = "splunk.profiler.otlp.protocol";
public static final String CONFIG_KEY_OTLP_PROTOCOL = "otel.exporter.otlp.protocol";
public static final String CONFIG_KEY_OTEL_OTLP_URL = "otel.exporter.otlp.endpoint";
public static final String CONFIG_KEY_MEMORY_ENABLED = PROFILER_MEMORY_ENABLED_PROPERTY;
public static final String CONFIG_KEY_MEMORY_EVENT_RATE_LIMIT_ENABLED =
Expand Down Expand Up @@ -82,7 +83,6 @@ Map<String, String> defaultProperties() {
config.put(CONFIG_KEY_MEMORY_ENABLED, String.valueOf(DEFAULT_MEMORY_ENABLED));
config.put(CONFIG_KEY_MEMORY_EVENT_RATE, DEFAULT_MEMORY_EVENT_RATE);
config.put(CONFIG_KEY_CALL_STACK_INTERVAL, DEFAULT_CALL_STACK_INTERVAL.toMillis() + "ms");
config.put(CONFIG_KEY_OTLP_PROTOCOL, "http/protobuf");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes it a little more challenging for a casual reader to know the default, but I think it's fine.

return config;
}

Expand Down Expand Up @@ -116,7 +116,9 @@ private static String getDefaultLogsEndpoint(ConfigProperties config) {
}

public static String getOtlpProtocol(ConfigProperties config) {
return config.getString(CONFIG_KEY_OTLP_PROTOCOL);
return config.getString(
CONFIG_KEY_PROFILER_OTLP_PROTOCOL,
config.getString(CONFIG_KEY_OTLP_PROTOCOL, "http/protobuf"));
Comment on lines +119 to +121
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

}

public static boolean getMemoryEnabled(ConfigProperties config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
import static org.mockito.Mockito.when;

import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;

class ConfigurationTest {
Expand All @@ -36,7 +40,7 @@ void getConfigUrl_endpointDefined() {
when(config.getString(Configuration.CONFIG_KEY_INGEST_URL, otelEndpoint))
.thenReturn(logsEndpoint);
String result = Configuration.getConfigUrl(config);
assertEquals(result, logsEndpoint);
assertEquals(logsEndpoint, result);
}

@Test
Expand All @@ -46,7 +50,7 @@ void getConfigUrl_endpointNotDefined() {
when(config.getString(Configuration.CONFIG_KEY_INGEST_URL, otelEndpoint))
.thenReturn(otelEndpoint);
String result = Configuration.getConfigUrl(config);
assertEquals(result, otelEndpoint);
assertEquals(otelEndpoint, result);
}

@Test
Expand All @@ -67,4 +71,29 @@ void getConfigUrlSplunkRealm() {
String result = Configuration.getConfigUrl(config);
assertNull(result);
}

@Test
void getOtlpProtocolDefault() {
String result =
Configuration.getOtlpProtocol(DefaultConfigProperties.create(Collections.emptyMap()));
assertEquals("http/protobuf", result);
}

@Test
void getOtlpProtocolOtelPropertySet() {
String result =
Configuration.getOtlpProtocol(
DefaultConfigProperties.create(
Collections.singletonMap("otel.exporter.otlp.protocol", "test")));
assertEquals("test", result);
}

@Test
void getOtlpProtocol() {
Map<String, String> map = new HashMap<>();
map.put("otel.exporter.otlp.protocol", "test1");
map.put("splunk.profiler.otlp.protocol", "test2");
String result = Configuration.getOtlpProtocol(DefaultConfigProperties.create(map));
assertEquals("test2", result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ void testCustomEndpointGrpc() {
when(builder.addHeader(EXTRA_CONTENT_TYPE, STACKTRACES_HEADER_VALUE)).thenReturn(builder);
when(builder.build()).thenReturn(expected);

when(config.getString(Configuration.CONFIG_KEY_OTLP_PROTOCOL)).thenReturn("grpc");
when(config.getString(Configuration.CONFIG_KEY_PROFILER_OTLP_PROTOCOL, null))
.thenReturn("grpc");
when(config.getString(Configuration.CONFIG_KEY_OTEL_OTLP_URL, null))
.thenReturn("http://shadowed.example.com:9122/");
when(config.getString(Configuration.CONFIG_KEY_INGEST_URL, "http://shadowed.example.com:9122/"))
Expand All @@ -97,7 +98,8 @@ void testCustomEndpointHttp() {
when(builder.addHeader(EXTRA_CONTENT_TYPE, STACKTRACES_HEADER_VALUE)).thenReturn(builder);
when(builder.build()).thenReturn(expected);

when(config.getString(Configuration.CONFIG_KEY_OTLP_PROTOCOL)).thenReturn("http/protobuf");
when(config.getString(Configuration.CONFIG_KEY_PROFILER_OTLP_PROTOCOL, null))
.thenReturn("http/protobuf");
when(config.getString(Configuration.CONFIG_KEY_OTEL_OTLP_URL, null))
.thenReturn("http://shadowed.example.com:9122/");
when(config.getString(
Expand Down