majialoong commented on PR #20543:
URL: https://github.com/apache/kafka/pull/20543#issuecomment-3340188944
To test compatibility, I wrote the following test code, which includes code
demonstrating the usage of Gauge and Measurable.
```
import org.apache.kafka.common.MetricName;
import org.apache.kafka.common.metrics.Gauge;
import org.apache.kafka.common.metrics.Measurable;
import org.apache.kafka.common.metrics.MetricConfig;
import org.apache.kafka.common.metrics.Metrics;
import org.apache.kafka.common.metrics.stats.Min;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;
public class TestCompatibility {
public static void main(String[] args) {
Metrics metrics = new Metrics();
// Kafka about MetricValueProvider have two sub-interface Gauge and
Measurable
// test Gauge
MetricName gaugeMetricNameOne = new MetricName("gaugeMetricNameOne",
"test-metrics", "description for gauge "
+ "metric "
+ "one",
new HashMap<>());
metrics.addMetric(gaugeMetricNameOne, (Gauge<String>) (config, now)
-> "hello gauge.");
MetricName gaugeMetricNameTwo = new MetricName("gaugeMetricNameTwo",
"test-metrics", "description for gauge "
+ "metric two",
new HashMap<>());
metrics.addMetric(gaugeMetricNameTwo, (Gauge<Integer>) (config, now)
-> 123);
Gauge<String> stringGauge = (config, now) -> "string gauge";
MetricName gaugeMetricNameThree = new
MetricName("gaugeMetricNameThree", "test-metrics", "description for gauge "
+ "metric three",
new HashMap<>());
metrics.addMetric(gaugeMetricNameThree, stringGauge);
System.out.println("gaugeMetricNameOne: " +
metrics.metric(gaugeMetricNameOne).metricValue());
System.out.println("gaugeMetricNameTwo: " +
metrics.metric(gaugeMetricNameTwo).metricValue());
System.out.println("gaugeMetricNameThree: " +
metrics.metric(gaugeMetricNameThree).metricValue());
// test Measurable
MetricName measurableMetricNameOne = new
MetricName("measurableMetricNameOne", "test-metrics", "description for "
+ " measurable metric one",
new HashMap<>());
metrics.addMetric(measurableMetricNameOne, (config, now) -> 100L);
MetricName measurableMetricNameTwo = new
MetricName("measurableMetricNameTwo", "test-metrics", "description "
+ "for measurable metric two",
new HashMap<>());
Measurable measurable = (Measurable) (config, now) -> 200L;
metrics.addMetric(measurableMetricNameTwo, measurable);
MetricName measurableMetricNameThree = new
MetricName("measurableMetricNameThree", "test-metrics", "description "
+ "for measurable metric three",
new HashMap<>());
// test Measurable implementation class Min
Min min = new Min();
long windowMs = 100;
int samples = 2;
MetricConfig config = new MetricConfig().timeWindow(windowMs,
TimeUnit.MILLISECONDS).samples(samples);
min.record(config, 50, System.currentTimeMillis());
metrics.addMetric(measurableMetricNameThree, min);
System.out.println("measurableMetricNameOne: " +
metrics.metric(measurableMetricNameOne).metricValue());
System.out.println("measurableMetricNameTwo: " +
metrics.metric(measurableMetricNameTwo).metricValue());
System.out.println("measurableMetricNameThree: " +
metrics.metric(measurableMetricNameThree).metricValue());
}
}
```
I have prepared three versions of the Kafka-clients JAR files :
1. **kafka-clients-1.0.1.jar**(The Gauge and MetricValueProvider interfaces
have been added(1.0.0 version), and KafkaMetric first time as public type(1.0.1
version).)
2. **kafka-clients-4.2.0-SNAPSHOT.jar**(trunk branch code)
3. **kafka-clients-4.2.0-SNAPSHOT-new.jar** (with this PR code)
Regarding source code compatibility, I tested the code using the three
different versions of the JAR file, and it compiled successfully in all three
cases.
<img width="1154" height="308" alt="image"
src="https://github.com/user-attachments/assets/4d2dc6aa-7539-4e97-b444-6a210723c7bb"
/>
Regarding binary compatibility, I compiled the test code using each of these
three different versions of the JAR file, and all of them ran successfully in
all three versions.
1. Compile using version **kafka-clients-1.0.1.jar**,and run directly using
the three versions of the JAR files.
<img width="1452" height="1320" alt="image"
src="https://github.com/user-attachments/assets/c7aeff5b-6d26-40c3-9b7b-193e2815ffd8"
/>
2. Compile using version **kafka-clients-4.2.0-SNAPSHOT.jar**,and run
directly using the three versions of the JAR files.
<img width="1470" height="1318" alt="image"
src="https://github.com/user-attachments/assets/f30a6711-0a7f-4ebb-a9f1-aadc98826e65"
/>
3. Compile using version **kafka-clients-4.2.0-SNAPSHOT-new.jar**,and run
directly using the three versions of the JAR files.
<img width="1478" height="1330" alt="image"
src="https://github.com/user-attachments/assets/00817726-576f-4ecc-89b7-daa89eefe296"
/>
Regarding binary compatibility testing, we also used
[japicmp](https://github.com/siom79/japicmp) for verification.
1. Use the libs files generated by compiling **the code included in this
PR**. The binary compatibility check using japicmp shows no changes.
<img width="3820" height="1108" alt="image"
src="https://github.com/user-attachments/assets/bafd059d-b919-4642-93d2-55cbb62c3c7a"
/>
3. And use libs files were compiled using code from **the trunk branch**.
The binary compatibility check using japicmp shows no changes.
<img width="3788" height="1132" alt="image"
src="https://github.com/user-attachments/assets/825bfb9d-d467-455d-97eb-8fcc15bd7f07"
/>
--
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]