Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
* Add Stable config source
* Add snakeyaml to parse file
  • Loading branch information
paullegranddc committed Feb 3, 2025
1 parent 6d86370 commit 5311824
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ dependencies {
// it contains annotations that are also present in the instrumented application classes
api "com.datadoghq:dd-javac-plugin-client:0.2.2"

implementation 'org.yaml:snakeyaml:2.0'

testImplementation project(":utils:test-utils")
testImplementation("org.assertj:assertj-core:3.20.2")
testImplementation libs.bundles.junit5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ public enum ConfigOrigin {
REMOTE("remote_config"),
/** configurations that are set through JVM properties */
JVM_PROP("jvm_prop"),
/** configuration read in the stable config file, managed by customers */
CUSTOMER_STABLE_CONFIG("customer_stable_config"),
/** configuration read in the stable config file, managed by fleet */
FLEET_STABLE_CONFIG("fleet_stable_config"),
/** set when the user has not set any configuration for the key (defaults to a value) */
DEFAULT("default");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package datadog.trace.bootstrap.config.provider;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashMap;

import static datadog.trace.util.Strings.propertyNameToEnvironmentVariableName;

import datadog.trace.api.ConfigOrigin;
import datadog.trace.bootstrap.config.provider.ConfigProvider;

import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.constructor.SafeConstructor;

final public class StableConfigSource extends ConfigProvider.Source {
static final String MANAGED_STABLE_CONFIGURATION_PATH = "/etc/datadog-agent/managed/datadog-agent/stable/datadog_apm.yaml";
static final String LOCAL_STABLE_CONFIGURATION_PATH = "/etc/datadog-agent/datadog_apm.yaml";

final ConfigOrigin fileOrigin;
HashMap<String, String> configuration;

StableConfigSource(String file, ConfigOrigin origin) {
this.fileOrigin = origin;
try {
configuration = parseStableConfig(file);
} catch (Exception e) {
configuration = new HashMap();
}
}

private static final HashMap<String, String> parseStableConfig(String filePath) {
Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions()));
InputStream input = new FileInputStream(new File(filePath));
Object data = yaml.load(input);

HashMap<Sting, Object> config = new HashMap();

return config;
};

public final String get(String key) {
return configuration.get(propertyNameToEnvironmentVariableName(key));
}

public final ConfigOrigin origin() {
return fileOrigin;
}

private class StableConfig {
private String config_id;
private HashMap<String, Object> apm_configuration_default;

private void setApmConfigurationDefault(HashMap<String, Object> m) {
apm_configuration_default = m;
}

private void setConfigId(String i) {
config_id = i;
}
}
}

0 comments on commit 5311824

Please sign in to comment.