Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix override
  • Loading branch information
attilakreiner committed Mar 11, 2024
commit 1544c29cc427c7b2f3fc9c1616bfb3bb34e72a9e
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@ public class OtlpEndpointConfig
{
public String protocol;
public URI location;
public OtlpOverridesConfig overrides;

public OtlpEndpointConfig(
String protocol,
URI location,
OtlpOverridesConfig overrides)
URI location)
{
this.protocol = protocol;
this.location = location;
this.overrides = overrides;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class OltpConfiguration extends Configuration
public static final PropertyDef<Duration> OTLP_EXPORTER_RETRY_INTERVAL;
public static final PropertyDef<Duration> OTLP_EXPORTER_TIMEOUT_INTERVAL;
public static final PropertyDef<Duration> OTLP_EXPORTER_WARNING_INTERVAL;
public static final PropertyDef<String> OTLP_EXPORTER_METRICS_OVERRIDE;
public static final PropertyDef<String> OTLP_EXPORTER_LOGS_OVERRIDE;

private static final ConfigurationDef OTLP_EXPORTER_CONFIG;

Expand All @@ -35,6 +37,8 @@ public class OltpConfiguration extends Configuration
(c, v) -> Duration.parse(v), "PT30S");
OTLP_EXPORTER_WARNING_INTERVAL = config.property(Duration.class, "warning.interval",
(c, v) -> Duration.parse(v), "PT5M");
OTLP_EXPORTER_METRICS_OVERRIDE = config.property("metrics.override");
OTLP_EXPORTER_LOGS_OVERRIDE = config.property("logs.override");
OTLP_EXPORTER_CONFIG = config;
}

Expand All @@ -58,4 +62,15 @@ public Duration warningInterval()
{
return OTLP_EXPORTER_WARNING_INTERVAL.get(this);
}

// TODO: Ati
Comment thread
attilakreiner marked this conversation as resolved.
Outdated
public String metricsOverride()
{
return OTLP_EXPORTER_METRICS_OVERRIDE.get(this);
}

public String logsOverride()
{
return OTLP_EXPORTER_LOGS_OVERRIDE.get(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public OltpExporterHandler(
this.timeoutInterval = config.timeoutInterval();
this.warningInterval = config.warningInterval().toMillis();
this.context = context;
this.metricsEndpoint = exporter.resolveMetrics();
this.logsEndpoint = exporter.resolveLogs();
this.metricsEndpoint = exporter.resolveMetrics(config.metricsOverride());
this.logsEndpoint = exporter.resolveLogs(config.logsOverride());
this.signals = exporter.resolveSignals();
this.protocol = exporter.resolveProtocol();
this.interval = exporter.resolveInterval();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,12 @@
import jakarta.json.bind.adapter.JsonbAdapter;

import io.aklivity.zilla.runtime.exporter.otlp.config.OtlpEndpointConfig;
import io.aklivity.zilla.runtime.exporter.otlp.config.OtlpOverridesConfig;

public class OtlpEndpointAdapter implements JsonbAdapter<OtlpEndpointConfig, JsonObject>
{
private static final String PROTOCOL_NAME = "protocol";
private static final String PROTOCOL_DEFAULT = "http";
private static final String LOCATION_NAME = "location";
private static final String OVERRIDES_NAME = "overrides";

private final OtlpOverridesAdapter overrides;

public OtlpEndpointAdapter()
{
this.overrides = new OtlpOverridesAdapter();
}

@Override
public JsonObject adaptToJson(
Expand All @@ -51,10 +42,6 @@ public JsonObject adaptToJson(
{
object.add(LOCATION_NAME, endpoint.location.toString());
}
if (endpoint.overrides != null)
{
object.add(OVERRIDES_NAME, overrides.adaptToJson(endpoint.overrides));
}
return object.build();
}

Expand All @@ -66,9 +53,6 @@ public OtlpEndpointConfig adaptFromJson(
? object.getString(PROTOCOL_NAME)
: PROTOCOL_DEFAULT;
URI url = URI.create(object.getString(LOCATION_NAME));
OtlpOverridesConfig overridesConfig = object.containsKey(OVERRIDES_NAME)
? overrides.adaptFromJson(object.getJsonObject(OVERRIDES_NAME))
: null;
return new OtlpEndpointConfig(protocol, url, overridesConfig);
return new OtlpEndpointConfig(protocol, url);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,18 @@ public OtlpExporterConfig(
this.options = (OtlpOptionsConfig)exporter.options;
}

public URI resolveMetrics()
public URI resolveMetrics(
String override)
{
assert options != null;
assert options.endpoint != null;
assert options.endpoint.location != null;

URI result;
URI location = options.endpoint.location;
if (options.endpoint.overrides != null && options.endpoint.overrides.metrics != null)
if (override != null)
{
result = location.resolve(options.endpoint.overrides.metrics);
result = location.resolve(override);
}
else
{
Expand All @@ -58,17 +59,18 @@ public URI resolveMetrics()
return result;
}

public URI resolveLogs()
public URI resolveLogs(
String override)
{
assert options != null;
assert options.endpoint != null;
assert options.endpoint.location != null;

URI result;
URI location = options.endpoint.location;
if (options.endpoint.overrides != null && options.endpoint.overrides.logs != null)
if (override != null)
{
result = location.resolve(options.endpoint.overrides.logs);
result = location.resolve(override);
}
else
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

import io.aklivity.zilla.runtime.exporter.otlp.config.OtlpEndpointConfig;
import io.aklivity.zilla.runtime.exporter.otlp.config.OtlpOptionsConfig;
import io.aklivity.zilla.runtime.exporter.otlp.config.OtlpOverridesConfig;

public class OltpOptionsConfigAdapterTest
{
Expand All @@ -60,12 +59,7 @@ public void shouldReadOptions()
"],\n" +
"\"endpoint\":\n" +
"{\n" +
"\"location\": \"http://localhost:4317\",\n" +
"\"overrides\": \n" +
"{\n" +
"\"metrics\": \"/v1/metricsOverride\",\n" +
"\"logs\": \"/v1/logsOverride\"\n" +
"}\n" +
"\"location\": \"http://localhost:4317\"\n" +
"}\n" +
"}";

Expand All @@ -77,8 +71,6 @@ public void shouldReadOptions()
assertThat(options.interval, equalTo(30L));
assertThat(options.signals, containsInAnyOrder(METRICS));
assertThat(options.endpoint.location, equalTo(URI.create("http://localhost:4317")));
assertThat(options.endpoint.overrides.metrics, equalTo(URI.create("/v1/metricsOverride")));
assertThat(options.endpoint.overrides.logs, equalTo(URI.create("/v1/logsOverride")));
}

@Test
Expand All @@ -94,16 +86,10 @@ public void shouldWriteOptions()
"]," +
"\"endpoint\":" +
"{" +
"\"location\":\"http://localhost:4317\"," +
"\"overrides\":" +
"{" +
"\"metrics\":\"/v1/metrics\"," +
"\"logs\":\"/v1/logs\"" +
"}" +
"\"location\":\"http://localhost:4317\"" +
"}" +
"}";
OtlpOverridesConfig overrides = new OtlpOverridesConfig(URI.create("/v1/metrics"), URI.create("/v1/logs"));
OtlpEndpointConfig endpoint = new OtlpEndpointConfig("http", URI.create("http://localhost:4317"), overrides);
OtlpEndpointConfig endpoint = new OtlpEndpointConfig("http", URI.create("http://localhost:4317"));
OtlpOptionsConfig config = new OtlpOptionsConfig(30, Set.of(METRICS), endpoint);

// WHEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@
import io.aklivity.zilla.runtime.engine.config.ExporterConfig;
import io.aklivity.zilla.runtime.exporter.otlp.config.OtlpEndpointConfig;
import io.aklivity.zilla.runtime.exporter.otlp.config.OtlpOptionsConfig;
import io.aklivity.zilla.runtime.exporter.otlp.config.OtlpOverridesConfig;

public class OtlpExporterConfigTest
{
@Test
public void shouldCreateDefaultMetricsUrl()
{
// GIVEN
OtlpOverridesConfig overrides = new OtlpOverridesConfig(null, null);
OtlpEndpointConfig endpoint = new OtlpEndpointConfig("http", URI.create("http://example.com"), overrides);
OtlpEndpointConfig endpoint = new OtlpEndpointConfig("http", URI.create("http://example.com"));
OtlpOptionsConfig options = new OtlpOptionsConfig(30L, Set.of(METRICS), endpoint);
ExporterConfig exporter = ExporterConfig.builder()
.namespace("test")
Expand All @@ -46,8 +44,8 @@ public void shouldCreateDefaultMetricsUrl()
OtlpExporterConfig oltpExporter = new OtlpExporterConfig(exporter);

// WHEN
URI metrics = oltpExporter.resolveMetrics();
URI logs = oltpExporter.resolveLogs();
URI metrics = oltpExporter.resolveMetrics(null);
URI logs = oltpExporter.resolveLogs(null);

// THEN
assertThat(metrics, equalTo(URI.create("http://example.com/v1/metrics")));
Expand All @@ -58,9 +56,7 @@ public void shouldCreateDefaultMetricsUrl()
public void shouldOverrideAbsoluteMetricsUrl()
{
// GIVEN
OtlpOverridesConfig overrides = new OtlpOverridesConfig(URI.create("http://overridden.com/metrics"),
URI.create("http://overridden.com/logs"));
OtlpEndpointConfig endpoint = new OtlpEndpointConfig("http", URI.create("http://example.com"), overrides);
OtlpEndpointConfig endpoint = new OtlpEndpointConfig("http", URI.create("http://example.com"));
OtlpOptionsConfig options = new OtlpOptionsConfig(30L, Set.of(METRICS), endpoint);
ExporterConfig exporter = ExporterConfig.builder()
.namespace("test")
Expand All @@ -71,8 +67,8 @@ public void shouldOverrideAbsoluteMetricsUrl()
OtlpExporterConfig oltpExporter = new OtlpExporterConfig(exporter);

// WHEN
URI metrics = oltpExporter.resolveMetrics();
URI logs = oltpExporter.resolveLogs();
URI metrics = oltpExporter.resolveMetrics("http://overridden.com/metrics");
URI logs = oltpExporter.resolveLogs("http://overridden.com/logs");

// THEN
assertThat(metrics, equalTo(URI.create("http://overridden.com/metrics")));
Expand All @@ -83,8 +79,7 @@ public void shouldOverrideAbsoluteMetricsUrl()
public void shouldOverrideRelativeMetricsUrl()
{
// GIVEN
OtlpOverridesConfig overrides = new OtlpOverridesConfig(URI.create("/v42/metrix"), URI.create("/v42/logz"));
OtlpEndpointConfig endpoint = new OtlpEndpointConfig("http", URI.create("http://example.com"), overrides);
OtlpEndpointConfig endpoint = new OtlpEndpointConfig("http", URI.create("http://example.com"));
OtlpOptionsConfig options = new OtlpOptionsConfig(30L, Set.of(METRICS), endpoint);
ExporterConfig exporter = ExporterConfig.builder()
.namespace("test")
Expand All @@ -95,8 +90,8 @@ public void shouldOverrideRelativeMetricsUrl()
OtlpExporterConfig oltpExporter = new OtlpExporterConfig(exporter);

// WHEN
URI metrics = oltpExporter.resolveMetrics();
URI logs = oltpExporter.resolveLogs();
URI metrics = oltpExporter.resolveMetrics("/v42/metrix");
URI logs = oltpExporter.resolveLogs("/v42/logz");

// THEN
assertThat(metrics, equalTo(URI.create("http://example.com/v42/metrix")));
Expand Down