Skip to content

KAFKA-19139 Plugin#wrapInstance should use LinkedHashMap instead of Map #19519

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

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from

Conversation

m1a2st
Copy link
Collaborator

@m1a2st m1a2st commented Apr 20, 2025

There will be an update to the PluginMetrics#metricName method: the type
of the tags parameter will be changed
from Map to LinkedHashMap.
This change is necessary because the order of metric tags is important

  1. If the tag order is inconsistent, identical metrics may be treated as
    distinct ones by the metrics backend
  2. KAFKA-18390 is updating metric naming to use LinkedHashMap. For
    consistency, we should follow the same approach here.

@lllilllilllilili
Copy link

Good. Using LinkedHashMap makes sense here to ensure consistent tag ordering and avoid duplicate time series in metrics backends. The trade-off is acceptable since this is not on a performance-critical path.

@github-actions github-actions bot removed the small Small PRs label Apr 21, 2025
Copy link
Contributor

@frankvicky frankvicky left a comment

Choose a reason for hiding this comment

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

@m1a2st: Thanks for the patch.
Could you please check the modified files and eliminate the double brace initialization?

Comment on lines 3749 to 3751
private static final LinkedHashMap<String, String> TAGS = new LinkedHashMap<>() {{
put("k", "v");
}};
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Could we use a static block instead of double brace initialization?

@github-actions github-actions bot removed the triage PRs from the community label Apr 22, 2025
Copy link
Contributor

@frankvicky frankvicky left a comment

Choose a reason for hiding this comment

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

@m1a2st: Thanks for the patch.
I have a few comments.

Comment on lines 405 to 409
Properties baseProps = new Properties() {{
setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9999");
setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
}};
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we also clean this, and do we need static here?

@@ -36,11 +35,15 @@

public class PluginMetricsImplTest {

private final Map<String, String> extraTags = Collections.singletonMap("my-tag", "my-value");
private static final LinkedHashMap<String, String> EXTRA_TAGS = new LinkedHashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we eliminate the static keyword?
private final LinkedHashMap<String, String> EXTRA_TAGS = new LinkedHashMap<>(Map.of("my-tag", "my-value"));

@@ -2881,9 +2875,13 @@ private MetricName expectedMetricName(String clientId, String config, Class<?> c

private static final String NAME = "name";
private static final String DESCRIPTION = "description";
private static final Map<String, String> TAGS = Collections.singletonMap("k", "v");
private static final LinkedHashMap<String, String> TAGS = new LinkedHashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

private static final LinkedHashMap<String, String> TAGS = new LinkedHashMap<>(Map.of("t1", "v1"));

@@ -64,10 +64,13 @@ public class ConnectMetricsTest {
WorkerConfig.KEY_CONVERTER_CLASS_CONFIG, "org.apache.kafka.connect.json.JsonConverter",
WorkerConfig.VALUE_CONVERTER_CLASS_CONFIG, "org.apache.kafka.connect.json.JsonConverter");
private static final ConnectorTaskId CONNECTOR_TASK_ID = new ConnectorTaskId("connector", 0);
private static final Map<String, String> TAGS = Map.of("t1", "v1");

private static final LinkedHashMap<String, String> TAGS = new LinkedHashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

assertEquals(0, metrics.metric(metricName).metricValue());
monitorableAuthorizer.authorize(null, null);
assertEquals(1, metrics.metric(metricName).metricValue());
}

public static class MonitorableAuthorizer implements Authorizer, Monitorable {

private final Map<String, String> extraTags = Map.of("k1", "v1");
private static final LinkedHashMap<String, String> EXTRA_TAGS = new LinkedHashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

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

Successfully merging this pull request may close these issues.

3 participants