majialoong commented on PR #20543:
URL: https://github.com/apache/kafka/pull/20543#issuecomment-3299951609

   For binary compatibility issues, the following tests were performed:
   1. Binary compatibility tested using 
[japicmp](https://siom79.github.io/japicmp/)
   
   `kafka-clients-4.2.0-SNAPSHOT.jar` is the code before this PR, and 
`kafka-clients-4.2.0-SNAPSHOT-new.jar` contains the changed code of this PR.
   
   <img width="3834" height="1070" alt="image" 
src="https://github.com/user-attachments/assets/49616163-d26b-40d6-b940-2bf198c18516";
 />
   
   2.  Write a test code to verify
   ```
   import java.util.HashMap;
   import java.util.concurrent.TimeUnit;
   
   import org.apache.kafka.common.MetricName;
   import org.apache.kafka.common.metrics.Gauge;
   import org.apache.kafka.common.metrics.MetricConfig;
   import org.apache.kafka.common.metrics.Metrics;
   import org.apache.kafka.common.metrics.stats.Min;
   
   public class CustomMetrics {
       public static void main(String[] args) {
           Metrics metrics = new Metrics();
   
           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);
   
           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<>());
           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(measurableMetricNameTwo, min);
   
           System.out.println("gaugeMetricNameOne: " + 
metrics.metric(gaugeMetricNameOne).metricValue());
           System.out.println("gaugeMetricNameTwo: " + 
metrics.metric(gaugeMetricNameTwo).metricValue());
           System.out.println("measurableMetricNameOne: " + 
metrics.metric(measurableMetricNameOne).metricValue());
           System.out.println("measurableMetricNameTwo: " + 
metrics.metric(measurableMetricNameTwo).metricValue());
       }
   }
   ```
   Compile using the code in the current trunk branch and version 1.0.1. Then 
run using the code that includes the changes in this PR.
   
   trunk beanch :
   <img width="1382" height="756" alt="image" 
src="https://github.com/user-attachments/assets/f0454100-9c41-4336-9127-8029bd1c54d8";
 />
   
   1.0.1 version : 
   <img width="1338" height="722" alt="image" 
src="https://github.com/user-attachments/assets/e91540aa-1434-46b7-bd84-fd34da0b5f02";
 />
   
   


-- 
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]

Reply via email to