frankgh commented on code in PR #102:
URL: https://github.com/apache/cassandra-sidecar/pull/102#discussion_r1536036588


##########
src/main/dist/conf/sidecar.yaml:
##########
@@ -142,6 +142,15 @@ healthcheck:
   initial_delay_millis: 0
   poll_freq_millis: 30000
 
+metrics:
+  registry_name: cassandra_sidecar
+  vertx:
+    enabled: true
+    expose_via_jmx: false
+    jmx_domain_name: sidecar.vertx.jmx_domain
+    monitored_server_route_regexes:               # list of regexes for 
matching server routes

Review Comment:
   NIT:
   ```suggestion
       monitored_server_route_regexes:               # regex list to match 
server routes
   ```



##########
src/main/java/org/apache/cassandra/sidecar/routes/DiskSpaceProtectionHandler.java:
##########
@@ -99,6 +100,8 @@ protected void handleInternal(RoutingContext context,
         .onFailure(throwable -> {
             if (throwable instanceof InsufficientStorageException)
             {
+                InstanceMetrics metrics = instance.metrics();
+                
metrics.resource().insufficientStagingSpaceErrors.metric.mark();

Review Comment:
   NIT:
   ```suggestion;
                   
instance.metrics().resource().insufficientStagingSpaceErrors.metric.mark();
   ```



##########
src/main/java/org/apache/cassandra/sidecar/config/yaml/MetricsConfigurationImpl.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.config.yaml;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.cassandra.sidecar.config.MetricsConfiguration;
+import org.apache.cassandra.sidecar.config.VertxMetricsConfiguration;
+
+/**
+ * Configuration needed for capturing metrics.
+ */
+public class MetricsConfigurationImpl implements MetricsConfiguration

Review Comment:
   can we add tests for yaml parsing? we have a set of tests under 
`org.apache.cassandra.sidecar.config.SidecarConfigurationTest`



##########
src/main/java/org/apache/cassandra/sidecar/tasks/HealthCheckPeriodicTask.java:
##########
@@ -101,6 +108,11 @@ public void execute(Promise<Void> promise)
 
         // join always waits until all its futures are completed and will not 
fail as soon as one of the future fails
         Future.join(futures)
+              .onComplete(v -> {
+                  int instancesUp = instancesConfig.instances().size() - 
instanceDown.get();

Review Comment:
   you don't really need an AtomicInteger to keep track of the down instances. 
You can check the results instead.
   
   `v.result().causes().stream().filter(Objects::nonNull).count()`



##########
src/main/java/org/apache/cassandra/sidecar/cluster/instance/InstanceMetadata.java:
##########
@@ -58,4 +58,9 @@ public interface InstanceMetadata
      * @return a {@link CassandraAdapterDelegate} specific for the instance
      */
     @Nullable CassandraAdapterDelegate delegate();
+
+    /**
+     * @return {@link InstanceMetrics} metrics specific for the cassandra 
instance

Review Comment:
   Should we annotate with `@NotNull`?



##########
src/main/java/org/apache/cassandra/sidecar/cluster/instance/InstanceMetadata.java:
##########
@@ -58,4 +58,9 @@ public interface InstanceMetadata
      * @return a {@link CassandraAdapterDelegate} specific for the instance
      */
     @Nullable CassandraAdapterDelegate delegate();
+
+    /**
+     * @return {@link InstanceMetrics} metrics specific for the cassandra 
instance

Review Comment:
   NIT
   ```suggestion
        * @return {@link InstanceMetrics} metrics specific for the Cassandra 
instance
   ```



##########
src/test/java/org/apache/cassandra/sidecar/restore/RestoreJobManagerTest.java:
##########
@@ -66,7 +68,7 @@ class RestoreJobManagerTest
     @BeforeEach
     void setup()
     {
-        Injector injector = Guice.createInjector(new MainModule());
+        Injector injector = Guice.createInjector(Modules.override(new 
MainModule()).with(new TestModule()));

Review Comment:
   why do we need the test module here? the metrics should be provided in the 
main module



##########
src/main/java/org/apache/cassandra/sidecar/cluster/instance/InstanceMetadataImpl.java:
##########
@@ -188,6 +203,29 @@ public Builder delegate(CassandraAdapterDelegate delegate)
             return update(b -> b.delegate = delegate);
         }
 
+        /**
+         * Builds instance specific {@link 
com.codahale.metrics.MetricRegistry} given the global registry name.
+         *
+         * @param registryName global {@link 
com.codahale.metrics.MetricRegistry} name
+         * @return a reference to this Builder
+         */
+        public Builder globalMetricRegistryName(String registryName)
+
+        {
+            Objects.requireNonNull(registryName);
+
+            String instanceRegistryName = instanceRegistryName(registryName);
+            MetricRegistry instanceMetricRegistry = 
SharedMetricRegistries.getOrCreate(instanceRegistryName);
+            InstanceMetricsImpl instanceMetrics = new 
InstanceMetricsImpl(instanceMetricRegistry);
+
+            return update(b -> b.metrics = instanceMetrics);
+        }
+
+        private String instanceRegistryName(String globalRegistryName)
+        {
+            return globalRegistryName + "_" + id;

Review Comment:
   this will not work if you set the globalMetricRegistryName first and then 
the id. Should we compute this during build time instead?



##########
src/main/java/org/apache/cassandra/sidecar/metrics/instance/UploadSSTableMetrics.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.metrics.instance;
+
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import org.apache.cassandra.sidecar.metrics.NamedMetric;
+
+import static 
org.apache.cassandra.sidecar.metrics.instance.InstanceMetrics.INSTANCE_PREFIX;
+
+/**
+ * {@link UploadSSTableMetrics} tracks metrics captured during upload of 
SSTable components into Sidecar.
+ */
+public class UploadSSTableMetrics
+{
+    public static final String DOMAIN = INSTANCE_PREFIX + ".upload_sstable";
+    protected final MetricRegistry metricRegistry;
+    protected final Map<String, UploadSSTableComponentMetrics> 
uploadComponentMetrics = new ConcurrentHashMap<>();
+
+    public UploadSSTableMetrics(MetricRegistry metricRegistry)
+    {
+        this.metricRegistry = metricRegistry;
+    }
+
+    public UploadSSTableComponentMetrics forComponent(String component)
+    {
+        return uploadComponentMetrics
+               .computeIfAbsent(component, sstableComponent -> new 
UploadSSTableComponentMetrics(metricRegistry, sstableComponent));
+    }
+
+    /**
+     * Metrics tracking during upload of a specific SSTable component
+     */
+    public static class UploadSSTableComponentMetrics
+    {
+        protected final MetricRegistry metricRegistry;
+        public final String sstableComponent;
+        public final NamedMetric<Meter> rateLimitedCalls;
+        public final NamedMetric<Meter> diskUsageHighErrors;
+
+        public UploadSSTableComponentMetrics(MetricRegistry metricRegistry, 
String sstableComponent)
+        {
+            this.metricRegistry = Objects.requireNonNull(metricRegistry, 
"Metric registry can not be null");
+            this.sstableComponent
+            = Objects.requireNonNull(sstableComponent, "SSTable component 
required for component specific metrics capture");
+            if (sstableComponent.isEmpty())
+            {
+                throw new IllegalArgumentException("SSTableComponent required 
for component specific metrics capture");
+            }
+
+            NamedMetric.Tag componentTag = NamedMetric.Tag.of("component", 
sstableComponent);
+
+            rateLimitedCalls
+            = NamedMetric.builder(metricRegistry::meter)
+                         .withDomain(DOMAIN)
+                         .withName("throttled_429")

Review Comment:
   should we make these names constants of the class with public visibility?



##########
src/main/java/org/apache/cassandra/sidecar/routes/sstableuploads/SSTableUploadHandler.java:
##########
@@ -116,10 +119,15 @@ public void handleInternal(RoutingContext context,
         // accept the upload.
         httpRequest.pause();
 
+        InstanceMetrics instanceMetrics = 
metadataFetcher.instance(host).metrics();

Review Comment:
   InstanceMetadata can be null, we usually return 503 Unavailable when this 
occurs. I think we run into  the issue of an NPE here. 



##########
src/test/java/org/apache/cassandra/sidecar/server/ServerSSLTest.java:
##########
@@ -124,6 +123,7 @@ void tearDown() throws InterruptedException
     void failsWhenKeyStoreIsNotConfigured()
     {
         
builder.sslConfiguration(SslConfigurationImpl.builder().enabled(true).build());
+        vertx = vertx();

Review Comment:
   why is this change needed?



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