You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by GitBox <gi...@apache.org> on 2022/01/24 21:38:34 UTC

[GitHub] [cassandra] frankgh commented on a change in pull request #1421: CASSANDRA-17224: Virtual table for exposing CQL metrics

frankgh commented on a change in pull request #1421:
URL: https://github.com/apache/cassandra/pull/1421#discussion_r791167770



##########
File path: src/java/org/apache/cassandra/db/virtual/CQLMetricsTable.java
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.db.virtual;
+
+import com.google.common.annotations.VisibleForTesting;
+
+import org.apache.cassandra.db.marshal.DoubleType;
+import org.apache.cassandra.db.marshal.UTF8Type;
+import org.apache.cassandra.dht.LocalPartitioner;
+import org.apache.cassandra.metrics.CQLMetrics;
+import org.apache.cassandra.schema.TableMetadata;
+import org.apache.cassandra.cql3.QueryProcessor;
+
+// Virtual table for CQL metrics
+public class CQLMetricsTable extends AbstractVirtualTable

Review comment:
       Let's make this class `final` consistent with other virtual tables
   ```suggestion
   final class CQLMetricsTable extends AbstractVirtualTable
   ```

##########
File path: src/java/org/apache/cassandra/db/virtual/CQLMetricsTable.java
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.db.virtual;
+
+import com.google.common.annotations.VisibleForTesting;
+
+import org.apache.cassandra.db.marshal.DoubleType;
+import org.apache.cassandra.db.marshal.UTF8Type;
+import org.apache.cassandra.dht.LocalPartitioner;
+import org.apache.cassandra.metrics.CQLMetrics;
+import org.apache.cassandra.schema.TableMetadata;
+import org.apache.cassandra.cql3.QueryProcessor;
+
+// Virtual table for CQL metrics
+public class CQLMetricsTable extends AbstractVirtualTable
+{
+    public static final String TABLE_NAME = "cql_metrics";
+    public static final String PREPARED_STATEMENTS_COUNT_COL = "prepared_statements_count";
+    public static final String PREPARED_STATEMENTS_EVICTED_COL = "prepared_statements_evicted";
+    public static final String PREPARED_STATEMENTS_EXECUTED_COL = "prepared_statements_executed";
+    public static final String PREPARED_STATEMENTS_RATIO_COL = "prepared_statements_ratio";
+    public static final String REGULAR_STATEMENTS_EXECUTED_COL = "regular_statements_executed";
+    public static final String NAME_COL = "name";
+    public static final String VALUE_ROW = "value";

Review comment:
       Maybe "cql" makes more sense for the value of the name column ?

##########
File path: src/java/org/apache/cassandra/db/virtual/CQLMetricsTable.java
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.db.virtual;
+
+import com.google.common.annotations.VisibleForTesting;
+
+import org.apache.cassandra.db.marshal.DoubleType;
+import org.apache.cassandra.db.marshal.UTF8Type;
+import org.apache.cassandra.dht.LocalPartitioner;
+import org.apache.cassandra.metrics.CQLMetrics;
+import org.apache.cassandra.schema.TableMetadata;
+import org.apache.cassandra.cql3.QueryProcessor;
+
+// Virtual table for CQL metrics
+public class CQLMetricsTable extends AbstractVirtualTable
+{
+    public static final String TABLE_NAME = "cql_metrics";
+    public static final String PREPARED_STATEMENTS_COUNT_COL = "prepared_statements_count";
+    public static final String PREPARED_STATEMENTS_EVICTED_COL = "prepared_statements_evicted";
+    public static final String PREPARED_STATEMENTS_EXECUTED_COL = "prepared_statements_executed";
+    public static final String PREPARED_STATEMENTS_RATIO_COL = "prepared_statements_ratio";
+    public static final String REGULAR_STATEMENTS_EXECUTED_COL = "regular_statements_executed";
+    public static final String NAME_COL = "name";
+    public static final String VALUE_ROW = "value";
+
+    private final CQLMetrics cqlMetrics;
+
+    // Default constructor references query processor metrics
+    CQLMetricsTable(String keyspace)
+    {
+        this(keyspace, QueryProcessor.metrics);
+    }
+
+    // For dependency injection
+    @VisibleForTesting
+    CQLMetricsTable(String keyspace, CQLMetrics cqlMetrics)
+    {
+        // create virtual table with this name
+        super(TableMetadata.builder(keyspace, TABLE_NAME)
+                           .kind(TableMetadata.Kind.VIRTUAL)
+                           .partitioner(new LocalPartitioner(UTF8Type.instance))
+                           .addPartitionKeyColumn(NAME_COL, UTF8Type.instance)
+                           .addRegularColumn(PREPARED_STATEMENTS_COUNT_COL, DoubleType.instance)
+                           .addRegularColumn(PREPARED_STATEMENTS_EVICTED_COL, DoubleType.instance)
+                           .addRegularColumn(PREPARED_STATEMENTS_EXECUTED_COL, DoubleType.instance)
+                           .addRegularColumn(PREPARED_STATEMENTS_RATIO_COL, DoubleType.instance)
+                           .addRegularColumn(REGULAR_STATEMENTS_EXECUTED_COL, DoubleType.instance)

Review comment:
       Maybe match the type of the value without needing to cast it to double?
   ```suggestion
                              .addRegularColumn(PREPARED_STATEMENTS_COUNT_COL, Int32Type.instance)
                              .addRegularColumn(PREPARED_STATEMENTS_EVICTED_COL, LongType.instance)
                              .addRegularColumn(PREPARED_STATEMENTS_EXECUTED_COL, LongType.instance)
                              .addRegularColumn(PREPARED_STATEMENTS_RATIO_COL, DoubleType.instance)
                              .addRegularColumn(REGULAR_STATEMENTS_EXECUTED_COL, LongType.instance)
   ```

##########
File path: src/java/org/apache/cassandra/db/virtual/CQLMetricsTable.java
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.db.virtual;
+
+import com.google.common.annotations.VisibleForTesting;
+
+import org.apache.cassandra.db.marshal.DoubleType;
+import org.apache.cassandra.db.marshal.UTF8Type;
+import org.apache.cassandra.dht.LocalPartitioner;
+import org.apache.cassandra.metrics.CQLMetrics;
+import org.apache.cassandra.schema.TableMetadata;
+import org.apache.cassandra.cql3.QueryProcessor;
+
+// Virtual table for CQL metrics
+public class CQLMetricsTable extends AbstractVirtualTable
+{
+    public static final String TABLE_NAME = "cql_metrics";
+    public static final String PREPARED_STATEMENTS_COUNT_COL = "prepared_statements_count";
+    public static final String PREPARED_STATEMENTS_EVICTED_COL = "prepared_statements_evicted";
+    public static final String PREPARED_STATEMENTS_EXECUTED_COL = "prepared_statements_executed";
+    public static final String PREPARED_STATEMENTS_RATIO_COL = "prepared_statements_ratio";
+    public static final String REGULAR_STATEMENTS_EXECUTED_COL = "regular_statements_executed";
+    public static final String NAME_COL = "name";
+    public static final String VALUE_ROW = "value";
+
+    private final CQLMetrics cqlMetrics;
+
+    // Default constructor references query processor metrics
+    CQLMetricsTable(String keyspace)
+    {
+        this(keyspace, QueryProcessor.metrics);
+    }
+
+    // For dependency injection
+    @VisibleForTesting
+    CQLMetricsTable(String keyspace, CQLMetrics cqlMetrics)
+    {
+        // create virtual table with this name
+        super(TableMetadata.builder(keyspace, TABLE_NAME)
+                           .kind(TableMetadata.Kind.VIRTUAL)
+                           .partitioner(new LocalPartitioner(UTF8Type.instance))
+                           .addPartitionKeyColumn(NAME_COL, UTF8Type.instance)
+                           .addRegularColumn(PREPARED_STATEMENTS_COUNT_COL, DoubleType.instance)
+                           .addRegularColumn(PREPARED_STATEMENTS_EVICTED_COL, DoubleType.instance)
+                           .addRegularColumn(PREPARED_STATEMENTS_EXECUTED_COL, DoubleType.instance)
+                           .addRegularColumn(PREPARED_STATEMENTS_RATIO_COL, DoubleType.instance)
+                           .addRegularColumn(REGULAR_STATEMENTS_EXECUTED_COL, DoubleType.instance)
+                           .build());
+        this.cqlMetrics = cqlMetrics;
+    }
+
+    @Override
+    public DataSet data()
+    {
+        // populate metrics in the virtual table
+        SimpleDataSet result = new SimpleDataSet(metadata());
+        addRow(result, VALUE_ROW, cqlMetrics);
+
+        return result;

Review comment:
       minor nit: it might be worth considering inlining since we don't call `addRow` anywhere else?
   ```suggestion
           return new SimpleDataSet(metadata()).row(VALUE_ROW)
                                               .column(PREPARED_STATEMENTS_COUNT_COL, cqlMetrics.preparedStatementsCount.getValue())
                                               .column(PREPARED_STATEMENTS_EVICTED_COL, cqlMetrics.preparedStatementsEvicted.getCount())
                                               .column(PREPARED_STATEMENTS_EXECUTED_COL, cqlMetrics.preparedStatementsExecuted.getCount())
                                               .column(PREPARED_STATEMENTS_RATIO_COL, cqlMetrics.preparedStatementsRatio.getValue())
                                               .column(REGULAR_STATEMENTS_EXECUTED_COL, cqlMetrics.regularStatementsExecuted.getCount());
   ```




-- 
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-unsubscribe@cassandra.apache.org

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



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