-
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?
Conversation
* Add Stable config source * Add snakeyaml to parse file
|
||
private static final HashMap<String, String> parseStableConfig(String filePath) { | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
🔵 Code Quality Violation
Do not initialize FileInputStream. Use a Files.newInputStream or Files.newOutputStream instead (...read more)
The classes that creates FileInputStream
and FileOutputStream
triggers too much garbage collection. Instead, use methods from the nio
package that cause less garbage collection.
Learn More
} | ||
} | ||
|
||
private static final HashMap<String, String> parseStableConfig(String filePath) { |
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
private static final HashMap<String, String> parseStableConfig(String filePath) { | |
private static final Map<String, String> parseStableConfig(String filePath) { |
Avoid using a specific implementation type; use the more general Map instead (...read more)
Relying on particular implementation types, such as, HashSet
or LinkedList
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
or List
when declaring variables and parameters.
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
⚪ Code Quality Violation
private HashMap<String, Object> apm_configuration_default; | |
private Map<String, Object> apm_configuration_default; |
Avoid using a specific implementation type; use the more general Map instead (...read more)
Relying on particular implementation types, such as, HashSet
or LinkedList
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
or List
when declaring variables and parameters.
private String config_id; | ||
private HashMap<String, Object> apm_configuration_default; | ||
|
||
private void setApmConfigurationDefault(HashMap<String, Object> m) { |
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
private void setApmConfigurationDefault(HashMap<String, Object> m) { | |
private void setApmConfigurationDefault(Map<String, Object> m) { |
Avoid using a specific implementation type; use the more general Map instead (...read more)
Relying on particular implementation types, such as, HashSet
or LinkedList
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
or List
when declaring variables and parameters.
static final String LOCAL_STABLE_CONFIGURATION_PATH = "/etc/datadog-agent/datadog_apm.yaml"; | ||
|
||
final ConfigOrigin fileOrigin; | ||
HashMap<String, String> configuration; |
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
HashMap<String, String> configuration; | |
Map<String, String> configuration; |
Avoid using a specific implementation type; use the more general Map instead (...read more)
Relying on particular implementation types, such as, HashSet
or LinkedList
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
or List
when declaring variables and parameters.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
try { | ||
configuration = parseStableConfig(file); | ||
} catch (Exception e) { | ||
configuration = new HashMap(); |
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.
You should still be able to declare configuration
as final
, javac is smart enough to figure out only a single assignment happens here. For an empty map (if you change the declared type to Map
instead of HashMap
) you can also use Map.of()
or Collections.emptyMap()
. Finally, we should at least report the exception if the file exists but is not readable/parseable.
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.
+1
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); |
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.
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 = ... ) {
}
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Please follow Java naming conventions -- use camel case not underscores
What Does This Do
Motivation
Additional Notes
Contributor Checklist
type:
and (comp:
orinst:
) labels in addition to any usefull labelsclose
,fix
or any linking keywords when referencing an issue.Use
solves
instead, and assign the PR milestone to the issueJira ticket: [PROJ-IDENT]