btlqql opened a new pull request, #4292:
URL: https://github.com/apache/rocketmq-dashboard/pull/4292
## What is the purpose of the change
Fixes #4291.
A native ratio alert whose threshold unit is `%` is delivered with a raw
floating-point artifact for
`${value}`: the stored fraction `0.29` is rendered as `28.999999999999996`.
The template has to scale
the fraction by 100 because ratio samples are stored as fractions of the
whole
(`ApacheRocketMqClusterMetricsCollector` normalizes `value > 1 ? value / 100
: value`) and the `%`
threshold is divided by 100 in `AlertRuleSemanticFingerprint`, but it scaled
with plain `double`
arithmetic, so `Double.toString` printed the exact binary product.
## Brief changelog
-
`server/src/main/java/org/apache/rocketmq/studio/ops/alert/AlertNotificationTemplate.java`
- `${value}` for a ratio metric with the `%` unit is now scaled with
`BigDecimal.valueOf(value).movePointRight(2).stripTrailingZeros().toPlainString()`,
which yields
the shortest exact decimal (`0.29` -> `29`, `0.07` -> `7`) and keeps the
existing `0.865` -> `86.5`
rendering.
- A non-finite value keeps the previous `String.valueOf` rendering instead
of raising.
- The non-ratio path is unchanged.
-
`server/src/test/java/org/apache/rocketmq/studio/ops/alert/AlertNotificationTemplateTest.java`
- New `rendersWholePercentForRatioValueWithoutFloatingPointNoiseTest`.
## Verification
Red, before the fix (`mvn -o -f server/pom.xml test
-Dtest=AlertNotificationTemplateTest`):
```
[ERROR] Tests run: 5, Failures: 1, Errors: 0, Skipped: 0, Time elapsed:
0.158 s <<< FAILURE! -- in
org.apache.rocketmq.studio.ops.alert.AlertNotificationTemplateTest
expected: "29%"
but was: "28.999999999999996%"
[ERROR]
AlertNotificationTemplateTest.rendersWholePercentForRatioValueWithoutFloatingPointNoiseTest:58
[ERROR] Tests run: 5, Failures: 1, Errors: 0, Skipped: 0
[INFO] BUILD FAILURE
```
Green, after the fix (`mvn -o -f server/pom.xml test
-Dtest=AlertNotificationTemplateTest`):
```
[INFO] Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.130
s -- in org.apache.rocketmq.studio.ops.alert.AlertNotificationTemplateTest
[INFO] Tests run: 5, Failures: 0, Errors: 0, Skipped: 0
[INFO] BUILD SUCCESS
```
Full server suite on this branch (`mvn -o -f server/pom.xml test`) compared
with the unmodified base
`rocketmq-studio` @ 6c24d2ed:
```
base Tests run: 2151, Failures: 5, Errors: 5, Skipped: 0
branch Tests run: 2152, Failures: 5, Errors: 5, Skipped: 0
```
The single added test is the new one; the 5 failures and 5 errors are the
pre-existing
`CliAgentProviderTest`/`ClaudeCodeAgentProviderTest` POSIX `sh` tests and
the two
`AuthCorsIntegrationTest` cases being aligned in #4217, unchanged by this
change.
--
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]