Skip to content
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 @@ -23,36 +23,10 @@

public interface ReportingConfig {

/**
* @return the {@link Opa} config implementation
* @see Opa for more information on why this API is deprecated
*/
@Deprecated
Opa opa();

boolean secure();

String token();

/**
* Opa holds the configuration for the agent and filter implementations should interact with a
* remote Open Policy Agent endpoint.
*
* <p>Note, this API is deprecated because it is a goal of the Hypertrace community to migrate
* away form supplying this vendor-specific config and instead have authors of Hypertrace
* extensions/filters to have an indiomatic way to extned the Hypertrace configuration properties
* for their use cases
*/
@Deprecated
interface Opa {

boolean enabled();

String endpoint();

int pollPeriodSeconds();
}

final class ConfigProvider {

private static final Logger logger = LoggerFactory.getLogger(ConfigProvider.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import org.hypertrace.agent.config.v1.Config.DataCapture;
import org.hypertrace.agent.config.v1.Config.JavaAgent;
import org.hypertrace.agent.config.v1.Config.Message;
import org.hypertrace.agent.config.v1.Config.Opa;
import org.hypertrace.agent.config.v1.Config.Opa.Builder;
import org.hypertrace.agent.config.v1.Config.PropagationFormat;
import org.hypertrace.agent.config.v1.Config.Reporting;
import org.hypertrace.agent.config.v1.Config.TraceReporterType;
Expand All @@ -48,11 +46,6 @@ private EnvironmentConfig() {}
static final String REPORTING_SECURE = REPORTING_PREFIX + "secure";
static final String REPORTING_CERT_FILE = REPORTING_PREFIX + "cert.file";

private static final String OPA_PREFIX = REPORTING_PREFIX + "opa.";
static final String OPA_ENDPOINT = OPA_PREFIX + "endpoint";
static final String OPA_POLL_PERIOD = OPA_PREFIX + "poll.period.seconds";
static final String OPA_ENABLED = OPA_PREFIX + "enabled";

private static final String CAPTURE_PREFIX = HT_PREFIX + "data.capture.";
public static final String CAPTURE_BODY_MAX_SIZE_BYTES = CAPTURE_PREFIX + "body.max.size.bytes";
public static final String CAPTURE_HTTP_HEADERS_PREFIX = CAPTURE_PREFIX + "http.headers.";
Expand Down Expand Up @@ -138,25 +131,6 @@ private static Reporting.Builder applyReporting(Reporting.Builder builder) {
if (certFilePath != null) {
builder.setCertFile(StringValue.of(certFilePath));
}
Builder opaBuilder = applyOpa(builder.getOpa().toBuilder());
builder.setOpa(opaBuilder);
return builder;
}

private static Opa.Builder applyOpa(Opa.Builder builder) {
String address = getProperty(OPA_ENDPOINT);
if (address != null) {
builder.setEndpoint(StringValue.newBuilder().setValue(address).build());
}
String pollPeriod = getProperty(OPA_POLL_PERIOD);
if (pollPeriod != null) {
builder.setPollPeriodSeconds(
Int32Value.newBuilder().setValue(Integer.parseInt(pollPeriod)).build());
}
String enabled = getProperty(OPA_ENABLED);
if (enabled != null) {
builder.setEnabled(BoolValue.newBuilder().setValue(Boolean.valueOf(enabled)).build());
}
return builder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
import org.hypertrace.agent.config.v1.Config.AgentConfig;
import org.hypertrace.agent.config.v1.Config.DataCapture;
import org.hypertrace.agent.config.v1.Config.Message;
import org.hypertrace.agent.config.v1.Config.Opa;
import org.hypertrace.agent.config.v1.Config.Opa.Builder;
import org.hypertrace.agent.config.v1.Config.PropagationFormat;
import org.hypertrace.agent.config.v1.Config.Reporting;
import org.hypertrace.agent.config.v1.Config.TraceReporterType;
Expand All @@ -54,8 +52,6 @@ private HypertraceConfig() {}

static final String DEFAULT_SERVICE_NAME = "unknown";
static final String DEFAULT_REPORTING_ENDPOINT = "http://localhost:4317";
static final String DEFAULT_OPA_ENDPOINT = "http://localhost:8181/";
static final int DEFAULT_OPA_POLL_PERIOD_SECONDS = 30;
// 128 KiB
static final int DEFAULT_BODY_MAX_SIZE_BYTES = 128 * 1024;

Expand Down Expand Up @@ -146,19 +142,6 @@ private static Reporting.Builder applyReportingDefaults(Reporting.Builder builde
if (builder.getTraceReporterType().equals(Config.TraceReporterType.UNSPECIFIED)) {
builder.setTraceReporterType(TraceReporterType.OTLP);
}
Builder opaBuilder = applyOpaDefaults(builder.getOpa().toBuilder());
builder.setOpa(opaBuilder);
return builder;
}

private static Opa.Builder applyOpaDefaults(Opa.Builder builder) {
if (!builder.hasEndpoint()) {
builder.setEndpoint(StringValue.newBuilder().setValue(DEFAULT_OPA_ENDPOINT).build());
}
if (!builder.hasPollPeriodSeconds()) {
builder.setPollPeriodSeconds(
Int32Value.newBuilder().setValue(DEFAULT_OPA_POLL_PERIOD_SECONDS).build());
}
return builder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
@AutoService(ReportingConfig.class)
public final class ReportingConfigImpl implements ReportingConfig {

private final Opa opa;
private final Config.Reporting reporting;

/**
Expand All @@ -37,12 +36,6 @@ public ReportingConfigImpl() {

public ReportingConfigImpl(final Config.Reporting reportingConfig) {
this.reporting = reportingConfig;
this.opa = new OpaImpl(reportingConfig.getOpa());
}

@Override
public Opa opa() {
return opa;
}

@Override
Expand All @@ -54,28 +47,4 @@ public boolean secure() {
public String token() {
return reporting.getToken().getValue();
}

private static final class OpaImpl implements Opa {

private final Config.Opa opa;

public OpaImpl(final Config.Opa opa) {
this.opa = opa;
}

@Override
public boolean enabled() {
return opa.hasEnabled() ? opa.getEnabled().getValue() : true;
}

@Override
public String endpoint() {
return opa.getEndpoint().getValue();
}

@Override
public int pollPeriodSeconds() {
return opa.getPollPeriodSeconds().getValue();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ class EnvironmentConfigTest {
@ClearSystemProperty(key = EnvironmentConfig.REPORTING_SECURE)
@ClearSystemProperty(key = EnvironmentConfig.REPORTING_TRACE_TYPE)
@ClearSystemProperty(key = EnvironmentConfig.REPORTING_CERT_FILE)
@ClearSystemProperty(key = EnvironmentConfig.OPA_ENDPOINT)
@ClearSystemProperty(key = EnvironmentConfig.OPA_POLL_PERIOD)
@ClearSystemProperty(key = EnvironmentConfig.OPA_ENABLED)
@ClearSystemProperty(key = EnvironmentConfig.PROPAGATION_FORMATS)
@ClearSystemProperty(key = EnvironmentConfig.CAPTURE_HTTP_BODY_PREFIX + "request")
@ClearSystemProperty(key = EnvironmentConfig.CAPTURE_BODY_MAX_SIZE_BYTES)
Expand All @@ -49,9 +46,6 @@ public void systemProperties() {
System.setProperty(EnvironmentConfig.REPORTING_SECURE, "true");
System.setProperty(EnvironmentConfig.REPORTING_CERT_FILE, "/bar/test.pem");
System.setProperty(EnvironmentConfig.CAPTURE_HTTP_BODY_PREFIX + "request", "true");
System.setProperty(EnvironmentConfig.OPA_ENDPOINT, "http://azkaban:9090");
System.setProperty(EnvironmentConfig.OPA_POLL_PERIOD, "10");
System.setProperty(EnvironmentConfig.OPA_ENABLED, "true");
System.setProperty(EnvironmentConfig.PROPAGATION_FORMATS, "B3,TRACECONTEXT");
System.setProperty(EnvironmentConfig.CAPTURE_BODY_MAX_SIZE_BYTES, "512");
System.setProperty(EnvironmentConfig.JAVAAGENT_FILTER_JAR_PATHS, "/path1.jar,/path/2/jar.jar");
Expand All @@ -73,11 +67,6 @@ public void systemProperties() {
Assertions.assertEquals("http://:-)", agentConfig.getReporting().getEndpoint().getValue());
Assertions.assertEquals(
TraceReporterType.OTLP, agentConfig.getReporting().getTraceReporterType());
Assertions.assertEquals(
"http://azkaban:9090", agentConfig.getReporting().getOpa().getEndpoint().getValue());
Assertions.assertEquals(true, agentConfig.getReporting().getOpa().getEnabled().getValue());
Assertions.assertEquals(
10, agentConfig.getReporting().getOpa().getPollPeriodSeconds().getValue());
Assertions.assertEquals(512, agentConfig.getDataCapture().getBodyMaxSizeBytes().getValue());
Assertions.assertEquals(true, agentConfig.getReporting().getSecure().getValue());
Assertions.assertEquals("/bar/test.pem", agentConfig.getReporting().getCertFile().getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ public void defaultValues() throws IOException {
Assertions.assertEquals(
Arrays.asList(PropagationFormat.TRACECONTEXT), agentConfig.getPropagationFormatsList());
Assertions.assertEquals(false, agentConfig.getReporting().getSecure().getValue());
Assertions.assertEquals(
HypertraceConfig.DEFAULT_OPA_ENDPOINT,
agentConfig.getReporting().getOpa().getEndpoint().getValue());
Assertions.assertEquals(
HypertraceConfig.DEFAULT_OPA_POLL_PERIOD_SECONDS,
agentConfig.getReporting().getOpa().getPollPeriodSeconds().getValue());
Assertions.assertEquals(
HypertraceConfig.DEFAULT_BODY_MAX_SIZE_BYTES,
agentConfig.getDataCapture().getBodyMaxSizeBytes().getValue());
Expand Down Expand Up @@ -111,10 +105,6 @@ private void assertConfig(AgentConfig agentConfig) {
Assertions.assertEquals(
"http://localhost:4317", agentConfig.getReporting().getEndpoint().getValue());
Assertions.assertEquals(true, agentConfig.getReporting().getSecure().getValue());
Assertions.assertEquals(
"http://opa.localhost:8181/", agentConfig.getReporting().getOpa().getEndpoint().getValue());
Assertions.assertEquals(
12, agentConfig.getReporting().getOpa().getPollPeriodSeconds().getValue());
Assertions.assertEquals(16, agentConfig.getDataCapture().getBodyMaxSizeBytes().getValue());
Assertions.assertEquals(
true, agentConfig.getDataCapture().getHttpHeaders().getRequest().getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@

import static org.junit.jupiter.api.Assertions.*;

import com.google.protobuf.BoolValue;
import java.util.Iterator;
import java.util.ServiceLoader;
import org.hypertrace.agent.config.v1.Config.Opa;
import org.hypertrace.agent.config.v1.Config.Reporting;
import org.hypertrace.agent.config.v1.Config.Reporting.Builder;
import org.hypertrace.agent.core.config.ReportingConfig;
import org.junit.jupiter.api.Test;

Expand All @@ -39,21 +35,4 @@ void instantiateViaServiceLoaderApi() {
assertNotNull(reportingConfig);
assertFalse(iterator.hasNext());
}

@Test
void opaEnabledIfNotProvided() {
final ReportingConfigImpl reportingConfig =
new ReportingConfigImpl(Reporting.getDefaultInstance());
assertTrue(reportingConfig.opa().enabled());
}

@Test
void opaDisabledIfExplicitlySet() {
final Builder reportingBuilder = Reporting.getDefaultInstance().toBuilder();
final Opa explicitOpaConfig =
reportingBuilder.getOpaBuilder().setEnabled(BoolValue.of(false)).build();
final ReportingConfigImpl reportingConfig =
new ReportingConfigImpl(reportingBuilder.setOpa(explicitOpaConfig).build());
assertFalse(reportingConfig.opa().enabled());
}
}
3 changes: 0 additions & 3 deletions otel-extensions/src/test/resources/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ reporting:
secure: true
trace_reporter_type: OTLP
cert_file: /foo/bar/example.pem
opa:
endpoint: http://opa.localhost:8181/
pollPeriodSeconds: 12
dataCapture:
bodyMaxSizeBytes: 16
httpHeaders:
Expand Down