Skip to content

feat: support customized metrics reporter#18710

Closed
HuangZhenQiu wants to merge 1 commit intoapache:masterfrom
HuangZhenQiu:customizable-metrics-reporter
Closed

feat: support customized metrics reporter#18710
HuangZhenQiu wants to merge 1 commit intoapache:masterfrom
HuangZhenQiu:customizable-metrics-reporter

Conversation

@HuangZhenQiu
Copy link
Copy Markdown
Member

Describe the issue this Pull Request addresses

Add Custom reporter type for Hudi users to customize any metrics reporter for internal infra requirement

Summary and Changelog

  1. Add CUSTOM MetricsReporterType
  2. Change MetricsReporterFactory to load custom reporter defined in config with reflection
  3. Add test cases for TestMetricsReporterFactory to cover the change

Impact

none

Risk Level

none

Documentation Update

none

Contributor's checklist

  • Read through contributor's guide
  • Enough context is provided in the sections above
  • Adequate tests were added if applicable

@github-actions github-actions Bot added the size:M PR with lines of changes in (100, 300] label May 8, 2026
@HuangZhenQiu HuangZhenQiu requested review from cshuo and danny0405 May 8, 2026 20:45
Copy link
Copy Markdown
Contributor

@hudi-agent hudi-agent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 This review was generated by an AI agent and may contain mistakes. Please verify any suggestions before applying.

Thanks for the contribution! This PR adds a CUSTOM MetricsReporterType and refactors MetricsReporterFactory to dispatch custom reporter loading via the switch statement, with support for multiple constructor signatures. The main thing worth a closer look is backward compatibility for users who already configure hoodie.metrics.reporter.class without reporter.type — see inline comments. Please take a look at any inline comments, and this should be ready for a Hudi committer or PMC member to take it from here. One minor readability nit on the guard-clause pattern; everything else looks clean.

case SLF4J:
reporter = new Slf4jMetricsReporter(registry);
break;
case CUSTOM:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 This looks like a silent backward-incompatible change. Before this PR, if a user set hoodie.metrics.reporter.class=com.foo.MyReporter without touching reporter.type, the class-name check ran first and the custom reporter was loaded. After this PR, since METRICS_REPORTER_TYPE_VALUE defaults to GRAPHITE, the same config will silently fall into the GRAPHITE case and ignore the user's custom class — they'll get a Graphite reporter (or a startup failure) with no warning. Could you preserve the prior behavior — e.g., if reporter.class is set and reporter.type is left at the default, treat it as CUSTOM (or at least log a clear warning) so existing deployments aren't silently broken? @yihua

- AI-generated; verify before applying. React 👍/👎 to flag quality.

.withDocumentation("Fully qualified class name of a custom MetricsReporter implementation. "
+ "The class must extend MetricsReporter and support one of these constructors (tried in order): "
+ "(Properties, MetricRegistry), (HoodieMetricsConfig, MetricRegistry), or no-arg. "
+ "Set reporter.type=CUSTOM or leave it unset when using this option.");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 The phrase "or leave it unset when using this option" doesn't match the actual code behavior. METRICS_REPORTER_TYPE_VALUE defaults to GRAPHITE (not unset), and even when it is null createReporter returns Option.empty() — neither path will load the custom class. Users effectively must set reporter.type=CUSTOM. Could you tighten this doc accordingly?

- AI-generated; verify before applying. React 👍/👎 to flag quality.

break;
case CUSTOM:
String reporterClassName = metricsConfig.getMetricReporterClassName();
if (!StringUtils.isNullOrEmpty(reporterClassName)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 nit: could you invert this into a guard clause? Throwing first and then falling through to the happy-path return removes the else branch and makes the intent clearer — e.g. if (StringUtils.isNullOrEmpty(reporterClassName)) { throw …; } return Option.of(loadCustomReporter(…));

- AI-generated; verify before applying. React 👍/👎 to flag quality.

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.15%. Comparing base (47bf4e4) to head (fd52f6e).

Additional details and impacted files
@@            Coverage Diff            @@
##             master   #18710   +/-   ##
=========================================
  Coverage     68.14%   68.15%           
- Complexity    29077    29093   +16     
=========================================
  Files          2522     2522           
  Lines        141177   141184    +7     
  Branches      17514    17512    -2     
=========================================
+ Hits          96208    96225   +17     
+ Misses        37061    37051   -10     
  Partials       7908     7908           
Flag Coverage Δ
common-and-other-modules 44.43% <100.00%> (+<0.01%) ⬆️
hadoop-mr-java-client 44.97% <12.50%> (-0.03%) ⬇️
spark-client-hadoop-common 48.34% <12.50%> (-0.02%) ⬇️
spark-java-tests 49.03% <100.00%> (+0.03%) ⬆️
spark-scala-tests 44.90% <12.50%> (-0.01%) ⬇️
utilities 37.64% <12.50%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...pache/hudi/config/metrics/HoodieMetricsConfig.java 83.00% <100.00%> (+1.30%) ⬆️
...rg/apache/hudi/metrics/MetricsReporterFactory.java 93.33% <100.00%> (+1.22%) ⬆️
...a/org/apache/hudi/metrics/MetricsReporterType.java 100.00% <100.00%> (ø)

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hudi-bot
Copy link
Copy Markdown
Collaborator

hudi-bot commented May 8, 2026

CI report:

Bot commands @hudi-bot supports the following commands:
  • @hudi-bot run azure re-run the last Azure build

@HuangZhenQiu
Copy link
Copy Markdown
Member Author

This change is not needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M PR with lines of changes in (100, 300]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants