yifan-c commented on code in PR #297:
URL: https://github.com/apache/cassandra-sidecar/pull/297#discussion_r2594031553
##########
client-common/src/main/java/org/apache/cassandra/sidecar/common/ApiEndpointsV1.java:
##########
@@ -177,6 +177,9 @@ public final class ApiEndpointsV1
// Lifecycle APIs
public static final String LIFECYCLE_ROUTE = API_V1 + CASSANDRA +
"/lifecycle";
+ private static final String SYSTEM_API_PREFIX = API_V1 + "/system";
+ public static final String SYSTEM_DISK_INFO_ROUTE = SYSTEM_API_PREFIX +
"/diskinfo";
Review Comment:
following the convention (using `-` to connect words in endpoint), it should
be `disk-info`.
##########
server/src/main/java/org/apache/cassandra/sidecar/acl/authorization/BasicPermissions.java:
##########
@@ -92,4 +92,7 @@ public class BasicPermissions
// Lifecycle permissions
public static final Permission READ_LIFECYCLE = new
DomainAwarePermission("LIFECYCLE:READ", CLUSTER_SCOPE);
public static final Permission MODIFY_LIFECYCLE = new
DomainAwarePermission("LIFECYCLE:MODIFY", CLUSTER_SCOPE);
+
+ // System information related permissions
+ public static final Permission SYSTEM = new StandardPermission("SYSTEM",
CLUSTER_SCOPE);
Review Comment:
nit: Should it be `DISK_INFO:READ`? `SYSTEM` might be too wide.
##########
server/src/main/java/org/apache/cassandra/sidecar/handlers/sysinfo/DiskInfoHandler.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.handlers.sysinfo;
+
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.github.benmanes.caffeine.cache.CacheLoader;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import com.github.benmanes.caffeine.cache.LoadingCache;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import io.netty.handler.codec.http.HttpResponseStatus;
+import io.vertx.core.http.HttpServerRequest;
+import io.vertx.core.net.SocketAddress;
+import io.vertx.ext.auth.authorization.Authorization;
+import io.vertx.ext.web.RoutingContext;
+import org.apache.cassandra.sidecar.acl.authorization.BasicPermissions;
+import org.apache.cassandra.sidecar.common.response.data.DiskInfo;
+import org.apache.cassandra.sidecar.concurrent.ExecutorPools;
+import org.apache.cassandra.sidecar.handlers.AbstractHandler;
+import org.apache.cassandra.sidecar.handlers.AccessProtected;
+import org.apache.cassandra.sidecar.utils.CassandraInputValidator;
+import org.apache.cassandra.sidecar.utils.InstanceMetadataFetcher;
+import org.jetbrains.annotations.NotNull;
+import oshi.SystemInfo;
+import oshi.software.os.OSFileStore;
+
+import static
org.apache.cassandra.sidecar.utils.HttpExceptions.wrapHttpException;
+
+/**
+ * Handler that retrieves disk information for all file stores on the system.
+ * Uses OSHI library to gather metrics about storage capacity and usage for
each mounted file system.
+ * Disk information is cached for 5 minutes to avoid expensive OSHI calls on
every request.
+ */
+@Singleton
+public class DiskInfoHandler extends AbstractHandler<Void> implements
AccessProtected
+{
+ private static final Logger LOGGER =
LoggerFactory.getLogger(DiskInfoHandler.class);
+ private static final String CACHE_KEY = "disk_info";
+ private static final Duration CACHE_TTL = Duration.ofMinutes(5);
+
+ private final LoadingCache<String, List<DiskInfo>> diskInfoCache;
+
+ /**
+ * Constructs a handler with the provided {@code metadataFetcher}
+ *
+ * @param metadataFetcher the interface to retrieve instance metadata
+ * @param executorPools the executor pools for blocking executions
+ * @param validator a validator instance to validate
Cassandra-specific input
+ */
+ @Inject
+ protected DiskInfoHandler(InstanceMetadataFetcher metadataFetcher,
ExecutorPools executorPools, CassandraInputValidator validator)
+ {
+ super(metadataFetcher, executorPools, validator);
+
+ this.diskInfoCache = Caffeine.newBuilder()
+ .expireAfterWrite(CACHE_TTL)
+ .maximumSize(1)
Review Comment:
The cache has only a single value.. Why using a cache? Seemingly an
overhead.
If it remains a single value cache, maybe consider just using
`AtomicReference` and a `lastUpdated` timestamp.
--
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]