-
Notifications
You must be signed in to change notification settings - Fork 157
feat: Introduce metric validation for otter tests #19260
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: main
Are you sure you want to change the base?
Conversation
Fix #18638 This change introduces: * `NetworkMetrics` a singleton that collects all `NodeMetric` instances * `NodeMetric` lightweight in-memory `Metrics` implementation that instruments all added `Metric` with `TestMetricInvocationHandler` to record the history of the metrics * `assertThat` validations for metric validation Currently only `assertThat().neverExceeds()` is implemented to show how the system works. More to follow. Signed-off-by: Timo Brandstätter <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅ @@ Coverage Diff @@
## main #19260 +/- ##
=========================================
Coverage 69.35% 69.35%
Complexity 23268 23268
=========================================
Files 2645 2645
Lines 100710 100710
Branches 10409 10409
=========================================
Hits 69846 69846
Misses 26902 26902
Partials 3962 3962 🚀 New features to boost your workflow:
|
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferences |
* @param threshold the threshold for the metric | ||
* @return the {@link MultipleNodeMetricsResults} instance | ||
*/ | ||
public MultipleNodeMetricsAssert neverExceeds(final double threshold) { |
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 am unsure if we should introduce new names or stick with typical AssertJ names (e.g., isLessThan()
). I see the advantages of both.
.map(SingleNodeMetricsAssert::toDouble) | ||
.filter(v -> v > threshold) | ||
.toList(); | ||
failWithMessage( |
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.
wrongValues
can potentially be very long. I wonder if there is a better way to report this. Maybe the maximum would be sufficient?
We should also report the timestamp when the limit was exceeded.
*/ | ||
public final class NetworkMetrics { | ||
|
||
private static final NetworkMetrics INSTANCE = new NetworkMetrics(); |
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.
Can we avoid introducing a Singleton?
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.
Yes removed
if (started) { | ||
return; | ||
} | ||
started = true; |
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 not thread-safe. Not sure if it is intended.
final Thread updaterThread = new Thread( | ||
() -> { | ||
while (started) { | ||
final Instant start = Instant.now(); |
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 should not use Instant.now()
but use the FakeTime
instead.
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.
On second thought. If this implementation is only used in Turtle tests, we should make NodeMetrics
a TimeTickReceiver
and call the updaters every time a tick is received. What do you think?
* integration tests. It records the full history of every metric value so that assertions can be | ||
* executed after a test run. | ||
*/ | ||
public class NodeMetrics implements Metrics { |
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 this implementation will only be used in tests running on Turtle. I suggest moving this package under the turtle
package.
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 am afraid I have to refresh my memory about the Metrics
implementation before I can finish the review.
# Conflicts: # platform-sdk/consensus-otter-tests/src/test/java/org/hiero/otter/test/HappyPathTest.java
Signed-off-by: Timo Brandstätter <[email protected]>
assertThat(logResults).noMessageWithLevelHigherThan(Level.INFO); | ||
|
||
assertThat(network.getStatusProgression()) | ||
.hasSteps(target(ACTIVE).requiringInterim(REPLAYING_EVENTS, OBSERVING, CHECKING)); | ||
|
||
assertThat(network.getMetricsResultsFor("platform", "bytes_per_trans").ignoring(firstNode)) | ||
.neverExceeds(444); |
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.
can we make 444 a constant?
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.
the strings should also be constants I think
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 feel like we should introduce a class like MetricId
that has category and name. and use that for creating metrics as well as when we are asserting them
Fix #18638
This change introduces:
NetworkMetrics
a singleton that collects allNodeMetric
instancesNodeMetric
lightweight in-memoryMetrics
implementation that instruments all addedMetric
withTestMetricInvocationHandler
to record the history of the metricsassertThat
validations for metric validationCurrently only
assertThat().neverExceeds()
is implemented to show how the system works. More to follow.