arjunashok commented on code in PR #135:
URL: https://github.com/apache/cassandra-sidecar/pull/135#discussion_r1750975083


##########
src/test/integration/org/apache/cassandra/sidecar/routes/ClientStatsHandlerIntegrationTest.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.sidecar.routes;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import io.vertx.core.buffer.Buffer;
+import io.vertx.ext.web.client.HttpResponse;
+import io.vertx.ext.web.client.predicate.ResponsePredicate;
+import io.vertx.junit5.VertxExtension;
+import io.vertx.junit5.VertxTestContext;
+import org.apache.cassandra.sidecar.common.response.ClientStatsResponse;
+import org.apache.cassandra.sidecar.testing.IntegrationTestBase;
+import org.apache.cassandra.testing.CassandraIntegrationTest;
+import org.apache.cassandra.testing.CassandraTestContext;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Test the client-stats endpoint with cassandra container.
+ */
+@ExtendWith(VertxExtension.class)
+public class ClientStatsHandlerIntegrationTest extends IntegrationTestBase
+{
+
+    @CassandraIntegrationTest
+    void retrieveClientStatsDefault(VertxTestContext context, 
CassandraTestContext cassandraTestContext)
+    throws Exception
+    {
+        String testRoute = "/api/v1/storage/client-stats";
+        testWithClient(context, client -> {
+            client.get(server.actualPort(), "127.0.0.1", testRoute)
+                  .expect(ResponsePredicate.SC_OK)
+                  .send(context.succeeding(response -> {
+                      assertClientStatsResponse(response, 
Collections.emptyMap(), cassandraTestContext.version.toString());
+                      context.completeNow();
+                  }));
+        });
+    }
+
+    @CassandraIntegrationTest
+    void retrieveClientStatsWithClientOptions(VertxTestContext context, 
CassandraTestContext cassandraTestContext)
+    throws Exception
+    {
+        Map<String, Boolean> params = 
Collections.singletonMap("client-options", true);
+        String testRoute = "/api/v1/storage/client-stats?client-options=true";
+        testWithClient(context, client -> {
+            client.get(server.actualPort(), "127.0.0.1", testRoute)
+                  .expect(ResponsePredicate.SC_OK)
+                  .send(context.succeeding(response -> {
+                      assertClientStatsResponse(response, params, 
cassandraTestContext.version.toString());
+                      context.completeNow();
+                  }));
+        });
+    }
+
+    @CassandraIntegrationTest
+    void retrieveClientStatsByProtocol(VertxTestContext context, 
CassandraTestContext cassandraTestContext)
+    throws Exception
+    {
+        Map<String, Boolean> params = Collections.singletonMap("by-protocol", 
true);
+        String testRoute = "/api/v1/storage/client-stats?by-protocol=true";
+        testWithClient(context, client -> {
+            client.get(server.actualPort(), "127.0.0.1", testRoute)
+                  .expect(ResponsePredicate.SC_OK)
+                  .send(context.succeeding(response -> {
+                      assertClientStatsResponse(response, params, 
cassandraTestContext.version.toString());
+                      context.completeNow();
+                  }));
+        });
+    }
+
+    @CassandraIntegrationTest
+    void retrieveClientStatsVerbose(VertxTestContext context, 
CassandraTestContext cassandraTestContext)
+    throws Exception
+    {
+        Map<String, Boolean> params = Collections.singletonMap("verbose", 
true);
+        String testRoute = "/api/v1/storage/client-stats?verbose=true";

Review Comment:
   Will do



##########
src/test/integration/org/apache/cassandra/sidecar/routes/ClientStatsHandlerIntegrationTest.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.sidecar.routes;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import io.vertx.core.buffer.Buffer;
+import io.vertx.ext.web.client.HttpResponse;
+import io.vertx.ext.web.client.predicate.ResponsePredicate;
+import io.vertx.junit5.VertxExtension;
+import io.vertx.junit5.VertxTestContext;
+import org.apache.cassandra.sidecar.common.response.ClientStatsResponse;
+import org.apache.cassandra.sidecar.testing.IntegrationTestBase;
+import org.apache.cassandra.testing.CassandraIntegrationTest;
+import org.apache.cassandra.testing.CassandraTestContext;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Test the client-stats endpoint with cassandra container.
+ */
+@ExtendWith(VertxExtension.class)
+public class ClientStatsHandlerIntegrationTest extends IntegrationTestBase
+{
+
+    @CassandraIntegrationTest
+    void retrieveClientStatsDefault(VertxTestContext context, 
CassandraTestContext cassandraTestContext)
+    throws Exception
+    {
+        String testRoute = "/api/v1/storage/client-stats";
+        testWithClient(context, client -> {
+            client.get(server.actualPort(), "127.0.0.1", testRoute)
+                  .expect(ResponsePredicate.SC_OK)
+                  .send(context.succeeding(response -> {
+                      assertClientStatsResponse(response, 
Collections.emptyMap(), cassandraTestContext.version.toString());
+                      context.completeNow();
+                  }));
+        });
+    }
+
+    @CassandraIntegrationTest
+    void retrieveClientStatsWithClientOptions(VertxTestContext context, 
CassandraTestContext cassandraTestContext)
+    throws Exception
+    {
+        Map<String, Boolean> params = 
Collections.singletonMap("client-options", true);
+        String testRoute = "/api/v1/storage/client-stats?client-options=true";
+        testWithClient(context, client -> {
+            client.get(server.actualPort(), "127.0.0.1", testRoute)
+                  .expect(ResponsePredicate.SC_OK)
+                  .send(context.succeeding(response -> {
+                      assertClientStatsResponse(response, params, 
cassandraTestContext.version.toString());
+                      context.completeNow();
+                  }));
+        });
+    }
+
+    @CassandraIntegrationTest
+    void retrieveClientStatsByProtocol(VertxTestContext context, 
CassandraTestContext cassandraTestContext)
+    throws Exception
+    {
+        Map<String, Boolean> params = Collections.singletonMap("by-protocol", 
true);
+        String testRoute = "/api/v1/storage/client-stats?by-protocol=true";
+        testWithClient(context, client -> {
+            client.get(server.actualPort(), "127.0.0.1", testRoute)

Review Comment:
   Good point. However, since all the existing integration tests are defined 
this way, and the `Server` implementation does not expose the host API, I'd 
like to keep this as-is to keep the scope of this PR confined to the changes 
related to this API.



##########
src/main/java/org/apache/cassandra/sidecar/routes/ClientStatsHandler.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.sidecar.routes;
+
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import com.datastax.driver.core.Metadata;
+import com.google.inject.Inject;
+import io.vertx.core.http.HttpServerRequest;
+import io.vertx.core.net.SocketAddress;
+import io.vertx.ext.web.RoutingContext;
+import org.apache.cassandra.sidecar.cluster.CassandraAdapterDelegate;
+import org.apache.cassandra.sidecar.common.server.MetricsOperations;
+import org.apache.cassandra.sidecar.concurrent.ExecutorPools;
+import org.apache.cassandra.sidecar.utils.InstanceMetadataFetcher;
+
+import static 
org.apache.cassandra.sidecar.utils.HttpExceptions.cassandraServiceUnavailable;
+
+/**
+ * Handler for retrieving client stats
+ */
+public class ClientStatsHandler extends AbstractHandler<Void>
+{
+    /**
+     * Constructs a handler with the provided {@code metadataFetcher}
+     *
+     * @param metadataFetcher the metadata fetcher
+     * @param executorPools   executor pools for blocking executions
+     */
+    @Inject
+    protected ClientStatsHandler(InstanceMetadataFetcher metadataFetcher, 
ExecutorPools executorPools)
+    {
+        super(metadataFetcher, executorPools, null);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void handleInternal(RoutingContext context,
+                               HttpServerRequest httpRequest,
+                               String host,
+                               SocketAddress remoteAddress,
+                               Void request)
+    {
+
+        CassandraAdapterDelegate delegate = metadataFetcher.delegate(host);
+        if (delegate == null)
+        {
+            context.fail(cassandraServiceUnavailable());
+            return;
+        }
+        MetricsOperations operations = delegate.metricsOperations();
+        Metadata metadata = delegate.metadata();
+        if (operations == null || metadata == null)
+        {
+            context.fail(cassandraServiceUnavailable());
+            return;
+        }
+
+        Map<String, String> params = httpRequest.params().entries()

Review Comment:
   Yes, ignoring arbitrary params is intentional, so as to not fail-fast, which 
is typically common-practice. 
   
   As for the invalid/non-boolean values, the existing sidecar APIs default 
them to `false`. I'll update this to use the existing `parseBooleanQueryParam` 
utility invoked from the handler.



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