Skip to content

Commit

Permalink
feat(telemetry): collect SPDK underlying device type
Browse files Browse the repository at this point in the history
ref: 6033

Signed-off-by: Chin-Ya Huang <chin-ya.huang@suse.com>
  • Loading branch information
c3y1huang authored and David Ko committed Dec 12, 2023
1 parent e716691 commit 27101bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 10 additions & 2 deletions controller/setting_controller.go
Expand Up @@ -1720,9 +1720,17 @@ func (info *ClusterInfo) collectNodeDiskCount() error {

structMap := make(map[util.StructName]int)
for _, disk := range node.Spec.Disks {
deviceType, err := types.GetDeviceTypeOf(disk.Path)
var deviceType string
switch disk.Type {
case longhorn.DiskTypeFilesystem:
deviceType, err = types.GetDeviceTypeOf(disk.Path)
case longhorn.DiskTypeBlock:
deviceType, err = types.GetBlockDeviceType(disk.Path)
default:
err = fmt.Errorf("unknown disk type %v", disk.Type)
}
if err != nil {
info.logger.WithError(err).Warnf("Failed to get device type of %v", disk.Path)
info.logger.WithError(err).Warnf("Failed to get %v device type of %v", disk.Type, disk.Path)
deviceType = types.ValueUnknown
}

Expand Down
6 changes: 3 additions & 3 deletions types/device.go
Expand Up @@ -33,7 +33,7 @@ func GetDeviceTypeOf(mountPath string) (string, error) {
return "", errors.Wrapf(err, "failed to get device path in %v", procMountPaths)
}

return getBlockDeviceType(devicePath)
return GetBlockDeviceType(devicePath)
}

func getDevicePathOf(mountPath, procMountPath string) (string, error) {
Expand Down Expand Up @@ -67,7 +67,7 @@ func getDevicePathOf(mountPath, procMountPath string) (string, error) {
return devicePath, nil
}

func getBlockDeviceType(devicePath string) (string, error) {
func GetBlockDeviceType(devicePath string) (string, error) {
// Check if device rotational file exist
deviceID := filepath.Base(devicePath)
rotationalPath := fmt.Sprintf("/sys/block/%s/queue/rotational", deviceID)
Expand All @@ -84,7 +84,7 @@ func getBlockDeviceType(devicePath string) (string, error) {
}

// Try to get the device type of the parent device
return getBlockDeviceType(parentDevicePath)
return GetBlockDeviceType(parentDevicePath)

}
return "", errors.Wrapf(err, "failed to get %v file information", rotationalPath)
Expand Down

0 comments on commit 27101bb

Please sign in to comment.