He-Pin commented on code in PR #3382:
URL: https://github.com/apache/pekko/pull/3382#discussion_r3650576243
##########
cluster-metrics/src/main/scala/org/apache/pekko/cluster/metrics/Metric.scala:
##########
@@ -271,13 +271,15 @@ private[metrics] trait MetricNumericConverter {
* May involve rounding or truncation.
*/
def convertNumber(from: Any): Either[Long, Double] = from match {
- case n: Int => Left(n)
- case n: Long => Left(n)
- case n: Double => Right(n)
- case n: Float => Right(n)
- case n: BigInt => Left(n.longValue)
- case n: BigDecimal => Right(n.doubleValue)
- case x => throw new IllegalArgumentException(s"Not a number
[$x]")
+ case n: Int => Left(n)
+ case n: Long => Left(n)
+ case n: Double => Right(n)
+ case n: Float => Right(n)
+ case n: java.math.BigInteger => Left(n.longValue)
+ case n: java.math.BigDecimal => Right(n.doubleValue)
Review Comment:
The internal producers (JMX MXBeans, Sigar, protobuf deserialization) only
emit Int/Long/Double/Float + the now-added java.math types. Short/Byte never
appear in any internal path. A generic Number catch-all would also face the
longValue vs doubleValue ambiguity — we'd have to guess the user's intent. The
current fail-fast for unrecognized types is intentional to surface misuse early
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]