The reporting service has a compact aggregator that accepts measurements in different units and builds a short summary of normalized values. After a recent change, the summary started behaving strangely: some values look too large, and the order of elements in the report no longer matches expectations.
summarize method must:
factorToBase field;totalBase as the sum of the normalized values;normalized list sorted in descending order by normalized value;name in ascending order.maxBase field must contain the maximum normalized value from the input list.totalBase must be 0.0;maxBase must be 0.0;normalized must be an empty list.scala REPL or in a small main:import metrics.*
val items = List(
Measurement("disk", 2.0, 1000.0),
Measurement("ram", 1500.0, 1.0),
Measurement("net", 3.0, 1000.0)
)
MetricSummary.summarize(items)
Compare the result with the expected normalization:
disk -> 2000.0;ram -> 1500.0;net -> 3000.0.Separately check the case with equal normalized values:
import metrics.*
val tied = List(
Measurement("zeta", 2.0, 10.0),
Measurement("alpha", 20.0, 1.0)
)
MetricSummary.summarize(tied)
value * factorToBase.normalized.baseValue;name in ascending order.3.3.121scalac compilation and JVM runfactorToBase is the multiplier for conversion to the base unit and may be a fractional numberUse line comments to explain the problem, its impact, the fix and how to test it.