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
Add support to disable attributes in ConsoleReporter to be consistent… #1092
Add support to disable attributes in ConsoleReporter to be consistent… #1092
Conversation
… with GraphiteReporter
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.
Thank you for working on this! I didn't add filtering attributes to ConsoleReporter
, because it's mostly used for debug purposes. But I guess there is no reason not to implement it in a backward-compatible manner. I've added a couple of comments, which need to be addressed, before merging.
* @param status Status to be logged | ||
*/ | ||
private void printIfEnabled(MetricAttribute type, String status) { | ||
if(isMetricAttributeDisabled(type)) { |
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 think it would better with one condition statement. I also don't think the we need to use isMetricAttributeDisabled
method as well.
if (!getDisabledMetricAttributes().contains(type)) {
output.println(status);
}
@@ -291,8 +291,17 @@ protected boolean isShutdownExecutorOnStop() { | |||
return shutdownExecutorOnStop; | |||
} | |||
|
|||
protected Set<MetricAttribute> getDisabledMetricAttributes() { |
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, don't remove the getDisabledMetricAttributes
method. All changes must be backward-compatible.
* @param attribute metric attribute | ||
* @return True if attribute is configured to be disabled | ||
*/ | ||
protected boolean isMetricAttributeDisabled(MetricAttribute attribute) { |
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 don't believe we need to extract the logic of checking of an attribute to a separate method. disabledMetricAttributes
can't be null, so we basically have one method which does nothing but delegates a call to the contains
method of EnumSet
.
@@ -6,10 +6,7 @@ | |||
import java.io.ByteArrayOutputStream; | |||
import java.io.PrintStream; | |||
import java.io.UnsupportedEncodingException; | |||
import java.util.Locale; |
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, don't introduce star imports if they were not present.
.outputTo(output) | ||
.formattedFor(Locale.US) | ||
.withClock(clock) | ||
.formattedFor(TimeZone.getTimeZone("PST")) |
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 guess we could extract the timezone to a variable, so all tests use the same timezone.
|
||
final ConsoleReporter customReporter = ConsoleReporter.forRegistry(registry) | ||
.outputTo(output) | ||
.formattedFor(Locale.US) |
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.
We could extract the locale to a variable, so all tests use the same locale.
@@ -360,7 +360,7 @@ private void reportGauge(String name, Gauge gauge) { | |||
|
|||
private void announceIfEnabled(MetricAttribute metricAttribute, String metricName, String group, double value, String units) | |||
throws GangliaException { | |||
if (getDisabledMetricAttributes().contains(metricAttribute)) { | |||
if (isMetricAttributeDisabled(metricAttribute)) { |
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, don't introduce unrelated changes. Let's focus on ConsoleReporter
.
@@ -322,14 +322,14 @@ private void reportHistogram(String name, Histogram histogram, long timestamp) t | |||
} | |||
|
|||
private void sendIfEnabled(MetricAttribute type, String name, double value, long timestamp) throws IOException { | |||
if (getDisabledMetricAttributes().contains(type)){ | |||
if (isMetricAttributeDisabled(type)){ |
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.
Let's avoid changes in the classes not directly targeted by this pull request.
@arteam Thanks for the code review .. I've changed these stuff and gonna push them soon |
Thanks for your hard work on this, looks great! |
Add support to disable attributes in console reporter to be consistent with GraphiteReporter features .. I saw its easy to be implemented there with not so many changes