Skip to content

Commit

Permalink
Change category name to look more like codes (#2390)
Browse files Browse the repository at this point in the history
* Change category name to look more like codes

Currently, the category names are phrases/sentences. Keeping it as
codes makes them more succinct and easily searchable.
  • Loading branch information
kislaykishore authored Aug 26, 2024
1 parent 577de7c commit 697baff
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 32 deletions.
54 changes: 37 additions & 17 deletions internal/fs/wrappers/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ var (
tracer = otel.Tracer(name)
)

// Error categories
const (
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.
func init() {

Expand Down Expand Up @@ -97,34 +117,34 @@ func categorize(err error) string {
syscall.EPROTO,
syscall.ERFKILL,
syscall.EXDEV:
return "device errors"
return errDevice

case syscall.ENOTEMPTY:
return "directory not empty"
return errDirNotEmpty

case syscall.EEXIST:
return "file exists"
return errFileExists

case syscall.EBADF,
syscall.EBADFD,
syscall.EFBIG,
syscall.EISDIR,
syscall.EISNAM,
syscall.ENOTBLK:
return "file/directory errors"
return errFileDir

case syscall.ENOSYS:
return "function not implemented"
return errNotImplemented

case syscall.EIO:
return "input/output error"
return errIO

case syscall.ECANCELED,
syscall.EINTR:
return "interrupt errors"
return errInterrupt

case syscall.EINVAL:
return "invalid argument"
return errInvalidArg

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

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

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

case syscall.ENOENT:
return "no such file or directory"
return errNoFileOrDir

case syscall.ENOTDIR:
return "not a directory"
return errNotADir

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

case syscall.EAGAIN,
syscall.EBUSY,
Expand All @@ -244,13 +264,13 @@ func categorize(err error) string {
syscall.EOWNERDEAD,
syscall.ESRCH,
syscall.EUSERS:
return "process/resource management errors"
return errProcessMgmt

case syscall.EMFILE,
syscall.ENFILE:
return "too many open files"
return errTooManyFiles
}
return "miscellaneous errors"
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: "input/output error",
expectedCategory: errIO,
},
{
fsErr: syscall.ENOTEMPTY,
expectedCategory: "directory not empty",
expectedCategory: errDirNotEmpty,
},
{
fsErr: syscall.EEXIST,
expectedCategory: "file exists",
expectedCategory: errFileExists,
},
{
fsErr: syscall.EINVAL,
expectedCategory: "invalid argument",
expectedCategory: errInvalidArg,
},
{
fsErr: syscall.EINTR,
expectedCategory: "interrupt errors",
expectedCategory: errInterrupt,
},
{
fsErr: syscall.ENOSYS,
expectedCategory: "function not implemented",
expectedCategory: errNotImplemented,
},
{
fsErr: syscall.ENOSPC,
expectedCategory: "process/resource management errors",
expectedCategory: errProcessMgmt,
},
{
fsErr: syscall.E2BIG,
expectedCategory: "invalid operation",
expectedCategory: errInvalidOp,
},
{
fsErr: syscall.EHOSTDOWN,
expectedCategory: "network errors",
expectedCategory: errNetwork,
},
{
fsErr: syscall.ENODATA,
expectedCategory: "miscellaneous errors",
expectedCategory: errMisc,
},
{
fsErr: syscall.ENODEV,
expectedCategory: "device errors",
expectedCategory: errDevice,
},
{
fsErr: syscall.EISDIR,
expectedCategory: "file/directory errors",
expectedCategory: errFileDir,
},
{
fsErr: syscall.ENOSYS,
expectedCategory: "function not implemented",
expectedCategory: errNotImplemented,
},
{
fsErr: syscall.ENFILE,
expectedCategory: "too many open files",
expectedCategory: errTooManyFiles,
},
{
fsErr: syscall.EPERM,
expectedCategory: "permission errors",
expectedCategory: errPerm,
},
}

Expand Down

0 comments on commit 697baff

Please sign in to comment.