diff --git a/javaagent-core/src/main/java/org/hypertrace/agent/core/config/ReportingConfig.java b/javaagent-core/src/main/java/org/hypertrace/agent/core/config/ReportingConfig.java new file mode 100644 index 000000000..71ea210d9 --- /dev/null +++ b/javaagent-core/src/main/java/org/hypertrace/agent/core/config/ReportingConfig.java @@ -0,0 +1,83 @@ +/* + * Copyright The Hypertrace Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.hypertrace.agent.core.config; + +import java.util.Iterator; +import java.util.ServiceLoader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +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. + * + *

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); + + private static volatile ReportingConfig reportingConfig; + + private static ReportingConfig load() { + ServiceLoader configs = ServiceLoader.load(ReportingConfig.class); + Iterator iterator = configs.iterator(); + if (!iterator.hasNext()) { + logger.error("Failed to load reporting config"); + return null; + } + return iterator.next(); + } + + public static ReportingConfig get() { + if (reportingConfig == null) { + synchronized (ConfigProvider.class) { + if (reportingConfig == null) { + reportingConfig = load(); + } + } + } + return reportingConfig; + } + } +} diff --git a/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/InstrumentationConfigImpl.java b/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/InstrumentationConfigImpl.java index 6859b5ffc..e49a42310 100644 --- a/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/InstrumentationConfigImpl.java +++ b/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/InstrumentationConfigImpl.java @@ -20,6 +20,7 @@ import org.hypertrace.agent.config.Config; import org.hypertrace.agent.config.Config.AgentConfig; import org.hypertrace.agent.config.Config.DataCapture; +import org.hypertrace.agent.config.Config.Message; import org.hypertrace.agent.core.config.InstrumentationConfig; @AutoService(InstrumentationConfig.class) @@ -65,7 +66,7 @@ public Message rpcBody() { return this.rpcBody; } - private class MessageImpl implements Message { + private static final class MessageImpl implements Message { private final Config.Message message; diff --git a/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/ReportingConfigImpl.java b/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/ReportingConfigImpl.java new file mode 100644 index 000000000..707f60445 --- /dev/null +++ b/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/ReportingConfigImpl.java @@ -0,0 +1,72 @@ +/* + * Copyright The Hypertrace Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.hypertrace.agent.otel.extensions.config; + +import com.google.auto.service.AutoService; +import org.hypertrace.agent.config.Config; +import org.hypertrace.agent.core.config.ReportingConfig; + +@AutoService(ReportingConfig.class) +public final class ReportingConfigImpl implements ReportingConfig { + + private final Opa opa; + private final Config.Reporting reporting; + + public ReportingConfigImpl(final Config.Reporting reporting) { + this.opa = new OpaImpl(reporting.getOpa()); + this.reporting = reporting; + } + + @Override + public Opa opa() { + return opa; + } + + @Override + public boolean secure() { + return reporting.getSecure().getValue(); + } + + @Override + 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(); + } + } +}