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

Log less #2718

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Log less #2718

wants to merge 4 commits into from

Conversation

Sneagan
Copy link
Contributor

@Sneagan Sneagan commented Nov 20, 2024

Summary

Log less

Type of Change

  • Product feature
  • Bug fix
  • Performance improvement
  • Refactor
  • Other

Tested Environments

  • Development
  • Staging
  • Production

Before Requesting Review

  • Does your code build cleanly without any errors or warnings?
  • Have you used auto closing keywords?
  • Have you added tests for new functionality?
  • Have validated query efficiency for new database queries?
  • Have documented new functionality in README or in comments?
  • Have you squashed all intermediate commits?
  • Is there a clear title that explains what the PR does?
  • Have you used intuitive function, variable and other naming?
  • Have you requested security and/or privacy review if needed
  • Have you performed a self review of this PR?

Manual Test Plan

@Sneagan Sneagan requested review from kdenhartog and clD11 November 20, 2024 19:44
Copy link
Member

@kdenhartog kdenhartog left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -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)
Copy link
Contributor

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

Copy link
Contributor Author

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*,?`} {
Copy link
Contributor

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, ",}", "}")
}

Copy link
Contributor Author

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, "}")
Copy link
Contributor

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*,?`} {
Copy link
Contributor

@clD11 clD11 Nov 22, 2024

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

Copy link
Contributor Author

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.

Copy link
Contributor

@clD11 clD11 left a 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
Copy link
Contributor

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*,?`} {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: I would not advocate using globals but we are already do it in that package for regex here and vars here. Calling must which can potentially panic on every request plus the overhead seems unnecessary. In the loop we are also copying every time rather than indexing the value.

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.

3 participants