-
Notifications
You must be signed in to change notification settings - Fork 70
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
Allow metrics configs to be loaded via resources #205
Allow metrics configs to be loaded via resources #205
Conversation
@@ -220,7 +219,7 @@ public boolean processAutoDiscovery(byte[] buffer) { | |||
String[] discovered; | |||
|
|||
try { | |||
String configs = new String(buffer, CharEncoding.UTF_8); | |||
String configs = new String(buffer, "UTF-8"); |
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.
Good catch to remove this dependency since it was only used for this.
What about creating constant instead of having duplicated strings?
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.
Done. I changed it to use a proper Charset instead.
@@ -38,6 +39,13 @@ | |||
public static final String PROCESS_NAME_REGEX = "process_name_regex"; | |||
public static final String ATTRIBUTE = "Attribute: "; | |||
|
|||
private static final ThreadLocal<Yaml> YAML = new ThreadLocal<Yaml>() { |
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.
Why does it need to be a ThreadLocal
object?
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.
There seemed to be non-trivial amount of initialization happening in the constructor, so I wanted to avoid it. The problem is (I believe) Yaml
is not thread safe, so I used the ThreadLocal to ensure that safety.
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.
ok I trust you judgement here
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 accurate. We weren't thread-unsafe due to how we deal with instances, but this is safer. Thank you for this cleanup.
@@ -199,6 +208,40 @@ private void loadMetricConfigFiles(AppConfig appConfig, LinkedList<Configuration | |||
} | |||
} | |||
|
|||
private void loadMetricConfigResources(AppConfig config, LinkedList<Configuration> configurationList) { |
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.
Is it legit to add a unit tests for this method, unless it is covered already?
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.
I was doing manual testing since the application is not structured well for easy testing. Do you have any suggestions for better ways to validate this in a unit test?
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 most probably will have to create a method to get the inputStream
so this method can be testable as such by creating an object instance and calling this method while providing your inputStream.
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.
Ok, I've added a few simple tests. Is this what you were looking for?
Avoids the need to catch the exception for an unknown charset.
Metrics configs embedded inside the agent aren’t directly accessible on the file system. Loading as a resource avoids having to copy to an external location.
314bb0a
to
2125937
Compare
@@ -51,6 +50,7 @@ | |||
private static final String AD_LEGACY_CONFIG_TERM = "#### SERVICE-DISCOVERY TERM ####"; | |||
private static final int AD_MAX_NAME_LEN = 80; | |||
private static final int AD_MAX_MAG_INSTANCES = 4; // 1000 instances ought to be enough for anyone | |||
private static final Charset UTF_8 = Charset.forName("UTF-8"); |
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.
Nice refactoring! 👍
@@ -38,6 +39,13 @@ | |||
public static final String PROCESS_NAME_REGEX = "process_name_regex"; | |||
public static final String ATTRIBUTE = "Attribute: "; | |||
|
|||
private static final ThreadLocal<Yaml> YAML = new ThreadLocal<Yaml>() { |
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.
ok I trust you judgement here
@@ -199,6 +208,40 @@ private void loadMetricConfigFiles(AppConfig appConfig, LinkedList<Configuration | |||
} | |||
} | |||
|
|||
private void loadMetricConfigResources(AppConfig config, LinkedList<Configuration> configurationList) { |
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 most probably will have to create a method to get the inputStream
so this method can be testable as such by creating an object instance and calling this method while providing your inputStream.
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.
Thanks for adding tests. This is solid work :) 💯
@gzussa would you like to merge this or should I request access to merge it myself? |
Using copy/paste from integrations-core. Will depend on a new jmxfetch release with DataDog/jmxfetch#205 before this will work.
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.
Looks good to me
@@ -219,38 +219,29 @@ public boolean processAutoDiscovery(byte[] buffer) { | |||
boolean reinit = false; | |||
String[] discovered; | |||
|
|||
try { |
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.
Indeed it looks like we were try...catch
ing an Exception that didn't even come into play here.
@@ -38,6 +39,13 @@ | |||
public static final String PROCESS_NAME_REGEX = "process_name_regex"; | |||
public static final String ATTRIBUTE = "Attribute: "; | |||
|
|||
private static final ThreadLocal<Yaml> YAML = new ThreadLocal<Yaml>() { |
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 accurate. We weren't thread-unsafe due to how we deal with instances, but this is safer. Thank you for this cleanup.
Metrics configs embedded inside the agent aren’t directly accessible on the file system. Loading as a resource avoids having to copy to an external location.
These files should match the standard
metrics.yaml
format, and includejmx_metrics
blocks at the top level.