Skip to content

Commit

Permalink
Incorporate review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kislaykishore committed Aug 23, 2024
1 parent bace0c6 commit a1abe0c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 48 deletions.
66 changes: 33 additions & 33 deletions internal/fs/wrappers/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ var (

// Error categories
const (
deviceErr = "DEVICE_ERROR"
dirNotEmptyErr = "DIR_NOT_EMPTY"
fileExistsErr = "FILE_EXISTS"
fileDirErr = "FILE_DIR_ERROR"
notImplementedErr = "NOT_IMPLEMENTED"
ioErr = "IO_ERROR"
intrErr = "INTERRUPT_ERROR"
invalidArgErr = "INVALID_ARGUMENT"
invalidOpErr = "INVALID_OPERATION"
miscErr = "MISC_ERROR"
nwErr = "NETWORK_ERROR"
noFileOrDirErr = "NO_FILE_OR_DIR"
notADirErr = "NOT_A_DIR"
permError = "PERM_ERROR"
processMgmtErr = "PROCESS_RESOURCE_MGMT_ERROR"
tooManyFilesErr = "TOO_MANY_OPEN_FILES"
errDevice = "DEVICE_ERROR"
errDirNotEmpty = "DIR_NOT_EMPTY"
errFileExists = "FILE_EXISTS"
errFileDir = "FILE_DIR_ERROR"
errNotImplemented = "NOT_IMPLEMENTED"
errIO = "IO_ERROR"
errInterrupt = "INTERRUPT_ERROR"
errInvalidArg = "INVALID_ARGUMENT"
errInvalidOp = "INVALID_OPERATION"
errMisc = "MISC_ERROR"
errNetwork = "NETWORK_ERROR"
errNoFileOrDir = "NO_FILE_OR_DIR"
errNotADir = "NOT_A_DIR"
errPerm = "PERM_ERROR"
errProcessMgmt = "PROCESS_RESOURCE_MGMT_ERROR"
errTooManyFiles = "TOO_MANY_OPEN_FILES"
)

// Initialize the metrics.
Expand Down Expand Up @@ -117,34 +117,34 @@ func categorize(err error) string {
syscall.EPROTO,
syscall.ERFKILL,
syscall.EXDEV:
return deviceErr
return errDevice

case syscall.ENOTEMPTY:
return dirNotEmptyErr
return errDirNotEmpty

case syscall.EEXIST:
return fileExistsErr
return errFileExists

case syscall.EBADF,
syscall.EBADFD,
syscall.EFBIG,
syscall.EISDIR,
syscall.EISNAM,
syscall.ENOTBLK:
return fileDirErr
return errFileDir

case syscall.ENOSYS:
return notImplementedErr
return errNotImplemented

case syscall.EIO:
return ioErr
return errIO

case syscall.ECANCELED,
syscall.EINTR:
return intrErr
return errInterrupt

case syscall.EINVAL:
return invalidArgErr
return errInvalidArg

case syscall.E2BIG,
syscall.EALREADY,
Expand All @@ -157,7 +157,7 @@ func categorize(err error) string {
syscall.ENOTTY,
syscall.ERANGE,
syscall.ESPIPE:
return invalidOpErr
return errInvalidOp

case syscall.EADV,
syscall.EBADSLT,
Expand Down Expand Up @@ -191,7 +191,7 @@ func categorize(err error) string {
syscall.EUCLEAN,
syscall.EUNATCH,
syscall.EXFULL:
return miscErr
return errMisc

case syscall.EADDRINUSE,
syscall.EADDRNOTAVAIL,
Expand Down Expand Up @@ -231,13 +231,13 @@ func categorize(err error) string {
syscall.ESOCKTNOSUPPORT,
syscall.ESTRPIPE,
syscall.ETIMEDOUT:
return nwErr
return errNetwork

case syscall.ENOENT:
return noFileOrDirErr
return errNoFileOrDir

case syscall.ENOTDIR:
return notADirErr
return errNotADir

case syscall.EACCES,
syscall.EKEYEXPIRED,
Expand All @@ -247,7 +247,7 @@ func categorize(err error) string {
syscall.EPERM,
syscall.EROFS,
syscall.ETXTBSY:
return permError
return errPerm

case syscall.EAGAIN,
syscall.EBUSY,
Expand All @@ -264,13 +264,13 @@ func categorize(err error) string {
syscall.EOWNERDEAD,
syscall.ESRCH,
syscall.EUSERS:
return processMgmtErr
return errProcessMgmt

case syscall.EMFILE,
syscall.ENFILE:
return tooManyFilesErr
return errTooManyFiles
}
return miscErr
return errMisc
}

// Records file system operation count, failed operation count and the operation latency.
Expand Down
30 changes: 15 additions & 15 deletions internal/fs/wrappers/monitoring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,63 +37,63 @@ func TestFsErrStrAndCategory(t *testing.T) {
}{
{
fsErr: fmt.Errorf("some random error"),
expectedCategory: ioErr,
expectedCategory: errIO,
},
{
fsErr: syscall.ENOTEMPTY,
expectedCategory: dirNotEmptyErr,
expectedCategory: errDirNotEmpty,
},
{
fsErr: syscall.EEXIST,
expectedCategory: fileExistsErr,
expectedCategory: errFileExists,
},
{
fsErr: syscall.EINVAL,
expectedCategory: invalidArgErr,
expectedCategory: errInvalidArg,
},
{
fsErr: syscall.EINTR,
expectedCategory: intrErr,
expectedCategory: errInterrupt,
},
{
fsErr: syscall.ENOSYS,
expectedCategory: notImplementedErr,
expectedCategory: errNotImplemented,
},
{
fsErr: syscall.ENOSPC,
expectedCategory: processMgmtErr,
expectedCategory: errProcessMgmt,
},
{
fsErr: syscall.E2BIG,
expectedCategory: invalidOpErr,
expectedCategory: errInvalidOp,
},
{
fsErr: syscall.EHOSTDOWN,
expectedCategory: nwErr,
expectedCategory: errNetwork,
},
{
fsErr: syscall.ENODATA,
expectedCategory: miscErr,
expectedCategory: errMisc,
},
{
fsErr: syscall.ENODEV,
expectedCategory: deviceErr,
expectedCategory: errDevice,
},
{
fsErr: syscall.EISDIR,
expectedCategory: fileDirErr,
expectedCategory: errFileDir,
},
{
fsErr: syscall.ENOSYS,
expectedCategory: notImplementedErr,
expectedCategory: errNotImplemented,
},
{
fsErr: syscall.ENFILE,
expectedCategory: tooManyFilesErr,
expectedCategory: errTooManyFiles,
},
{
fsErr: syscall.EPERM,
expectedCategory: permError,
expectedCategory: errPerm,
},
}

Expand Down

0 comments on commit a1abe0c

Please sign in to comment.