netudima commented on code in PR #4067:
URL: https://github.com/apache/cassandra/pull/4067#discussion_r2050897541


##########
src/java/org/apache/cassandra/db/monitoring/MonitoringTask.java:
##########
@@ -328,31 +379,126 @@ protected abstract static class Operation
          * this is set lazily as it takes time to build the query CQL */
         private String name;
 
+        /**
+         * creation time of this Operation object, in ms,
+         * this is different from operation's creationTimeNanos
+         * which does not follow wall clock and is useless for
+         * reporting purposes e.g. in virtual tables
+         */
+        private final long timestamp;
+
+        // optional keyspace and table this operation acts on
+        // used upon deserialisation
+        private String keyspace;
+        private String table;
+        private boolean crossNode;
+
         Operation(Monitorable operation, long failedAtNanos)
         {
             this.operation = operation;
             numTimesReported = 1;
             totalTimeNanos = failedAtNanos - operation.creationTimeNanos();
             minTime = totalTimeNanos;
             maxTime = totalTimeNanos;
+            timestamp = Clock.Global.currentTimeMillis();
         }
 
+        void add(Operation operation)
+        {
+            numTimesReported++;
+            totalTimeNanos += operation.totalTimeNanos;
+            maxTime = Math.max(maxTime, operation.maxTime);
+            minTime = Math.min(minTime, operation.minTime);
+        }
+
+        public abstract String getLogMessage();
+
+        @JsonProperty
         public String name()
         {
             if (name == null)
                 name = operation.name();
             return name;
         }
 
-        void add(Operation operation)
+        @JsonProperty
+        public String keyspace()
         {
-            numTimesReported++;
-            totalTimeNanos += operation.totalTimeNanos;
-            maxTime = Math.max(maxTime, operation.maxTime);
-            minTime = Math.min(minTime, operation.minTime);
+            if (operation != null)
+            {
+                String monitored = operation.monitoredOnKeyspace();
+                if (monitored != null)
+                    return monitored;
+            }
+            return keyspace;
         }
 
-        public abstract String getLogMessage();
+        @JsonProperty
+        public String table()
+        {
+            if (operation != null)
+            {
+                String monitored = operation.monitoredOnTable();
+                if (monitored != null)
+                    return monitored;
+            }
+            return table;
+        }
+
+        @JsonProperty
+        public boolean isCrossNode()
+        {
+            if (operation != null)
+                return operation.isCrossNode();
+
+            return crossNode;
+        }
+
+        @JsonProperty
+        public int numTimesReported()
+        {
+            return numTimesReported;
+        }
+
+        @JsonProperty
+        public long totalTimeNanos()
+        {
+            return totalTimeNanos;
+        }
+
+        @JsonProperty
+        public long maxTime()
+        {
+            return maxTime;
+        }
+
+        @JsonProperty
+        public long minTime()
+        {
+            return minTime;
+        }
+
+        @JsonIgnore
+        public long averageTime()
+        {
+            return totalTimeNanos / numTimesReported;
+        }
+
+        @JsonProperty
+        public long timestamp()
+        {
+            return timestamp;
+        }
+
+        public static String serialize(Collection<Operation> operations)
+        {
+            return JsonUtils.writeAsJsonString(operations);
+        }
+
+        public static List<Operation> deserialize(String message) throws 
Throwable
+        {
+            return JsonUtils.JSON_OBJECT_MAPPER.readValue(message, new 
TypeReference<>() {});

Review Comment:
   I suppose TypeReference value can be cached as a static variable and not 
allocated for each request..



-- 
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: pr-unsubscr...@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to