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
Revert "fix override"
This reverts commit 1544c29.
  • Loading branch information
attilakreiner committed Mar 13, 2024
commit 143514e47172ffc1ecfd838184438b88fbdc4148
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ public class OtlpEndpointConfig
{
public String protocol;
public URI location;
public OtlpOverridesConfig overrides;

public OtlpEndpointConfig(
String protocol,
URI location)
URI location,
OtlpOverridesConfig overrides)
{
this.protocol = protocol;
this.location = location;
this.overrides = overrides;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2021-2023 Aklivity Inc
*
* Licensed under the Aklivity Community License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at
*
* https://www.aklivity.io/aklivity-community-license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package io.aklivity.zilla.runtime.exporter.otlp.config;

import java.net.URI;

public class OtlpOverridesConfig
Comment thread
attilakreiner marked this conversation as resolved.
{
public URI metrics;
public URI logs;

public OtlpOverridesConfig(
URI metrics,
URI logs)
{
this.metrics = metrics;
this.logs = logs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ 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 @@ -37,8 +35,6 @@ 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 @@ -62,14 +58,4 @@ public Duration warningInterval()
{
return OTLP_EXPORTER_WARNING_INTERVAL.get(this);
}

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(config.metricsOverride());
this.logsEndpoint = exporter.resolveLogs(config.logsOverride());
this.metricsEndpoint = exporter.resolveMetrics();
this.logsEndpoint = exporter.resolveLogs();
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,12 +22,21 @@
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 @@ -42,6 +51,10 @@ 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 @@ -53,6 +66,9 @@ public OtlpEndpointConfig adaptFromJson(
? object.getString(PROTOCOL_NAME)
: PROTOCOL_DEFAULT;
URI url = URI.create(object.getString(LOCATION_NAME));
return new OtlpEndpointConfig(protocol, url);
OtlpOverridesConfig overridesConfig = object.containsKey(OVERRIDES_NAME)
? overrides.adaptFromJson(object.getJsonObject(OVERRIDES_NAME))
: null;
return new OtlpEndpointConfig(protocol, url, overridesConfig);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,17 @@ public OtlpExporterConfig(
this.options = (OtlpOptionsConfig)exporter.options;
}

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

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

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

URI result;
URI location = options.endpoint.location;
if (override != null)
if (options.endpoint.overrides != null && options.endpoint.overrides.logs != null)
{
result = location.resolve(override);
result = location.resolve(options.endpoint.overrides.logs);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2021-2023 Aklivity Inc
*
* Licensed under the Aklivity Community License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at
*
* https://www.aklivity.io/aklivity-community-license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package io.aklivity.zilla.runtime.exporter.otlp.internal.config;

import java.net.URI;

import jakarta.json.Json;
import jakarta.json.JsonObject;
import jakarta.json.JsonObjectBuilder;
import jakarta.json.bind.adapter.JsonbAdapter;

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

public class OtlpOverridesAdapter implements JsonbAdapter<OtlpOverridesConfig, JsonObject>
{
private static final String METRICS_NAME = "metrics";
private static final String LOGS_NAME = "logs";

@Override
public JsonObject adaptToJson(
OtlpOverridesConfig overrides)
{
JsonObjectBuilder object = Json.createObjectBuilder();
if (overrides.metrics != null)
{
object.add(METRICS_NAME, overrides.metrics.toString());
}
if (overrides.logs != null)
{
object.add(LOGS_NAME, overrides.logs.toString());
}
return object.build();
}

@Override
public OtlpOverridesConfig adaptFromJson(
JsonObject object)
{
URI metrics = object.containsKey(METRICS_NAME)
? URI.create(object.getString(METRICS_NAME))
: null;
URI logs = object.containsKey(LOGS_NAME)
? URI.create(object.getString(LOGS_NAME))
: null;
return new OtlpOverridesConfig(metrics, logs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

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 @@ -59,7 +60,12 @@ public void shouldReadOptions()
"],\n" +
"\"endpoint\":\n" +
"{\n" +
"\"location\": \"http://localhost:4317\"\n" +
"\"location\": \"http://localhost:4317\",\n" +
"\"overrides\": \n" +
"{\n" +
"\"metrics\": \"/v1/metricsOverride\",\n" +
"\"logs\": \"/v1/logsOverride\"\n" +
"}\n" +
"}\n" +
"}";

Expand All @@ -71,6 +77,8 @@ 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 @@ -86,10 +94,16 @@ public void shouldWriteOptions()
"]," +
"\"endpoint\":" +
"{" +
"\"location\":\"http://localhost:4317\"" +
"\"location\":\"http://localhost:4317\"," +
"\"overrides\":" +
"{" +
"\"metrics\":\"/v1/metrics\"," +
"\"logs\":\"/v1/logs\"" +
"}" +
"}" +
"}";
OtlpEndpointConfig endpoint = new OtlpEndpointConfig("http", URI.create("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);
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,14 +26,16 @@
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
OtlpEndpointConfig endpoint = new OtlpEndpointConfig("http", URI.create("http://example.com"));
OtlpOverridesConfig overrides = new OtlpOverridesConfig(null, null);
OtlpEndpointConfig endpoint = new OtlpEndpointConfig("http", URI.create("http://example.com"), overrides);
OtlpOptionsConfig options = new OtlpOptionsConfig(30L, Set.of(METRICS), endpoint);
ExporterConfig exporter = ExporterConfig.builder()
.namespace("test")
Expand All @@ -44,8 +46,8 @@ public void shouldCreateDefaultMetricsUrl()
OtlpExporterConfig oltpExporter = new OtlpExporterConfig(exporter);

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

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

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

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

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

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