-
Notifications
You must be signed in to change notification settings - Fork 52
CASSSIDECAR-366 Added endpoint for returning the system disk information #297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| // System information related permissions | ||
| public static final Permission SYSTEM = new StandardPermission("SYSTEM", CLUSTER_SCOPE); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
3ef5949 to
c195d7e
Compare
yifan-c
left a comment
There was a problem hiding this 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
frankgh
left a comment
There was a problem hiding this 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); |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: formatting
| if (diskInfoCache.compareAndSet(current, newEntry)) { | |
| if (diskInfoCache.compareAndSet(current, newEntry)) | |
| { |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
nvharikrishna
left a comment
There was a problem hiding this 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)) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
frankgh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
CASSSIDECAR-366 Added endpoint for System Disk Information to Sidecar
Endpoint information:
Sample response:
[ { "totalSpace": 1000000000000, "freeSpace": 500000000000, "usableSpace": 450000000000, "name": "data1", "mount": "/dev/sda1", "type": "ext4" } ]