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 2020/10/08 12:32:57 UTC

[GitHub] [cassandra] blerer opened a new pull request #769: Improve ClientRequestSizeMetrics test

blerer opened a new pull request #769:
URL: https://github.com/apache/cassandra/pull/769


   The test was only checking that the metrics where updated but was not
   testing if the updates were correct.
   
   This patch also fix the ClearableHistogram.clear method (through an ugly
   hack) that was not clearing the histogram count.


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

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


[GitHub] [cassandra] bereng commented on a change in pull request #769: Improve ClientRequestSizeMetrics test

Posted by GitBox <gi...@apache.org>.
bereng commented on a change in pull request #769:
URL: https://github.com/apache/cassandra/pull/769#discussion_r507581249



##########
File path: test/unit/org/apache/cassandra/metrics/ClientRequestSizeMetricsTest.java
##########
@@ -0,0 +1,127 @@
+/*
+ * 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 org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.codahale.metrics.Counter;
+import com.codahale.metrics.Histogram;
+import com.codahale.metrics.Snapshot;
+
+import org.apache.cassandra.cql3.CQLTester;
+import org.apache.cassandra.metrics.ClearableHistogram;
+import org.apache.cassandra.metrics.ClientRequestSizeMetrics;
+import org.apache.cassandra.metrics.DecayingEstimatedHistogramReservoir.EstimatedHistogramReservoirSnapshot;
+import org.apache.cassandra.metrics.DecayingEstimatedHistogramReservoir.Range;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Ensures we properly account for metrics tracked in the native protocol
+ */
+public class ClientRequestSizeMetricsTest extends CQLTester
+{
+    @BeforeClass
+    public static void setUp()
+    {
+        requireNetwork();
+    }
+
+    @Test
+    public void testReadAndWriteMetricsAreRecordedDuringNativeRequests() throws Throwable
+    {
+        // We want to ignore all the messages sent by the driver upon connection as well as
+        // the event sent upon schema updates
+        clearMetrics();
+
+        executeNet("SELECT * from system.peers");
+        assertThat(ClientRequestSizeMetrics.totalBytesRead.getCount()).isGreaterThan(0);
+        assertThat(ClientRequestSizeMetrics.totalBytesWritten.getCount()).isGreaterThan(0);
+
+        // The request fit in one single frame so we know the new number of received frames
+        assertEquals(1, ClientRequestSizeMetrics.bytesReceivedPerFrame.getCount());
+
+        long requestLength = ClientRequestSizeMetrics.totalBytesRead.getCount();
+        long responseLength = ClientRequestSizeMetrics.totalBytesWritten.getCount();
+
+        Snapshot snapshot = ClientRequestSizeMetrics.bytesReceivedPerFrame.getSnapshot();
+        assertMin(snapshot, requestLength);
+        assertMax(snapshot, requestLength);
+
+        // The response fit in one single frame so we know the new number of received frames
+        assertEquals(1, ClientRequestSizeMetrics.bytesTransmittedPerFrame.getCount());
+
+        snapshot = ClientRequestSizeMetrics.bytesTransmittedPerFrame.getSnapshot();
+        assertMin(snapshot, responseLength);
+        assertMax(snapshot, responseLength);
+
+        // Let's fire the same request again and test that the changes are the same that previously

Review comment:
       Can't you avoid duplicating code by folding into a loop such as:
   ```
   for (int i=1; i <=2 ; i++)
   {
     long expectedTotalBytesRead = i * requestLength;
     ....
   }
   ```
   




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

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


[GitHub] [cassandra] bereng commented on pull request #769: Improve ClientRequestSizeMetrics test

Posted by GitBox <gi...@apache.org>.
bereng commented on pull request #769:
URL: https://github.com/apache/cassandra/pull/769#issuecomment-712581165


   +1


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

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


[GitHub] [cassandra] blerer closed pull request #769: Improve ClientRequestSizeMetrics test

Posted by GitBox <gi...@apache.org>.
blerer closed pull request #769:
URL: https://github.com/apache/cassandra/pull/769


   


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

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


[GitHub] [cassandra] bereng commented on a change in pull request #769: Improve ClientRequestSizeMetrics test

Posted by GitBox <gi...@apache.org>.
bereng commented on a change in pull request #769:
URL: https://github.com/apache/cassandra/pull/769#discussion_r507578745



##########
File path: test/unit/org/apache/cassandra/metrics/ClientRequestSizeMetricsTest.java
##########
@@ -0,0 +1,127 @@
+/*
+ * 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 org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.codahale.metrics.Counter;
+import com.codahale.metrics.Histogram;
+import com.codahale.metrics.Snapshot;
+
+import org.apache.cassandra.cql3.CQLTester;
+import org.apache.cassandra.metrics.ClearableHistogram;
+import org.apache.cassandra.metrics.ClientRequestSizeMetrics;
+import org.apache.cassandra.metrics.DecayingEstimatedHistogramReservoir.EstimatedHistogramReservoirSnapshot;
+import org.apache.cassandra.metrics.DecayingEstimatedHistogramReservoir.Range;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Ensures we properly account for metrics tracked in the native protocol
+ */
+public class ClientRequestSizeMetricsTest extends CQLTester
+{
+    @BeforeClass
+    public static void setUp()
+    {
+        requireNetwork();
+    }
+
+    @Test
+    public void testReadAndWriteMetricsAreRecordedDuringNativeRequests() throws Throwable
+    {
+        // We want to ignore all the messages sent by the driver upon connection as well as
+        // the event sent upon schema updates
+        clearMetrics();
+
+        executeNet("SELECT * from system.peers");
+        assertThat(ClientRequestSizeMetrics.totalBytesRead.getCount()).isGreaterThan(0);
+        assertThat(ClientRequestSizeMetrics.totalBytesWritten.getCount()).isGreaterThan(0);
+
+        // The request fit in one single frame so we know the new number of received frames
+        assertEquals(1, ClientRequestSizeMetrics.bytesReceivedPerFrame.getCount());
+
+        long requestLength = ClientRequestSizeMetrics.totalBytesRead.getCount();

Review comment:
       Can't you declare these variables at line 56 and use them for those 2 initial asserts?




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

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


[GitHub] [cassandra] bereng commented on a change in pull request #769: Improve ClientRequestSizeMetrics test

Posted by GitBox <gi...@apache.org>.
bereng commented on a change in pull request #769:
URL: https://github.com/apache/cassandra/pull/769#discussion_r507581249



##########
File path: test/unit/org/apache/cassandra/metrics/ClientRequestSizeMetricsTest.java
##########
@@ -0,0 +1,127 @@
+/*
+ * 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 org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.codahale.metrics.Counter;
+import com.codahale.metrics.Histogram;
+import com.codahale.metrics.Snapshot;
+
+import org.apache.cassandra.cql3.CQLTester;
+import org.apache.cassandra.metrics.ClearableHistogram;
+import org.apache.cassandra.metrics.ClientRequestSizeMetrics;
+import org.apache.cassandra.metrics.DecayingEstimatedHistogramReservoir.EstimatedHistogramReservoirSnapshot;
+import org.apache.cassandra.metrics.DecayingEstimatedHistogramReservoir.Range;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Ensures we properly account for metrics tracked in the native protocol
+ */
+public class ClientRequestSizeMetricsTest extends CQLTester
+{
+    @BeforeClass
+    public static void setUp()
+    {
+        requireNetwork();
+    }
+
+    @Test
+    public void testReadAndWriteMetricsAreRecordedDuringNativeRequests() throws Throwable
+    {
+        // We want to ignore all the messages sent by the driver upon connection as well as
+        // the event sent upon schema updates
+        clearMetrics();
+
+        executeNet("SELECT * from system.peers");
+        assertThat(ClientRequestSizeMetrics.totalBytesRead.getCount()).isGreaterThan(0);
+        assertThat(ClientRequestSizeMetrics.totalBytesWritten.getCount()).isGreaterThan(0);
+
+        // The request fit in one single frame so we know the new number of received frames
+        assertEquals(1, ClientRequestSizeMetrics.bytesReceivedPerFrame.getCount());
+
+        long requestLength = ClientRequestSizeMetrics.totalBytesRead.getCount();
+        long responseLength = ClientRequestSizeMetrics.totalBytesWritten.getCount();
+
+        Snapshot snapshot = ClientRequestSizeMetrics.bytesReceivedPerFrame.getSnapshot();
+        assertMin(snapshot, requestLength);
+        assertMax(snapshot, requestLength);
+
+        // The response fit in one single frame so we know the new number of received frames
+        assertEquals(1, ClientRequestSizeMetrics.bytesTransmittedPerFrame.getCount());
+
+        snapshot = ClientRequestSizeMetrics.bytesTransmittedPerFrame.getSnapshot();
+        assertMin(snapshot, responseLength);
+        assertMax(snapshot, responseLength);
+
+        // Let's fire the same request again and test that the changes are the same that previously

Review comment:
       Can't you avoid duplicating code by folding into a loop such as:
   ```
   for (int i=1; i <=2 ; i++)
     {
       long expectedTotalBytesRead = i * requestLength;
       ....
     }
   ```
   




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

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


[GitHub] [cassandra] blerer commented on a change in pull request #769: Improve ClientRequestSizeMetrics test

Posted by GitBox <gi...@apache.org>.
blerer commented on a change in pull request #769:
URL: https://github.com/apache/cassandra/pull/769#discussion_r507873316



##########
File path: test/unit/org/apache/cassandra/metrics/ClientRequestSizeMetricsTest.java
##########
@@ -0,0 +1,127 @@
+/*
+ * 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 org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.codahale.metrics.Counter;
+import com.codahale.metrics.Histogram;
+import com.codahale.metrics.Snapshot;
+
+import org.apache.cassandra.cql3.CQLTester;
+import org.apache.cassandra.metrics.ClearableHistogram;
+import org.apache.cassandra.metrics.ClientRequestSizeMetrics;
+import org.apache.cassandra.metrics.DecayingEstimatedHistogramReservoir.EstimatedHistogramReservoirSnapshot;
+import org.apache.cassandra.metrics.DecayingEstimatedHistogramReservoir.Range;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Ensures we properly account for metrics tracked in the native protocol
+ */
+public class ClientRequestSizeMetricsTest extends CQLTester
+{
+    @BeforeClass
+    public static void setUp()
+    {
+        requireNetwork();
+    }
+
+    @Test
+    public void testReadAndWriteMetricsAreRecordedDuringNativeRequests() throws Throwable
+    {
+        // We want to ignore all the messages sent by the driver upon connection as well as
+        // the event sent upon schema updates
+        clearMetrics();
+
+        executeNet("SELECT * from system.peers");
+        assertThat(ClientRequestSizeMetrics.totalBytesRead.getCount()).isGreaterThan(0);
+        assertThat(ClientRequestSizeMetrics.totalBytesWritten.getCount()).isGreaterThan(0);
+
+        // The request fit in one single frame so we know the new number of received frames
+        assertEquals(1, ClientRequestSizeMetrics.bytesReceivedPerFrame.getCount());
+
+        long requestLength = ClientRequestSizeMetrics.totalBytesRead.getCount();
+        long responseLength = ClientRequestSizeMetrics.totalBytesWritten.getCount();
+
+        Snapshot snapshot = ClientRequestSizeMetrics.bytesReceivedPerFrame.getSnapshot();
+        assertMin(snapshot, requestLength);
+        assertMax(snapshot, requestLength);
+
+        // The response fit in one single frame so we know the new number of received frames
+        assertEquals(1, ClientRequestSizeMetrics.bytesTransmittedPerFrame.getCount());
+
+        snapshot = ClientRequestSizeMetrics.bytesTransmittedPerFrame.getSnapshot();
+        assertMin(snapshot, responseLength);
+        assertMax(snapshot, responseLength);
+
+        // Let's fire the same request again and test that the changes are the same that previously

Review comment:
       There is some differences between the 2 set of checks so it is not really feasable to use a loop but I can extract a method to reduce the code duplication.




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

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


[GitHub] [cassandra] blerer commented on a change in pull request #769: Improve ClientRequestSizeMetrics test

Posted by GitBox <gi...@apache.org>.
blerer commented on a change in pull request #769:
URL: https://github.com/apache/cassandra/pull/769#discussion_r507871764



##########
File path: test/unit/org/apache/cassandra/metrics/ClientRequestSizeMetricsTest.java
##########
@@ -0,0 +1,127 @@
+/*
+ * 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 org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.codahale.metrics.Counter;
+import com.codahale.metrics.Histogram;
+import com.codahale.metrics.Snapshot;
+
+import org.apache.cassandra.cql3.CQLTester;
+import org.apache.cassandra.metrics.ClearableHistogram;
+import org.apache.cassandra.metrics.ClientRequestSizeMetrics;
+import org.apache.cassandra.metrics.DecayingEstimatedHistogramReservoir.EstimatedHistogramReservoirSnapshot;
+import org.apache.cassandra.metrics.DecayingEstimatedHistogramReservoir.Range;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Ensures we properly account for metrics tracked in the native protocol
+ */
+public class ClientRequestSizeMetricsTest extends CQLTester
+{
+    @BeforeClass
+    public static void setUp()
+    {
+        requireNetwork();
+    }
+
+    @Test
+    public void testReadAndWriteMetricsAreRecordedDuringNativeRequests() throws Throwable
+    {
+        // We want to ignore all the messages sent by the driver upon connection as well as
+        // the event sent upon schema updates
+        clearMetrics();
+
+        executeNet("SELECT * from system.peers");
+        assertThat(ClientRequestSizeMetrics.totalBytesRead.getCount()).isGreaterThan(0);
+        assertThat(ClientRequestSizeMetrics.totalBytesWritten.getCount()).isGreaterThan(0);
+
+        // The request fit in one single frame so we know the new number of received frames
+        assertEquals(1, ClientRequestSizeMetrics.bytesReceivedPerFrame.getCount());
+
+        long requestLength = ClientRequestSizeMetrics.totalBytesRead.getCount();

Review comment:
       Done :-)




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

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