-
Notifications
You must be signed in to change notification settings - Fork 292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stable configuration draft #8328
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should still be able to declare There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||||||
} | ||||||
} | ||||||
Comment on lines
+24
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
|
||||||
private static final HashMap<String, String> parseStableConfig(String filePath) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⚪ Code Quality Violation
Suggested change
Avoid using a specific implementation type; use the more general Map instead (...read more)Relying on particular implementation types, such as, It is recommended to opt for general types such as |
||||||
Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions())); | ||||||
InputStream input = new FileInputStream(new File(filePath)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 Code Quality ViolationDo not initialize FileInputStream. Use a Files.newInputStream or Files.newOutputStream instead (...read more)The classes that creates Learn More |
||||||
Object data = yaml.load(input); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably leaking a file descriptor. You need to make sure to close the InputStream. Usually, the best to do that is using try ( InputStream 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; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⚪ Code Quality Violation
Suggested change
Avoid using a specific implementation type; use the more general Map instead (...read more)Relying on particular implementation types, such as, It is recommended to opt for general types such as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please follow Java naming conventions -- use camel case not underscores |
||||||
|
||||||
private void setApmConfigurationDefault(HashMap<String, Object> m) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⚪ Code Quality Violation
Suggested change
Avoid using a specific implementation type; use the more general Map instead (...read more)Relying on particular implementation types, such as, It is recommended to opt for general types such as |
||||||
apm_configuration_default = m; | ||||||
} | ||||||
|
||||||
private void setConfigId(String i) { | ||||||
config_id = i; | ||||||
} | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚪ Code Quality Violation
Avoid using a specific implementation type; use the more general Map instead (...read more)
Relying on particular implementation types, such as,
HashSet
orLinkedList
can limit your adaptability to embrace alternative implementations in the future, particularly as your requirements change and your code needs to undergo changes.It is recommended to opt for general types such as
Set
orList
when declaring variables and parameters.