Skip to content
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

Fix key log encoding #682

Merged
merged 4 commits into from
Aug 14, 2020
Merged

Fix key log encoding #682

merged 4 commits into from
Aug 14, 2020

Conversation

aschmahmann
Copy link
Contributor

Fixes #680

This is an attempt at normalizing how we log keys. Suggestions welcome, the main constraints are:

  1. Never log raw bytes
  2. Trying to make parsing logs reasonably easy
  3. Making it easy to see when bad things are happening (e.g. working with empty keys)

Comment on lines +296 to +309

type loggableRawKeyString string

func (lk loggableRawKeyString) String() string {
k := string(lk)

if len(k) == 0 {
return k
}

encStr := base32.RawStdEncoding.EncodeToString([]byte(k))

return encStr
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a little unfortunate that this is here. It didn't seem worth it to make a logging subpackage, but I'm willing to budge here.

if err == nil {
return newKey
}
return err.Error()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously we always returned the key whenever there was an error (e.g. empty string, invalid path, etc.) now we return error messages.

@@ -128,7 +128,7 @@ func (dht *IpfsDHT) GetValue(ctx context.Context, key string, opts ...routing.Op
if best == nil {
return nil, routing.ErrNotFound
}
logger.Debugf("GetValue %v %v", key, best)
logger.Debugf("GetValue %v %x", loggableRecordKeyString(key), best)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is, AFAICT, the only place we log record values. We now use hex encoding.

logging.go Outdated Show resolved Hide resolved
logging.go Outdated Show resolved Hide resolved
logging.go Outdated Show resolved Hide resolved
Copy link
Contributor

@petar petar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

return strings.ToLower(base32.RawStdEncoding.EncodeToString(k))
}

func tryFormatLoggableRecordKey(k string) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe tryParseAndFormat...

logging.go Outdated Show resolved Hide resolved
@petar petar merged commit 0e93285 into master Aug 14, 2020
@petar petar deleted the fix/key-log-encoding branch August 14, 2020 16:45
@aschmahmann aschmahmann mentioned this pull request Sep 22, 2020
72 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Directly logging key strings breaks terminal emulation
2 participants