You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "nvharikrishna (via GitHub)" <gi...@apache.org> on 2025/12/05 17:14:26 UTC
[PR] CASSSIDECAR-366 Added endpoint for returning the system disk information [cassandra-sidecar]
nvharikrishna opened a new pull request, #297:
URL: https://github.com/apache/cassandra-sidecar/pull/297
[CASSSIDECAR-366](https://issues.apache.org/jira/browse/CASSSIDECAR-366) Added endpoint for System Disk Information to Sidecar
Endpoint information:
- Path: /api/v1/system/disk-info
- Method: GET
- Authorization: Requires SYSTEM permission (a new permission that will be added)
- Response: JSON array of disk information objects
Sample response:
```json
[
{
"totalSpace": 1000000000000,
"freeSpace": 500000000000,
"usableSpace": 450000000000,
"name": "data1",
"mount": "/dev/sda1",
"type": "ext4"
}
]
```
--
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
Re: [PR] CASSSIDECAR-366 Added endpoint for returning the system disk information [cassandra-sidecar]
Posted by "yifan-c (via GitHub)" <gi...@apache.org>.
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: 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
Re: [PR] CASSSIDECAR-366 Added endpoint for returning the system disk information [cassandra-sidecar]
Posted by "nvharikrishna (via GitHub)" <gi...@apache.org>.
nvharikrishna commented on code in PR #297:
URL: https://github.com/apache/cassandra-sidecar/pull/297#discussion_r2594709013
##########
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:
done
##########
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:
It can be specific to disk info. Made the changes.
##########
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:
Used cache as it fits the cache use case. But yeah it could be overhead for this simple use case. Changed it to atomic reference with 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: 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
Re: [PR] CASSSIDECAR-366 Added endpoint for returning the system disk information [cassandra-sidecar]
Posted by "nvharikrishna (via GitHub)" <gi...@apache.org>.
nvharikrishna commented on code in PR #297:
URL: https://github.com/apache/cassandra-sidecar/pull/297#discussion_r2596500262
##########
server/src/main/java/org/apache/cassandra/sidecar/handlers/sysinfo/DiskInfoHandler.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.handlers.sysinfo;
+
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+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 Duration CACHE_TTL = Duration.ofMinutes(5);
+
+ private final AtomicReference<CacheEntry> 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 = new AtomicReference<>();
+ }
+
+ /**
+ * Loads disk information from the system using OSHI
+ */
+ private List<DiskInfo> loadDiskInfo()
Review Comment:
done
##########
server/src/main/java/org/apache/cassandra/sidecar/handlers/sysinfo/DiskInfoHandler.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.handlers.sysinfo;
+
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+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 Duration CACHE_TTL = Duration.ofMinutes(5);
+
+ private final AtomicReference<CacheEntry> 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 = new AtomicReference<>();
+ }
+
+ /**
+ * Loads disk information from the system using OSHI
+ */
+ private List<DiskInfo> loadDiskInfo()
+ {
+ SystemInfo systemInfo = new SystemInfo();
+ List<OSFileStore> fileStoreList = systemInfo.getOperatingSystem().getFileSystem().getFileStores();
+ List<DiskInfo> diskInfoList = new ArrayList<>(fileStoreList.size());
+
+ for (OSFileStore fileStore : fileStoreList)
+ {
+ diskInfoList.add(new DiskInfo(fileStore.getTotalSpace(),
+ fileStore.getFreeSpace(),
+ fileStore.getUsableSpace(),
+ fileStore.getName(),
+ fileStore.getMount(),
+ fileStore.getType()));
+ }
+
+ return diskInfoList;
+ }
+
+ /**
+ * Gets cached disk info or loads fresh data if cache is expired or empty
+ */
+ private List<DiskInfo> getCachedDiskInfo()
+ {
+ CacheEntry current = diskInfoCache.get();
+
+ // Check if cache is empty or expired
+ if (current == null || current.isExpired())
+ {
+ List<DiskInfo> freshData = loadDiskInfo();
+ CacheEntry newEntry = new CacheEntry(freshData, CACHE_TTL);
+
+ // Try to update with CAS
+ if (diskInfoCache.compareAndSet(current, newEntry)) {
Review Comment:
done
##########
server/src/main/java/org/apache/cassandra/sidecar/handlers/sysinfo/DiskInfoHandler.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.handlers.sysinfo;
+
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+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 Duration CACHE_TTL = Duration.ofMinutes(5);
+
+ private final AtomicReference<CacheEntry> 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 = new AtomicReference<>();
+ }
+
+ /**
+ * Loads disk information from the system using OSHI
+ */
+ private List<DiskInfo> loadDiskInfo()
+ {
+ SystemInfo systemInfo = new SystemInfo();
+ List<OSFileStore> fileStoreList = systemInfo.getOperatingSystem().getFileSystem().getFileStores();
+ List<DiskInfo> diskInfoList = new ArrayList<>(fileStoreList.size());
+
+ for (OSFileStore fileStore : fileStoreList)
+ {
+ diskInfoList.add(new DiskInfo(fileStore.getTotalSpace(),
+ fileStore.getFreeSpace(),
+ fileStore.getUsableSpace(),
+ fileStore.getName(),
+ fileStore.getMount(),
+ fileStore.getType()));
+ }
+
+ return diskInfoList;
+ }
+
+ /**
+ * Gets cached disk info or loads fresh data if cache is expired or empty
+ */
+ private List<DiskInfo> getCachedDiskInfo()
+ {
+ CacheEntry current = diskInfoCache.get();
+
+ // Check if cache is empty or expired
+ if (current == null || current.isExpired())
+ {
+ List<DiskInfo> freshData = loadDiskInfo();
+ CacheEntry newEntry = new CacheEntry(freshData, CACHE_TTL);
+
+ // Try to update with CAS
+ if (diskInfoCache.compareAndSet(current, newEntry)) {
+ return freshData;
+ }
+ }
+
+ return diskInfoCache.get().diskInfo;
+ }
+
+ @Override
+ protected Void extractParamsOrThrow(RoutingContext context)
+ {
+ // No params to extract
+ return null;
+ }
+
+ @Override
+ protected void handleInternal(RoutingContext context,
+ HttpServerRequest httpRequest,
+ @NotNull String host,
+ SocketAddress remoteAddress,
+ Void request)
+ {
+ executorPools.internal()
+ .executeBlocking(this::getCachedDiskInfo)
+ .onSuccess(context::json)
+ .onFailure(e -> {
+ LOGGER.warn("Failed to fetch disk information", e);
+ context.fail(wrapHttpException(HttpResponseStatus.SERVICE_UNAVAILABLE,
+ e.getMessage(), e));
+ });
+ }
+
+ @Override
+ public Set<Authorization> requiredAuthorizations()
+ {
+ return Set.of(BasicPermissions.DISK_INFO.toAuthorization());
+ }
+
+ /**
+ * Cache entry that holds the disk information and the expiry time
+ */
+ private static class CacheEntry
+ {
+ final List<DiskInfo> diskInfo;
+ final long expiryTime;
+
+ CacheEntry(List<DiskInfo> diskInfo, Duration ttl)
+ {
+ this.diskInfo = diskInfo;
+ this.expiryTime = System.currentTimeMillis() + ttl.toMillis();
Review Comment:
done
##########
server/src/main/java/org/apache/cassandra/sidecar/handlers/sysinfo/DiskInfoHandler.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.handlers.sysinfo;
+
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+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 Duration CACHE_TTL = Duration.ofMinutes(5);
+
+ private final AtomicReference<CacheEntry> 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 = new AtomicReference<>();
+ }
+
+ /**
+ * Loads disk information from the system using OSHI
+ */
+ private List<DiskInfo> loadDiskInfo()
+ {
+ SystemInfo systemInfo = new SystemInfo();
+ List<OSFileStore> fileStoreList = systemInfo.getOperatingSystem().getFileSystem().getFileStores();
+ List<DiskInfo> diskInfoList = new ArrayList<>(fileStoreList.size());
+
+ for (OSFileStore fileStore : fileStoreList)
+ {
+ diskInfoList.add(new DiskInfo(fileStore.getTotalSpace(),
+ fileStore.getFreeSpace(),
+ fileStore.getUsableSpace(),
+ fileStore.getName(),
+ fileStore.getMount(),
+ fileStore.getType()));
+ }
+
+ return diskInfoList;
+ }
+
+ /**
+ * Gets cached disk info or loads fresh data if cache is expired or empty
+ */
+ private List<DiskInfo> getCachedDiskInfo()
+ {
+ CacheEntry current = diskInfoCache.get();
+
+ // Check if cache is empty or expired
+ if (current == null || current.isExpired())
+ {
+ List<DiskInfo> freshData = loadDiskInfo();
+ CacheEntry newEntry = new CacheEntry(freshData, CACHE_TTL);
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.
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
Re: [PR] CASSSIDECAR-366 Added endpoint for returning the system disk information [cassandra-sidecar]
Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh merged PR #297:
URL: https://github.com/apache/cassandra-sidecar/pull/297
--
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
Re: [PR] CASSSIDECAR-366 Added endpoint for returning the system disk information [cassandra-sidecar]
Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on code in PR #297:
URL: https://github.com/apache/cassandra-sidecar/pull/297#discussion_r2596440782
##########
server/src/main/java/org/apache/cassandra/sidecar/handlers/sysinfo/DiskInfoHandler.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.handlers.sysinfo;
+
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+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 Duration CACHE_TTL = Duration.ofMinutes(5);
+
+ private final AtomicReference<CacheEntry> 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 = new AtomicReference<>();
+ }
+
+ /**
+ * Loads disk information from the system using OSHI
+ */
+ private List<DiskInfo> loadDiskInfo()
+ {
+ SystemInfo systemInfo = new SystemInfo();
+ List<OSFileStore> fileStoreList = systemInfo.getOperatingSystem().getFileSystem().getFileStores();
+ List<DiskInfo> diskInfoList = new ArrayList<>(fileStoreList.size());
+
+ for (OSFileStore fileStore : fileStoreList)
+ {
+ diskInfoList.add(new DiskInfo(fileStore.getTotalSpace(),
+ fileStore.getFreeSpace(),
+ fileStore.getUsableSpace(),
+ fileStore.getName(),
+ fileStore.getMount(),
+ fileStore.getType()));
+ }
+
+ return diskInfoList;
+ }
+
+ /**
+ * Gets cached disk info or loads fresh data if cache is expired or empty
+ */
+ private List<DiskInfo> getCachedDiskInfo()
+ {
+ CacheEntry current = diskInfoCache.get();
+
+ // Check if cache is empty or expired
+ if (current == null || current.isExpired())
+ {
+ List<DiskInfo> freshData = loadDiskInfo();
+ CacheEntry newEntry = new CacheEntry(freshData, CACHE_TTL);
+
+ // Try to update with CAS
+ if (diskInfoCache.compareAndSet(current, newEntry)) {
+ return freshData;
+ }
+ }
+
+ return diskInfoCache.get().diskInfo;
+ }
+
+ @Override
+ protected Void extractParamsOrThrow(RoutingContext context)
+ {
+ // No params to extract
+ return null;
+ }
+
+ @Override
+ protected void handleInternal(RoutingContext context,
+ HttpServerRequest httpRequest,
+ @NotNull String host,
+ SocketAddress remoteAddress,
+ Void request)
+ {
+ executorPools.internal()
+ .executeBlocking(this::getCachedDiskInfo)
+ .onSuccess(context::json)
+ .onFailure(e -> {
+ LOGGER.warn("Failed to fetch disk information", e);
+ context.fail(wrapHttpException(HttpResponseStatus.SERVICE_UNAVAILABLE,
+ e.getMessage(), e));
+ });
+ }
+
+ @Override
+ public Set<Authorization> requiredAuthorizations()
+ {
+ return Set.of(BasicPermissions.DISK_INFO.toAuthorization());
+ }
+
+ /**
+ * Cache entry that holds the disk information and the expiry time
+ */
+ private static class CacheEntry
+ {
+ final List<DiskInfo> diskInfo;
+ final long expiryTime;
+
+ CacheEntry(List<DiskInfo> diskInfo, Duration ttl)
+ {
+ this.diskInfo = diskInfo;
+ this.expiryTime = System.currentTimeMillis() + ttl.toMillis();
Review Comment:
can we use time provider here instead?
##########
server/src/main/java/org/apache/cassandra/sidecar/acl/authorization/FeaturePermission.java:
##########
@@ -80,7 +81,9 @@ public enum FeaturePermission
* Permission for live migration data copy operations. This feature permission grants access to
* stream files and list files, which are necessary for copying data during live migration processes.
*/
- LIVE_MIGRATION("LIVE_MIGRATION", DATA_COPY, LIST_FILES);
+ LIVE_MIGRATION("LIVE_MIGRATION", DATA_COPY, LIST_FILES),
+
+ SYSTEM("SYSTEM", DISK_INFO);
Review Comment:
👍
##########
server/src/main/java/org/apache/cassandra/sidecar/handlers/sysinfo/DiskInfoHandler.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.handlers.sysinfo;
+
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+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 Duration CACHE_TTL = Duration.ofMinutes(5);
+
+ private final AtomicReference<CacheEntry> 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 = new AtomicReference<>();
+ }
+
+ /**
+ * Loads disk information from the system using OSHI
+ */
+ private List<DiskInfo> loadDiskInfo()
+ {
+ SystemInfo systemInfo = new SystemInfo();
+ List<OSFileStore> fileStoreList = systemInfo.getOperatingSystem().getFileSystem().getFileStores();
+ List<DiskInfo> diskInfoList = new ArrayList<>(fileStoreList.size());
+
+ for (OSFileStore fileStore : fileStoreList)
+ {
+ diskInfoList.add(new DiskInfo(fileStore.getTotalSpace(),
+ fileStore.getFreeSpace(),
+ fileStore.getUsableSpace(),
+ fileStore.getName(),
+ fileStore.getMount(),
+ fileStore.getType()));
+ }
+
+ return diskInfoList;
+ }
+
+ /**
+ * Gets cached disk info or loads fresh data if cache is expired or empty
+ */
+ private List<DiskInfo> getCachedDiskInfo()
+ {
+ CacheEntry current = diskInfoCache.get();
+
+ // Check if cache is empty or expired
+ if (current == null || current.isExpired())
+ {
+ List<DiskInfo> freshData = loadDiskInfo();
+ CacheEntry newEntry = new CacheEntry(freshData, CACHE_TTL);
Review Comment:
can we use the [TimeProvider](https://github.com/apache/cassandra-sidecar/blob/trunk/server/src/main/java/org/apache/cassandra/sidecar/utils/TimeProvider.java) here instead? You could inject it as a class parameter for `DiskInfoHandler` and use it in this constructor
##########
server/src/main/java/org/apache/cassandra/sidecar/handlers/sysinfo/DiskInfoHandler.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.handlers.sysinfo;
+
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+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 Duration CACHE_TTL = Duration.ofMinutes(5);
+
+ private final AtomicReference<CacheEntry> 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 = new AtomicReference<>();
+ }
+
+ /**
+ * Loads disk information from the system using OSHI
+ */
+ private List<DiskInfo> loadDiskInfo()
+ {
+ SystemInfo systemInfo = new SystemInfo();
+ List<OSFileStore> fileStoreList = systemInfo.getOperatingSystem().getFileSystem().getFileStores();
+ List<DiskInfo> diskInfoList = new ArrayList<>(fileStoreList.size());
+
+ for (OSFileStore fileStore : fileStoreList)
+ {
+ diskInfoList.add(new DiskInfo(fileStore.getTotalSpace(),
+ fileStore.getFreeSpace(),
+ fileStore.getUsableSpace(),
+ fileStore.getName(),
+ fileStore.getMount(),
+ fileStore.getType()));
+ }
+
+ return diskInfoList;
+ }
+
+ /**
+ * Gets cached disk info or loads fresh data if cache is expired or empty
+ */
+ private List<DiskInfo> getCachedDiskInfo()
+ {
+ CacheEntry current = diskInfoCache.get();
+
+ // Check if cache is empty or expired
+ if (current == null || current.isExpired())
+ {
+ List<DiskInfo> freshData = loadDiskInfo();
+ CacheEntry newEntry = new CacheEntry(freshData, CACHE_TTL);
+
+ // Try to update with CAS
+ if (diskInfoCache.compareAndSet(current, newEntry)) {
Review Comment:
NIT: formatting
```suggestion
if (diskInfoCache.compareAndSet(current, newEntry))
{
```
##########
server/src/main/java/org/apache/cassandra/sidecar/handlers/sysinfo/DiskInfoHandler.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.handlers.sysinfo;
+
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+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 Duration CACHE_TTL = Duration.ofMinutes(5);
+
+ private final AtomicReference<CacheEntry> 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 = new AtomicReference<>();
+ }
+
+ /**
+ * Loads disk information from the system using OSHI
+ */
+ private List<DiskInfo> loadDiskInfo()
Review Comment:
NIT: can we keep the public methods before private methods?
--
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