-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
base: trunk
Are you sure you want to change the base?
Conversation
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. |
There was a problem hiding this 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?
private static final LinkedHashMap<String, String> TAGS = new LinkedHashMap<>() {{ | ||
put("k", "v"); | ||
}}; |
There was a problem hiding this comment.
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?
There was a problem hiding this 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.
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()); | ||
}}; |
There was a problem hiding this comment.
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<>(); |
There was a problem hiding this comment.
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<>(); |
There was a problem hiding this comment.
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<>(); |
There was a problem hiding this comment.
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<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
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
distinct ones by the metrics backend
consistency, we should follow the same approach here.