This is an automated email from the ASF dual-hosted git repository.

samt pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 73cd2c56ca Add histogram columns to timer metrics vtable
73cd2c56ca is described below

commit 73cd2c56ca07fc4bd1c77a7a45e1d6e27941fefa
Author: Sam Tunnicliffe <s...@apache.org>
AuthorDate: Thu Mar 20 16:35:47 2025 +0000

    Add histogram columns to timer metrics vtable
    
    Patch by Sam Tunnicliffe; reviewed by Maxim Muzafarov for
    CASSANDRA-20466
---
 CHANGES.txt                                        |  1 +
 .../cassandra/db/virtual/model/TimerMetricRow.java | 51 ++++++++++++++++++++++
 .../db/virtual/walker/TimerMetricRowWalker.java    | 21 ++++++++-
 .../metrics/JmxVirtualTableMetricsTest.java        |  8 ++++
 4 files changed, 80 insertions(+), 1 deletion(-)

diff --git a/CHANGES.txt b/CHANGES.txt
index 3f622f8976..324af6e281 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 5.1
+ * Add min/max/mean/percentiles to timer metrics vtable (CASSANDRA-20466)
  * Add support for time, date, timestamp types in scalar constraint 
(CASSANDRA-20274)
  * Add regular expression constraint (CASSANDRA-20275)
  * Improve constraints autocompletion (CASSANDRA-20341)
diff --git a/src/java/org/apache/cassandra/db/virtual/model/TimerMetricRow.java 
b/src/java/org/apache/cassandra/db/virtual/model/TimerMetricRow.java
index 4fd4b81758..ce38bd4e42 100644
--- a/src/java/org/apache/cassandra/db/virtual/model/TimerMetricRow.java
+++ b/src/java/org/apache/cassandra/db/virtual/model/TimerMetricRow.java
@@ -19,6 +19,7 @@
 package org.apache.cassandra.db.virtual.model;
 
 import com.codahale.metrics.Metric;
+import com.codahale.metrics.Snapshot;
 import com.codahale.metrics.Timer;
 
 import static org.apache.cassandra.metrics.CassandraMetricsRegistry.Metrics;
@@ -30,11 +31,13 @@ public class TimerMetricRow
 {
     private final String key;
     private final Timer value;
+    private final Snapshot snapshot;
 
     public TimerMetricRow(String key, Metric value)
     {
         this.key = key;
         this.value = (Timer) value;
+        this.snapshot = ((Timer) value).getSnapshot();
     }
 
     @Column
@@ -78,4 +81,52 @@ public class TimerMetricRow
     {
         return value.getOneMinuteRate();
     }
+
+    @Column
+    public double p75th()
+    {
+        return snapshot.get75thPercentile();
+    }
+
+    @Column
+    public double p95th()
+    {
+        return snapshot.get95thPercentile();
+    }
+
+    @Column
+    public double p98th()
+    {
+        return snapshot.get98thPercentile();
+    }
+
+    @Column
+    public double p99th()
+    {
+        return snapshot.get99thPercentile();
+    }
+
+    @Column
+    public double p999th()
+    {
+        return snapshot.get999thPercentile();
+    }
+
+    @Column
+    public double max()
+    {
+        return snapshot.getMax();
+    }
+
+    @Column
+    public double mean()
+    {
+        return snapshot.getMean();
+    }
+
+    @Column
+    public double min()
+    {
+        return snapshot.getMin();
+    }
 }
diff --git 
a/src/java/org/apache/cassandra/db/virtual/walker/TimerMetricRowWalker.java 
b/src/java/org/apache/cassandra/db/virtual/walker/TimerMetricRowWalker.java
index e4e15ffe67..c1e6a5005f 100644
--- a/src/java/org/apache/cassandra/db/virtual/walker/TimerMetricRowWalker.java
+++ b/src/java/org/apache/cassandra/db/virtual/walker/TimerMetricRowWalker.java
@@ -28,10 +28,21 @@ import org.apache.cassandra.db.virtual.model.TimerMetricRow;
  */
 public class TimerMetricRowWalker implements RowWalker<TimerMetricRow>
 {
+    // Note: max & min are defined as doubles here despite Timer itself 
exposing them as longs,
+    // via its histogram's snapshot. This is because historically, 
JMXTimerMBean defined these
+    // fields as doubles and the vtable representation should be consistent 
with that.
     @Override
     public void visitMeta(MetadataVisitor visitor)
     {
         visitor.accept(Column.Type.PARTITION_KEY, "name", String.class);
+        visitor.accept(Column.Type.REGULAR, "max", Double.TYPE);
+        visitor.accept(Column.Type.REGULAR, "mean", Double.TYPE);
+        visitor.accept(Column.Type.REGULAR, "min", Double.TYPE);
+        visitor.accept(Column.Type.REGULAR, "p75th", Double.TYPE);
+        visitor.accept(Column.Type.REGULAR, "p95th", Double.TYPE);
+        visitor.accept(Column.Type.REGULAR, "p98th", Double.TYPE);
+        visitor.accept(Column.Type.REGULAR, "p999th", Double.TYPE);
+        visitor.accept(Column.Type.REGULAR, "p99th", Double.TYPE);
         visitor.accept(Column.Type.REGULAR, "count", Long.TYPE);
         visitor.accept(Column.Type.REGULAR, "fifteen_minute_rate", 
Double.TYPE);
         visitor.accept(Column.Type.REGULAR, "five_minute_rate", Double.TYPE);
@@ -44,6 +55,14 @@ public class TimerMetricRowWalker implements 
RowWalker<TimerMetricRow>
     public void visitRow(TimerMetricRow row, RowMetadataVisitor visitor)
     {
         visitor.accept(Column.Type.PARTITION_KEY, "name", String.class, 
row::name);
+        visitor.accept(Column.Type.REGULAR, "max", Double.TYPE, row::max);
+        visitor.accept(Column.Type.REGULAR, "mean", Double.TYPE, row::mean);
+        visitor.accept(Column.Type.REGULAR, "min", Double.TYPE, row::min);
+        visitor.accept(Column.Type.REGULAR, "p75th", Double.TYPE, row::p75th);
+        visitor.accept(Column.Type.REGULAR, "p95th", Double.TYPE, row::p95th);
+        visitor.accept(Column.Type.REGULAR, "p98th", Double.TYPE, row::p98th);
+        visitor.accept(Column.Type.REGULAR, "p999th", Double.TYPE, 
row::p999th);
+        visitor.accept(Column.Type.REGULAR, "p99th", Double.TYPE, row::p99th);
         visitor.accept(Column.Type.REGULAR, "count", Long.TYPE, row::count);
         visitor.accept(Column.Type.REGULAR, "fifteen_minute_rate", 
Double.TYPE, row::fifteenMinuteRate);
         visitor.accept(Column.Type.REGULAR, "five_minute_rate", Double.TYPE, 
row::fiveMinuteRate);
@@ -62,7 +81,7 @@ public class TimerMetricRowWalker implements 
RowWalker<TimerMetricRow>
             case CLUSTERING:
                 return 0;
             case REGULAR:
-                return 6;
+                return 14;
             default:
                 throw new IllegalStateException("Unknown column type: " + 
type);
         }
diff --git 
a/test/unit/org/apache/cassandra/metrics/JmxVirtualTableMetricsTest.java 
b/test/unit/org/apache/cassandra/metrics/JmxVirtualTableMetricsTest.java
index 6f8c8b9822..6cf433e433 100644
--- a/test/unit/org/apache/cassandra/metrics/JmxVirtualTableMetricsTest.java
+++ b/test/unit/org/apache/cassandra/metrics/JmxVirtualTableMetricsTest.java
@@ -276,6 +276,14 @@ public class JmxVirtualTableMetricsTest extends CQLTester
 
         return CQLTester.row(getFullMetricName(objectName),
                              bean.getCount(),
+                             bean.getMax(),
+                             bean.getMean(),
+                             bean.getMin(),
+                             bean.get75thPercentile(),
+                             bean.get95thPercentile(),
+                             bean.get98thPercentile(),
+                             bean.get999thPercentile(),
+                             bean.get99thPercentile(),
                              bean.getFifteenMinuteRate(),
                              bean.getFiveMinuteRate(),
                              bean.getMeanRate(),


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to