Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KAFKA-18077: Remove deprecated JmxReporter(String) #17923

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,7 @@ public class JmxReporter implements MetricsReporter {
private final Map<String, KafkaMbean> mbeans = new HashMap<>();
private Predicate<String> mbeanPredicate = s -> true;

public JmxReporter() {
this("");
}

/**
* Create a JMX reporter that prefixes all metrics with the given string.
* @deprecated Since 2.6.0. Use {@link JmxReporter#JmxReporter()}
* Initialize JmxReporter with {@link JmxReporter#contextChange(MetricsContext)}
* Populate prefix by adding _namespace/prefix key value pair to {@link MetricsContext}
*/
@Deprecated
public JmxReporter(String prefix) {
this.prefix = prefix != null ? prefix : "";
}
public JmxReporter() {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please initialize "prefix" to empty string and then remove this default constructor as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chia7712 I got it; I missed initializing "prefix" to empty string, thanks.


@Override
public void configure(Map<String, ?> configs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,23 +177,4 @@ public void testJmxPrefix() throws Exception {
metrics.close();
}
}

@Test
public void testDeprecatedJmxPrefixWithDefaultMetrics() throws Exception {
@SuppressWarnings("deprecation")
JmxReporter reporter = new JmxReporter("my-prefix");

// for backwards compatibility, ensure prefix does not get overridden by the default empty namespace in metricscontext
MetricConfig metricConfig = new MetricConfig();
Metrics metrics = new Metrics(metricConfig, new ArrayList<>(Collections.singletonList(reporter)), Time.SYSTEM);

MBeanServer server = ManagementFactory.getPlatformMBeanServer();
try {
Sensor sensor = metrics.sensor("my-sensor");
sensor.add(metrics.metricName("pack.bean1.avg", "grp1"), new Avg());
assertEquals("my-prefix", server.getObjectInstance(new ObjectName("my-prefix:type=grp1")).getObjectName().getDomain());
} finally {
metrics.close();
}
}
}
Loading