Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lksfrnz
Copy link
Owner

@lksfrnz lksfrnz commented Jun 19, 2024

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.

Copy link

@johnjang johnjang left a 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.

.subList(
Constants.MAX_DATAPOINTS_PER_METRIC,
metric.getValues().size())));
if (metric instanceof MetricDefinition) {

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.

Copy link
Owner Author

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 {

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.

Copy link
Owner Author

@lksfrnz lksfrnz Jun 21, 2024

Choose a reason for hiding this comment

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

done

Comment on lines 74 to 78
} else if (metric instanceof MetricDefinitionBuilder) {
List<Double> values = ((MetricDefinitionBuilder) metric).getValues();
targetMembers.put(
metric.getName(), values.size() == 1 ? values.get(0) : values);
}

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?

Copy link
Owner Author

Choose a reason for hiding this comment

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

done

@lksfrnz lksfrnz force-pushed the MetricsRefactor branch 2 times, most recently from b299268 to 9fd3833 Compare June 20, 2024 23:37
@lksfrnz
Copy link
Owner Author

lksfrnz commented Jun 21, 2024

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

@johnjang johnjang Jun 24, 2024

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?

Copy link
Owner Author

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.

Copy link
Owner Author

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.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Updated name to getFormattedValues()

@lksfrnz lksfrnz force-pushed the MetricsRefactor branch 2 times, most recently from df894a1 to f59577b Compare June 25, 2024 20:52
@lksfrnz lksfrnz force-pushed the MetricsRefactor branch from 0ce5555 to 59e2593 Compare July 2, 2024 18:37
Copy link

@gordonpn gordonpn left a comment

Choose a reason for hiding this comment

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

LGTM

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.

3 participants