-
Notifications
You must be signed in to change notification settings - Fork 30
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
Log less #2718
base: master
Are you sure you want to change the base?
Log less #2718
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
fe17e6c
to
dbdb02f
Compare
@@ -236,25 +237,31 @@ func submit( | |||
if err != nil { | |||
return nil, resp, fmt.Errorf("%w: %s", errorutils.ErrFailedBodyRead, err.Error()) | |||
} | |||
sbody := string(body) | |||
for _, p := range []string{`"description":\s*"[^"]+"\s*,?`, `"\w+Country":\s*"[^"]+"\s*,?`} { | |||
re := regexp.MustCompile(p) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: instead of compiling the regex on every call of the method and for each value can we just compile them once and reuse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the readability cost of moving the regex out of here is worse than the performance cost of recompiling it. This call flow spends most of its time waiting for i/o and regex compilation time will be negligible.
@@ -236,25 +237,31 @@ func submit( | |||
if err != nil { | |||
return nil, resp, fmt.Errorf("%w: %s", errorutils.ErrFailedBodyRead, err.Error()) | |||
} | |||
sbody := string(body) | |||
for _, p := range []string{`"description":\s*"[^"]+"\s*,?`, `"\w+Country":\s*"[^"]+"\s*,?`} { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: could we extract this block into a function so we can test it
func redactData(body string) string {
d := description.ReplaceAllString(body, "")
c := country.ReplaceAllString(d, "")
return strings.ReplaceAll(c, ",}", "}")
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Done.
re := regexp.MustCompile(p) | ||
sbody = re.ReplaceAllString(sbody, "") | ||
} | ||
sbody = regexp.MustCompile(`,}`).ReplaceAllString(sbody, "}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: could we use strings.ReplaceAll(c, ",}", "}")
here
@@ -236,25 +237,31 @@ func submit( | |||
if err != nil { | |||
return nil, resp, fmt.Errorf("%w: %s", errorutils.ErrFailedBodyRead, err.Error()) | |||
} | |||
sbody := string(body) | |||
for _, p := range []string{`"description":\s*"[^"]+"\s*,?`, `"\w+Country":\s*"[^"]+"\s*,?`} { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: do we have an example of the response we are trying to redact this from?
we could add an example response to a test, I wonder if we can use an or instead of having two separate passes or the regex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a test with an example object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with comment.
sbody = re.ReplaceAllString(sbody, "") | ||
} | ||
sbody = strings.ReplaceAll(sbody, ",}", "}") | ||
return sbody |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: return strings.ReplaceAll(sbody, ",}", "}")
@@ -1180,3 +1182,12 @@ func FundWallet(ctx context.Context, destWallet *Wallet, amount decimal.Decimal) | |||
|
|||
return balance.TotalProbi, nil | |||
} | |||
|
|||
func redactUnneededContent(sbody string) string { | |||
for _, p := range []string{`"description":\s*"[^"]+"\s*,?`, `"\w+Country":\s*"[^"]+"\s*,?`} { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary
Log less
Type of Change
Tested Environments
Before Requesting Review
Manual Test Plan