rangareddy opened a new pull request, #19477:
URL: https://github.com/apache/hudi/pull/19477

   ### Describe the issue this Pull Request addresses
   
   Closes #12902. Enabling the CloudWatch reporter fails with nothing but:
   
   ```
   org.apache.hudi.exception.HoodieException: Unable to instantiate class
   org.apache.hudi.metrics.cloudwatch.CloudWatchMetricsReporter
   ```
   
   The real cause is several frames down:
   
   ```
   java.lang.NoSuchMethodException: 
org.apache.hudi.metrics.cloudwatch.CloudWatchMetricsReporter.<init>(
       org.apache.hudi.config.metrics.HoodieMetricsConfig, 
com.codahale.metrics.MetricRegistry)
        at java.lang.Class.getConstructor0(Class.java:3110)
        at 
org.apache.hudi.common.util.ReflectionUtils.loadClass(ReflectionUtils.java:73)
   ```
   
   The class resolved — so `hudi-aws` *is* on the classpath — but its 
constructor did not match, because the
   jar providing it was built against a different Hudi version. Working that 
out from the reported message took
   a maintainer digging the buried `NoSuchMethodException` out of the stack and 
pointing at the AWS SDK version
   matrix; the message itself says only that instantiation failed.
   
   `ReflectionUtils.loadClass` collapses `InstantiationException`, 
`IllegalAccessException`,
   `InvocationTargetException` and `NoSuchMethodException` into one 
`HoodieException` with a fixed message, and
   notes as much in its own TODO. #19418 added a translation for the 
missing-module case
   (`ClassNotFoundException`) but deliberately left every other cause 
untouched, which is why this one still
   surfaces bare.
   
   ### Summary and Changelog
   
   - `MetricsReporterFactory#createCloudWatchReporter` now also translates a 
`NoSuchMethodException` cause,
     reporting that the class was found but has no `(HoodieMetricsConfig, 
MetricRegistry)` constructor, that
     the likely cause is a jar built against a different Hudi version, and that 
the remedy is a matching
     `hudi-aws-bundle` — as distinct from the missing-module case, which says 
to *add* the bundle. Getting
     those two the wrong way round is what makes the current message unhelpful: 
absent and mismatched need
     different fixes.
   
   - Tests: adds `metricsReporterFactoryExplainsAConstructorMismatch`, and 
renames
     `metricsReporterFactoryLeavesNonClassNotFoundFailuresUntouched` to
     `metricsReporterFactoryLeavesOtherFailuresUntouched`. That test used a 
`NoSuchMethodException` cause to
     stand for "some other failure", which is now a handled case, so it uses an 
`InvocationTargetException`
     instead — a failure raised by the reporter's own constructor, which is the 
case that must still pass
     through untranslated.
   
   ### Verification
   
   With the new branch reverted, exactly one test fails, and it reproduces the 
reported message verbatim:
   
   ```
   [ERROR] metricsReporterFactoryExplainsAConstructorMismatch
   AssertionFailedError: The failure should say the constructor did not match, 
but was: Unable to
   instantiate class 
org.apache.hudi.aws.metrics.cloudwatch.CloudWatchMetricsReporter
   ```
   
   `metricsReporterFactoryLeavesOtherFailuresUntouched` stays green in that 
run, which is the point of keeping
   it: it shows the pass-through branch is genuinely exercised and not 
accidentally absorbed by the new one.
   
   `TestMetricsReporterFactory` runs 12 tests green, the whole 
`org.apache.hudi.metrics` package 21, with
   `checkstyle:check` and `apache-rat:check` clean.
   
   ### Impact
   
   Error text only. Nothing that used to succeed behaves differently, and a 
failure that is neither a missing
   class nor a missing constructor is still reported exactly as before.
   
   Worth noting for whoever picks up `ReflectionUtils`: its TODO 
("ReflectionUtils should throw a specific
   exception to indicate Reflection problem") is the general fix, and would 
remove the need for
   cause-sniffing here and anywhere else that wants to tell these failures 
apart. Not attempted in this PR —
   `loadClass` has many callers and changing what it throws is a much larger 
change than the one this issue
   needs.
   
   ### Risk Level
   
   none — one additional branch on an existing error path, plus tests.
   
   ### Documentation Update
   
   none
   
   ### Contributor's checklist
   
   - [x] Read through [contributor's 
guide](https://hudi.apache.org/contribute/how-to-contribute)
   - [x] Enough context is provided in the sections above
   - [x] Adequate tests were added if applicable
   - [x] CI passes on my PR
   


-- 
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]

Reply via email to