Log disk not found error just once (#6059)

Modified the LogIf function to log only if the error passed
is not on the ignored errors list.

Currently, only disk not found error is added to the list.
Added a new function in logger package called LogAlwaysIf, 
which will print on any error.

Fixes #5997
This commit is contained in:
kannappanr 2018-08-14 13:58:48 -07:00 committed by Harshavardhana
parent ff29aed05d
commit 0286e61aee
7 changed files with 29 additions and 13 deletions

View File

@ -47,6 +47,11 @@ const (
const loggerTimeFormat string = "15:04:05 MST 01/02/2006"
// List of error strings to be ignored by LogIf
const (
diskNotFoundError = "disk not found"
)
var matchingFuncNames = [...]string{
"http.HandlerFunc.ServeHTTP",
"cmd.serverMain",
@ -267,17 +272,36 @@ func getTrace(traceLevel int) []string {
return trace
}
// LogIf prints a detailed error message during
// LogAlwaysIf prints a detailed error message during
// the execution of the server.
func LogIf(ctx context.Context, err error) {
if Disable {
func LogAlwaysIf(ctx context.Context, err error) {
if err == nil {
return
}
logIf(ctx, err)
}
// LogIf prints a detailed error message during
// the execution of the server, if it is not an
// ignored error.
func LogIf(ctx context.Context, err error) {
if err == nil {
return
}
if err.Error() != diskNotFoundError {
logIf(ctx, err)
}
}
// logIf prints a detailed error message during
// the execution of the server.
func logIf(ctx context.Context, err error) {
if Disable {
return
}
req := GetReqInfo(ctx)
if req == nil {

View File

@ -36,14 +36,14 @@ var printEndpointError = func() func(Endpoint, error) {
m = make(map[string]bool)
m[err.Error()] = true
printOnce[endpoint] = m
logger.LogIf(ctx, err)
logger.LogAlwaysIf(ctx, err)
return
}
if m[err.Error()] {
return
}
m[err.Error()] = true
logger.LogIf(ctx, err)
logger.LogAlwaysIf(ctx, err)
}
}()

View File

@ -50,7 +50,6 @@ func (xl xlObjects) MakeBucketWithLocation(ctx context.Context, bucket, location
// Make a volume entry on all underlying storage disks.
for index, disk := range xl.getDisks() {
if disk == nil {
logger.LogIf(ctx, errDiskNotFound)
dErrs[index] = errDiskNotFound
continue
}
@ -234,7 +233,6 @@ func (xl xlObjects) DeleteBucket(ctx context.Context, bucket string) error {
// Remove a volume entry on all underlying storage disks.
for index, disk := range xl.getDisks() {
if disk == nil {
logger.LogIf(ctx, errDiskNotFound)
dErrs[index] = errDiskNotFound
continue
}

View File

@ -108,7 +108,6 @@ func healBucket(ctx context.Context, storageDisks []StorageAPI, bucket string, w
// Make a volume entry on all underlying storage disks.
for index, disk := range storageDisks {
if disk == nil {
logger.LogIf(ctx, errDiskNotFound)
dErrs[index] = errDiskNotFound
beforeState[index] = madmin.DriveStateOffline
afterState[index] = madmin.DriveStateOffline

View File

@ -428,7 +428,6 @@ func writeUniqueXLMetadata(ctx context.Context, disks []StorageAPI, bucket, pref
// Start writing `xl.json` to all disks in parallel.
for index, disk := range disks {
if disk == nil {
logger.LogIf(ctx, errDiskNotFound)
mErrs[index] = errDiskNotFound
continue
}
@ -467,7 +466,6 @@ func writeSameXLMetadata(ctx context.Context, disks []StorageAPI, bucket, prefix
// Start writing `xl.json` to all disks in parallel.
for index, disk := range disks {
if disk == nil {
logger.LogIf(ctx, errDiskNotFound)
mErrs[index] = errDiskNotFound
continue
}

View File

@ -103,7 +103,6 @@ func commitXLMetadata(ctx context.Context, disks []StorageAPI, srcBucket, srcPre
// Rename `xl.json` to all disks in parallel.
for index, disk := range disks {
if disk == nil {
logger.LogIf(ctx, errDiskNotFound)
mErrs[index] = errDiskNotFound
continue
}
@ -791,7 +790,6 @@ func (xl xlObjects) cleanupUploadedParts(ctx context.Context, uploadIDPath strin
// Cleanup uploadID for all disks.
for index, disk := range xl.getDisks() {
if disk == nil {
logger.LogIf(ctx, errDiskNotFound)
errs[index] = errDiskNotFound
continue
}

View File

@ -807,7 +807,6 @@ func (xl xlObjects) deleteObject(ctx context.Context, bucket, object string) err
for index, disk := range xl.getDisks() {
if disk == nil {
logger.LogIf(ctx, errDiskNotFound)
dErrs[index] = errDiskNotFound
continue
}