Skip to content

Conversation

@nvharikrishna
Copy link
Contributor

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:

  [
    {
      "totalSpace": 1000000000000,
      "freeSpace": 500000000000,
      "usableSpace": 450000000000,
      "name": "data1",
      "mount": "/dev/sda1",
      "type": "ext4"
    }
  ]

Comment on lines 96 to 97
// System information related permissions
public static final Permission SYSTEM = new StandardPermission("SYSTEM", CLUSTER_SCOPE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Should it be DISK_INFO:READ? SYSTEM might be too wide.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be specific to disk info. Made the changes.

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";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

following the convention (using - to connect words in endpoint), it should be disk-info.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


this.diskInfoCache = Caffeine.newBuilder()
.expireAfterWrite(CACHE_TTL)
.maximumSize(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@nvharikrishna nvharikrishna force-pushed the 366-trunk-sysinfo-disk branch from 3ef5949 to c195d7e Compare December 6, 2025 11:40
Copy link
Contributor

@yifan-c yifan-c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

The discussion thread on adding OSHI dep: https://lists.apache.org/thread/md5voclo1900nvysqgvlmtsc5xqy3ckd

Copy link
Contributor

@frankgh frankgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in general. I have a few comments

LIVE_MIGRATION("LIVE_MIGRATION", DATA_COPY, LIST_FILES);
LIVE_MIGRATION("LIVE_MIGRATION", DATA_COPY, LIST_FILES),

SYSTEM("SYSTEM", DISK_INFO);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

CacheEntry newEntry = new CacheEntry(freshData, CACHE_TTL);

// Try to update with CAS
if (diskInfoCache.compareAndSet(current, newEntry)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: formatting

Suggested change
if (diskInfoCache.compareAndSet(current, newEntry)) {
if (diskInfoCache.compareAndSet(current, newEntry))
{

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

/**
* Loads disk information from the system using OSHI
*/
private List<DiskInfo> loadDiskInfo()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: can we keep the public methods before private methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (current == null || current.isExpired())
{
List<DiskInfo> freshData = loadDiskInfo();
CacheEntry newEntry = new CacheEntry(freshData, CACHE_TTL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use the TimeProvider here instead? You could inject it as a class parameter for DiskInfoHandler and use it in this constructor

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

CacheEntry(List<DiskInfo> diskInfo, Duration ttl)
{
this.diskInfo = diskInfo;
this.expiryTime = System.currentTimeMillis() + ttl.toMillis();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use time provider here instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor Author

@nvharikrishna nvharikrishna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed review comments.

CacheEntry newEntry = new CacheEntry(freshData, CACHE_TTL);

// Try to update with CAS
if (diskInfoCache.compareAndSet(current, newEntry)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (current == null || current.isExpired())
{
List<DiskInfo> freshData = loadDiskInfo();
CacheEntry newEntry = new CacheEntry(freshData, CACHE_TTL);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

CacheEntry(List<DiskInfo> diskInfo, Duration ttl)
{
this.diskInfo = diskInfo;
this.expiryTime = System.currentTimeMillis() + ttl.toMillis();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

/**
* Loads disk information from the system using OSHI
*/
private List<DiskInfo> loadDiskInfo()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@frankgh frankgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@frankgh frankgh merged commit fa9439b into apache:trunk Dec 8, 2025
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants