-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Expose reporting config to consumers of
javaagent-core
so that `F…
…ilter` implementation authors can access them (#327)
- Loading branch information
Showing
3 changed files
with
157 additions
and
1 deletion.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
javaagent-core/src/main/java/org/hypertrace/agent/core/config/ReportingConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
* | ||
* <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); | ||
|
||
private static volatile ReportingConfig reportingConfig; | ||
|
||
private static ReportingConfig load() { | ||
ServiceLoader<ReportingConfig> configs = ServiceLoader.load(ReportingConfig.class); | ||
Iterator<ReportingConfig> 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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...nsions/src/main/java/org/hypertrace/agent/otel/extensions/config/ReportingConfigImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |