-
Notifications
You must be signed in to change notification settings - Fork 0
Refactored MetricsDefinition to use a MetricBuilder and be based off a super class #1
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
base: master
Are you sure you want to change the base?
Conversation
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 work so far! Left some questions in the file.
src/main/java/software/amazon/cloudwatchlogs/emf/model/MetricDirective.java
Outdated
Show resolved
Hide resolved
.subList( | ||
Constants.MAX_DATAPOINTS_PER_METRIC, | ||
metric.getValues().size()))); | ||
if (metric instanceof MetricDefinition) { |
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.
Personally, I'm not a big fan of instanceof
and doesn't feel objected oriented in this specific case. If we add two more types of metrics in the future, this section may get harder to read and maintain.
I wonder if we can abstract this out into its own class.
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.
refactored
class MetricDefinition { | ||
@NonNull | ||
/** Abstract immutable (except for name) class that all Metrics are based on. */ | ||
abstract class Metric { |
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.
Would prefer to have this in a separate file Metric.java
to be honest instead of being coupled together in MetricBuilder.java
file.
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
} else if (metric instanceof MetricDefinitionBuilder) { | ||
List<Double> values = ((MetricDefinitionBuilder) metric).getValues(); | ||
targetMembers.put( | ||
metric.getName(), values.size() == 1 ? values.get(0) : values); | ||
} |
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 this else if statement necessary? if metric is instanceof MetricDefinitionBuilder, implicitly it is instanceof MetricDefinition already so wouldn't line 74 never get executed?
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
b299268
to
9fd3833
Compare
Testing notes about 9fd3833: All but the resolveEnvironment tests passed which didn't pass on my machine before these changes, and these changes should not affect those tests. Also tested changes using the lambda example and the metrics were logged to CWL as expected |
values.add(value); | ||
} | ||
/** @return a simplified representation of the values of this metric. */ | ||
protected abstract Object getSimplifiedValues(); |
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.
qq: How would simplified values look like for histogram/stats?
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.
Statistics cannot be simplified so it would be the same as getValues()
. For histograms if there are only 1 or 2 distinct values they would each be their own bucket as per the SEH1 algorithm implementation I am following.
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 I'll rename this function to getPublishingValues()
or something similar, to imply that it is getting values in the format that they will be published in.
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.
Updated name to getFormattedValues()
df894a1
to
f59577b
Compare
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.
LGTM
Refactored the MetricDefinition to inherit a Metric super class which can be inherited by other type of metrics (coming soon). Also refactored MetricDefinition to be immutable and created a MetricDefinitionBuilder which behaves similar to how MetricDefinition used to.
Naming is also handled using a setter instead of on creation for simplicity in upcoming metric changes.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.