-
Notifications
You must be signed in to change notification settings - Fork 333
Expand file tree
/
Copy pathStableConfigSource.java
More file actions
105 lines (90 loc) · 3.28 KB
/
StableConfigSource.java
File metadata and controls
105 lines (90 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package datadog.trace.bootstrap.config.provider;
import static datadog.trace.util.Strings.propertyNameToEnvironmentVariableName;
import datadog.trace.api.ConfigOrigin;
import datadog.trace.bootstrap.config.provider.stableconfig.StableConfigMappingException;
import java.io.File;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class StableConfigSource extends ConfigProvider.Source {
private static final Logger log = LoggerFactory.getLogger(StableConfigSource.class);
public static final String LOCAL_STABLE_CONFIG_PATH =
"/etc/datadog-agent/application_monitoring.yaml";
public static final String FLEET_STABLE_CONFIG_PATH =
"/etc/datadog-agent/managed/datadog-agent/stable/application_monitoring.yaml";
public static final StableConfigSource LOCAL =
new StableConfigSource(LOCAL_STABLE_CONFIG_PATH, ConfigOrigin.LOCAL_STABLE_CONFIG);
public static final StableConfigSource FLEET =
new StableConfigSource(
StableConfigSource.FLEET_STABLE_CONFIG_PATH, ConfigOrigin.FLEET_STABLE_CONFIG);
private final ConfigOrigin fileOrigin;
private final StableConfig config;
StableConfigSource(String filePath, ConfigOrigin origin) {
this.fileOrigin = origin;
File file = new File(filePath);
if (!file.exists()) {
this.config = StableConfig.EMPTY;
return;
}
StableConfig cfg;
try {
log.debug("Stable configuration file found at path: {}", file);
cfg = StableConfigParser.parse(filePath);
} catch (StableConfigMappingException
| IllegalArgumentException
| ClassCastException
| NullPointerException e) {
log.warn("YAML mapping error in stable configuration file {}: {}", filePath, e.getMessage());
cfg = StableConfig.EMPTY;
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.error("Unexpected error while reading stable configuration file {}: {}", filePath, e);
} else {
log.error(
"Unexpected error while reading stable configuration file {}: {}",
filePath,
e.getMessage());
}
cfg = StableConfig.EMPTY;
}
this.config = cfg;
}
@Override
public String get(String key) {
if (this.config == StableConfig.EMPTY) {
return null;
}
return this.config.get(propertyNameToEnvironmentVariableName(key));
}
@Override
public ConfigOrigin origin() {
return fileOrigin;
}
public Set<String> getKeys() {
return this.config.getKeys();
}
public String getConfigId() {
return this.config.getConfigId();
}
public static class StableConfig {
public static final StableConfig EMPTY = new StableConfig(null, Collections.emptyMap());
private final Map<String, Object> apmConfiguration;
private final String configId;
public StableConfig(String configId, Map<String, Object> configMap) {
this.configId = configId;
this.apmConfiguration = configMap;
}
public String get(String key) {
Object value = this.apmConfiguration.get(key);
return (value == null) ? null : String.valueOf(value);
}
public Set<String> getKeys() {
return this.apmConfiguration.keySet();
}
public String getConfigId() {
return this.configId;
}
}
}