Skip to content
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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

paullegranddc
Copy link

What Does This Do

Motivation

Additional Notes

Contributor Checklist

Jira ticket: [PROJ-IDENT]

* 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));
Copy link
Contributor

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

View in Datadog  Leave us feedback  Documentation

}
}

private static final HashMap<String, String> parseStableConfig(String filePath) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Quality Violation

Suggested change
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.

View in Datadog  Leave us feedback  Documentation


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Quality Violation

Suggested change
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.

View in Datadog  Leave us feedback  Documentation

private String config_id;
private HashMap<String, Object> apm_configuration_default;

private void setApmConfigurationDefault(HashMap<String, Object> m) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Quality Violation

Suggested change
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.

View in Datadog  Leave us feedback  Documentation

static final String LOCAL_STABLE_CONFIGURATION_PATH = "/etc/datadog-agent/datadog_apm.yaml";

final ConfigOrigin fileOrigin;
HashMap<String, String> configuration;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Quality Violation

Suggested change
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.

View in Datadog  Leave us feedback  Documentation

Comment on lines +24 to +31
StableConfigSource(String file, ConfigOrigin origin) {
this.fileOrigin = origin;
try {
configuration = parseStableConfig(file);
} catch (Exception e) {
configuration = new HashMap();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Quality Violation

Consider adding super() or this() to your constructor (...read more)

In Java, it is suggested to call super() in an extended class. This rule will report a violation if both a call to super() and an overloaded constructor are absent.

View in Datadog  Leave us feedback  Documentation

try {
configuration = parseStableConfig(file);
} catch (Exception e) {
configuration = new HashMap();
Copy link
Contributor

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.

Copy link
Contributor

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);
Copy link
Contributor

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;
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants