From a05a4ab91136af7b7ff896b5f51dd706006f7fef Mon Sep 17 00:00:00 2001 From: Ryan Dens Date: Mon, 28 Jun 2021 14:37:17 -0400 Subject: [PATCH 1/7] :sparkles: add Reporting to InstrumentationConfig --- .../core/config/InstrumentationConfig.java | 36 +++++++++++ .../config/InstrumentationConfigImpl.java | 60 +++++++++++++++++++ 2 files changed, 96 insertions(+) diff --git a/javaagent-core/src/main/java/org/hypertrace/agent/core/config/InstrumentationConfig.java b/javaagent-core/src/main/java/org/hypertrace/agent/core/config/InstrumentationConfig.java index 9aec3fe57..17d6fa0fe 100644 --- a/javaagent-core/src/main/java/org/hypertrace/agent/core/config/InstrumentationConfig.java +++ b/javaagent-core/src/main/java/org/hypertrace/agent/core/config/InstrumentationConfig.java @@ -39,13 +39,49 @@ public interface InstrumentationConfig { /** Data capture for RPC body */ Message rpcBody(); + Reporting reporting(); + /** Message holds data capture configuration for various entities. */ interface Message { + boolean request(); boolean response(); } + interface Reporting { + + /** + * @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(); + } + default boolean isInstrumentationEnabled(String primaryName, String[] otherNames) { // the instNames is not used because the config does not support it at the moment. 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..62ff96c37 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,9 @@ 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.config.Config.Opa; +import org.hypertrace.agent.config.Config.Reporting; import org.hypertrace.agent.core.config.InstrumentationConfig; @AutoService(InstrumentationConfig.class) @@ -31,6 +34,7 @@ public class InstrumentationConfigImpl implements InstrumentationConfig { private final Message httpBody; private final Message rpcMetadata; private final Message rpcBody; + private final Reporting reporting; public InstrumentationConfigImpl() { DataCapture dataCapture = agentConfig.getDataCapture(); @@ -38,6 +42,7 @@ public InstrumentationConfigImpl() { this.httpBody = new MessageImpl(dataCapture.getHttpBody()); this.rpcMetadata = new MessageImpl(dataCapture.getRpcMetadata()); this.rpcBody = new MessageImpl(dataCapture.getRpcBody()); + reporting = new ReportingImpl(agentConfig.getReporting()); } @Override @@ -65,6 +70,11 @@ public Message rpcBody() { return this.rpcBody; } + @Override + public Reporting reporting() { + return reporting; + } + private class MessageImpl implements Message { private final Config.Message message; @@ -83,4 +93,54 @@ public boolean response() { return message.getResponse().getValue(); } } + + private static final class ReportingImpl implements Reporting { + + private final Opa opa; + private final Config.Reporting reporting; + + public ReportingImpl(final Config.Reporting reporting) { + 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.getEnabled().getValue(); + } + + @Override + public String endpoint() { + return opa.getEndpoint().getValue(); + } + + @Override + public int pollPeriodSeconds() { + return opa.getPollPeriodSeconds().getValue(); + } + } } From bc68fd3d10fb299ad4e4b628ecd8adeda118dc5d Mon Sep 17 00:00:00 2001 From: Ryan Dens Date: Mon, 28 Jun 2021 14:43:00 -0400 Subject: [PATCH 2/7] :recycle: make MessageImpl static and final --- .../agent/otel/extensions/config/InstrumentationConfigImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 62ff96c37..c5ea0870f 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 @@ -75,7 +75,7 @@ public Reporting reporting() { return reporting; } - private class MessageImpl implements Message { + private static final class MessageImpl implements Message { private final Config.Message message; From 1ae22461c765fc3092f712d0acc16059f66cffba Mon Sep 17 00:00:00 2001 From: Ryan Dens Date: Mon, 28 Jun 2021 15:07:21 -0400 Subject: [PATCH 3/7] :recycle: separate ReportingConfig from InstrumentationConfig --- .../core/config/InstrumentationConfig.java | 35 --------- .../agent/core/config/ReportingConfig.java | 50 +++++++++++++ .../config/InstrumentationConfigImpl.java | 59 --------------- .../config/ReportingConfigImpl.java | 72 +++++++++++++++++++ 4 files changed, 122 insertions(+), 94 deletions(-) create mode 100644 javaagent-core/src/main/java/org/hypertrace/agent/core/config/ReportingConfig.java create mode 100644 otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/ReportingConfigImpl.java diff --git a/javaagent-core/src/main/java/org/hypertrace/agent/core/config/InstrumentationConfig.java b/javaagent-core/src/main/java/org/hypertrace/agent/core/config/InstrumentationConfig.java index 17d6fa0fe..b9a14e128 100644 --- a/javaagent-core/src/main/java/org/hypertrace/agent/core/config/InstrumentationConfig.java +++ b/javaagent-core/src/main/java/org/hypertrace/agent/core/config/InstrumentationConfig.java @@ -39,8 +39,6 @@ public interface InstrumentationConfig { /** Data capture for RPC body */ Message rpcBody(); - Reporting reporting(); - /** Message holds data capture configuration for various entities. */ interface Message { @@ -49,39 +47,6 @@ interface Message { boolean response(); } - interface Reporting { - - /** - * @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(); - } - default boolean isInstrumentationEnabled(String primaryName, String[] otherNames) { // the instNames is not used because the config does not support it at the moment. 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..23b0065f9 --- /dev/null +++ b/javaagent-core/src/main/java/org/hypertrace/agent/core/config/ReportingConfig.java @@ -0,0 +1,50 @@ +/* + * 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; + +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(); + } +} 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 c5ea0870f..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 @@ -21,8 +21,6 @@ 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.config.Config.Opa; -import org.hypertrace.agent.config.Config.Reporting; import org.hypertrace.agent.core.config.InstrumentationConfig; @AutoService(InstrumentationConfig.class) @@ -34,7 +32,6 @@ public class InstrumentationConfigImpl implements InstrumentationConfig { private final Message httpBody; private final Message rpcMetadata; private final Message rpcBody; - private final Reporting reporting; public InstrumentationConfigImpl() { DataCapture dataCapture = agentConfig.getDataCapture(); @@ -42,7 +39,6 @@ public InstrumentationConfigImpl() { this.httpBody = new MessageImpl(dataCapture.getHttpBody()); this.rpcMetadata = new MessageImpl(dataCapture.getRpcMetadata()); this.rpcBody = new MessageImpl(dataCapture.getRpcBody()); - reporting = new ReportingImpl(agentConfig.getReporting()); } @Override @@ -70,11 +66,6 @@ public Message rpcBody() { return this.rpcBody; } - @Override - public Reporting reporting() { - return reporting; - } - private static final class MessageImpl implements Message { private final Config.Message message; @@ -93,54 +84,4 @@ public boolean response() { return message.getResponse().getValue(); } } - - private static final class ReportingImpl implements Reporting { - - private final Opa opa; - private final Config.Reporting reporting; - - public ReportingImpl(final Config.Reporting reporting) { - 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.getEnabled().getValue(); - } - - @Override - public String endpoint() { - return opa.getEndpoint().getValue(); - } - - @Override - public int pollPeriodSeconds() { - return opa.getPollPeriodSeconds().getValue(); - } - } } 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..d1e707bb0 --- /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) { + 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.getEnabled().getValue(); + } + + @Override + public String endpoint() { + return opa.getEndpoint().getValue(); + } + + @Override + public int pollPeriodSeconds() { + return opa.getPollPeriodSeconds().getValue(); + } + } +} From 588f9794656d7d3b0ad44a33f407de9b3cc51b09 Mon Sep 17 00:00:00 2001 From: Ryan Dens Date: Mon, 28 Jun 2021 15:30:30 -0400 Subject: [PATCH 4/7] :sparkles: add ReportingConfig static accessor API --- .../agent/core/config/ReportingConfig.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) 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 index 23b0065f9..71ea210d9 100644 --- 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 @@ -16,6 +16,11 @@ 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 { /** @@ -47,4 +52,32 @@ interface Opa { 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; + } + } } From 85311aafe46e4214e823b544c3f82be8f789b516 Mon Sep 17 00:00:00 2001 From: Ryan Dens Date: Mon, 28 Jun 2021 16:25:26 -0400 Subject: [PATCH 5/7] :ok_hand: add this qualifier to OPA field on ReportingConfigImpl --- .../agent/otel/extensions/config/ReportingConfigImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index d1e707bb0..3ff3a8400 100644 --- 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 @@ -27,7 +27,7 @@ public final class ReportingConfigImpl implements ReportingConfig { private final Config.Reporting reporting; public ReportingConfigImpl(final Config.Reporting reporting) { - opa = new OpaImpl(reporting.getOpa()); + this.opa = new OpaImpl(reporting.getOpa()); this.reporting = reporting; } From 881f1a3bd997c922f9a771680ea4375012e5f6f7 Mon Sep 17 00:00:00 2001 From: Ryan Dens Date: Mon, 28 Jun 2021 16:26:54 -0400 Subject: [PATCH 6/7] :art: remove whitespace change --- .../org/hypertrace/agent/core/config/InstrumentationConfig.java | 1 - 1 file changed, 1 deletion(-) diff --git a/javaagent-core/src/main/java/org/hypertrace/agent/core/config/InstrumentationConfig.java b/javaagent-core/src/main/java/org/hypertrace/agent/core/config/InstrumentationConfig.java index b9a14e128..9aec3fe57 100644 --- a/javaagent-core/src/main/java/org/hypertrace/agent/core/config/InstrumentationConfig.java +++ b/javaagent-core/src/main/java/org/hypertrace/agent/core/config/InstrumentationConfig.java @@ -41,7 +41,6 @@ public interface InstrumentationConfig { /** Message holds data capture configuration for various entities. */ interface Message { - boolean request(); boolean response(); From bab5dcaa5aa445f9a0493571422719db50c8f9f5 Mon Sep 17 00:00:00 2001 From: Ryan Dens Date: Mon, 28 Jun 2021 17:04:48 -0400 Subject: [PATCH 7/7] :recycle: return true for Opa.enabled if Opa.hasEnabled() is false --- .../agent/otel/extensions/config/ReportingConfigImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 3ff3a8400..707f60445 100644 --- 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 @@ -56,7 +56,7 @@ public OpaImpl(final Config.Opa opa) { @Override public boolean enabled() { - return opa.getEnabled().getValue(); + return opa.hasEnabled() ? opa.getEnabled().getValue() : true; } @Override