maedhroz commented on code in PR #2534:
URL: https://github.com/apache/cassandra/pull/2534#discussion_r1316347394


##########
src/java/org/apache/cassandra/metrics/AccordMetrics.java:
##########
@@ -0,0 +1,279 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.metrics;
+
+import java.lang.reflect.Field;
+import java.util.concurrent.TimeUnit;
+
+import accord.api.EventsListener;
+import accord.local.Command;
+import accord.primitives.Deps;
+import accord.primitives.PartialDeps;
+import accord.primitives.Timestamp;
+import accord.primitives.TxnId;
+import com.codahale.metrics.Counting;
+import com.codahale.metrics.Histogram;
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.Timer;
+import org.apache.cassandra.service.accord.AccordService;
+
+import static java.util.concurrent.TimeUnit.MICROSECONDS;
+import static org.apache.cassandra.metrics.CassandraMetricsRegistry.Metrics;
+
+public class AccordMetrics
+{
+    public final static AccordMetrics readMetrics = new AccordMetrics("ro");
+    public final static AccordMetrics writeMetrics = new AccordMetrics("rw");
+
+    /**
+     * The time between start on the coordinator and commit on this replica.
+     */
+    public final Timer commitLatency;
+
+    /**
+     * The time between start on the coordinator and execution on this replica.
+     */
+    public final Timer executeLatency;
+
+    /**
+     * The time between start on the coordinator and application on this 
replica.
+     */
+    public final Timer applyLatency;
+
+    /**
+     * Duration of applying changes.
+     */
+    public final Timer applyDuration;
+
+    /**
+     * The number of dependencies of the transaction on this replica.
+     */
+    public final Histogram deps;
+
+    public final Meter progressLogSize;
+
+    /**
+     * The number of dependencies of the transaction.
+     */
+    public final Histogram coordinatorDeps;
+
+    /**
+     * The number of fast path transactions executed on this coordinator.
+     */
+    public final Meter coordinatorFastPathTrx;
+
+    /**
+     * The number of slow path transactions executed on this coordinator.
+     */
+    public final Meter coordinatorSlowPathTrx;
+
+    /**
+     * The number of preempted transactions on this coordinator.
+     */
+    public final Meter coordinatorPreemptedTrx;
+
+    /**
+     * The number of timed out transactions on this coordinator.
+     */
+    public final Meter coordinatorTimedoutTrx;
+
+    /**
+     * The time between the start of the transaction and the start of the 
recovery, if the transaction is recovered.
+     */
+    public final Timer coordinatorRecoveryDelay;
+
+    /**
+     * The time between the start of the recovery and the execution of the 
transaction, if the transaction is recovered.
+     */
+    public final Timer coordinatorRecoveryDuration;
+
+    /**
+     * The ratio of the number of fast path transactions to the total number 
of transactions.
+     */
+    public final RatioGaugeSet fastPathToTotal;
+
+    private AccordMetrics(String scope)
+    {
+        DefaultNameFactory replica = new DefaultNameFactory("accord-replica", 
scope);
+        commitLatency = 
Metrics.timer(replica.createMetricName("CommitLatency"));
+        executeLatency = 
Metrics.timer(replica.createMetricName("ExecuteLatency"));
+        applyLatency = Metrics.timer(replica.createMetricName("ApplyLatency"));
+        applyDuration = 
Metrics.timer(replica.createMetricName("ApplyDuration"));
+        deps = Metrics.histogram(replica.createMetricName("Dependencies"), 
true);
+        progressLogSize = 
Metrics.meter(replica.createMetricName("ProgressLogSize"));
+
+        DefaultNameFactory coordinator = new 
DefaultNameFactory("accord-coordinator", scope);
+        coordinatorDeps = 
Metrics.histogram(coordinator.createMetricName("Dependencies"), true);
+        coordinatorFastPathTrx = 
Metrics.meter(coordinator.createMetricName("FastPathTrx"));
+        coordinatorSlowPathTrx = 
Metrics.meter(coordinator.createMetricName("SlowPathTrx"));
+        coordinatorPreemptedTrx = 
Metrics.meter(coordinator.createMetricName("PreemptedTrx"));
+        coordinatorTimedoutTrx = 
Metrics.meter(coordinator.createMetricName("TimedoutTrx"));
+        coordinatorRecoveryDelay = 
Metrics.timer(coordinator.createMetricName("RecoveryDelay"));
+        coordinatorRecoveryDuration = 
Metrics.timer(coordinator.createMetricName("RecoveryTime"));
+        fastPathToTotal = new RatioGaugeSet(coordinatorFastPathTrx, 
RatioGaugeSet.sum(coordinatorFastPathTrx, coordinatorSlowPathTrx), coordinator, 
"FastPathToTotal%s");
+    }
+
+    @Override
+    public String toString()
+    {
+        StringBuilder builder = new StringBuilder();
+        builder.append("AccordMetrics [");
+
+        try
+        {
+            for (Field f : getClass().getDeclaredFields())
+            {
+                f.setAccessible(true);
+                if (Counting.class.isAssignableFrom(f.getType()))
+                {
+                    Counting metric = (Counting) f.get(this);
+                    builder.append(String.format("%s: count=%d, ", 
f.getName(), metric.getCount()));
+                }
+            }
+        }
+        catch (IllegalAccessException e)
+        {
+            throw new RuntimeException(e);
+        }
+        builder.append("]");
+        return builder.toString();
+    }

Review Comment:
   As long as it doesn't end up being called on a hot path somewhere, it's 
probably fine. The alternate would, I guess, be adding the `Counting` instances 
to a collection and using that in `toString()` (sort of like how we track all 
metrics in `TableMetrics`), but using reflection isn't necessarily worse for 
this purpose.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to