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

core: Improve SEP-1, SEP-10 logging #262

Merged
merged 3 commits into from May 19, 2022
Merged

Conversation

lijamie98
Copy link
Collaborator

@lijamie98 lijamie98 commented May 17, 2022

PR Checklist

PR Structure

  • This PR has reasonably narrow scope (if not, break it down into smaller PRs).
  • This PR avoids mixing refactoring changes with feature changes (split into two PRs
    otherwise).
  • This PR's title starts with name of package that is most changed in the PR, ex.
    paymentservice.stellar, or all or doc if the changes are broad or impact many
    packages.

Thoroughness

  • This PR adds tests for the most critical parts of the new functionality or fixes.

What

Improve the logging of SEP-1 and SEP-10

Why

N/A

Known limitations

N/A

@lijamie98 lijamie98 self-assigned this May 17, 2022
@lijamie98 lijamie98 changed the title Enrich logging [WIP] all: Enrich logging May 17, 2022
@lijamie98 lijamie98 marked this pull request as draft May 17, 2022 15:20
@stellar-jenkins
Copy link

Reference Server Preview is available here:
https://anchor-ref-pr262.previews.kube001.services.stellar-ops.com/
SEP Server Preview is available here:
https://anchor-sep-pr262.previews.kube001.services.stellar-ops.com/

1 similar comment
@stellar-jenkins
Copy link

Reference Server Preview is available here:
https://anchor-ref-pr262.previews.kube001.services.stellar-ops.com/
SEP Server Preview is available here:
https://anchor-sep-pr262.previews.kube001.services.stellar-ops.com/

@lijamie98 lijamie98 force-pushed the 2022-05-17-enrich-logging branch 2 times, most recently from 646a4e3 to b4833d3 Compare May 18, 2022 15:13
@lijamie98 lijamie98 changed the title [WIP] all: Enrich logging Improve SEP-1, SEP-10 logging May 18, 2022
@lijamie98 lijamie98 marked this pull request as ready for review May 18, 2022 15:14
@stellar-jenkins
Copy link

Reference Server Preview is available here:
https://anchor-ref-pr262.previews.kube001.services.stellar-ops.com/
SEP Server Preview is available here:
https://anchor-sep-pr262.previews.kube001.services.stellar-ops.com/

@stellar-jenkins
Copy link

Reference Server Preview is available here:
https://anchor-ref-pr262.previews.kube001.services.stellar-ops.com/
SEP Server Preview is available here:
https://anchor-sep-pr262.previews.kube001.services.stellar-ops.com/

@lijamie98 lijamie98 changed the title Improve SEP-1, SEP-10 logging core: Improve SEP-1, SEP-10 logging May 18, 2022
@stellar-jenkins
Copy link

Reference Server Preview is available here:
https://anchor-ref-pr262.previews.kube001.services.stellar-ops.com/
SEP Server Preview is available here:
https://anchor-sep-pr262.previews.kube001.services.stellar-ops.com/

Copy link
Contributor

@marcelosalloum marcelosalloum left a comment

Choose a reason for hiding this comment

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

LGTM! I've left a few suggestions below ⬇️

core/src/main/java/org/stellar/anchor/util/Log.java Outdated Show resolved Hide resolved
@@ -31,10 +33,16 @@ public Sep1Service(Sep1Config sep1Config, ResourceReader resourceReader) {
}

public String getStellarToml() throws IOException, SepNotFoundException {
infoF("reading SEP1 TOML: {}", sep1Config.getStellarFile());
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can remove this log because it'll be repeated below.

Suggested change
infoF("reading SEP1 TOML: {}", sep1Config.getStellarFile());

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I felt a little debating here. One is for info logging and the other provides more details of how the TOML file is read in debug log.

In production, we will only see one entry. But in test or debug sessions, we will be able to see debug and info logs.

Comment on lines +57 to 67
infoF("Bad home_domain: {}", challengeRequest.getHomeDomain());
throw new SepValidationException(
String.format("home_domain [%s] is not supported.", challengeRequest.getHomeDomain()));
}

if (sep10Config.isClientAttributionRequired()) {
if (challengeRequest.getClientDomain() == null) {
infoF("ALERT: client domain required and not provided");
info("client_domain is required but not provided");
throw new SepValidationException("client_domain is required");
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Please allow me to discuss a concept here: I'd prefer to use error, rather than info logs when we're inside a catch, WDYT?

Comment on lines 80 to 89
@Test
fun testInfoBPII() {
val slot = slot<String>()
every { logger.info(capture(slot)) } answers {}

val testBeanPII = TestBeanPII()
Log.infoB("Hello", testBeanPII)
verify(exactly = 2) { logger.info(ofType(String::class)) }
assertFalse(slot.captured.contains("fieldPII"))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I've noticed the slot is not being used here... according with this link, you could use a list instead of a slot. It would look like this:

Suggested change
@Test
fun testInfoBPII() {
val slot = slot<String>()
every { logger.info(capture(slot)) } answers {}
val testBeanPII = TestBeanPII()
Log.infoB("Hello", testBeanPII)
verify(exactly = 2) { logger.info(ofType(String::class)) }
assertFalse(slot.captured.contains("fieldPII"))
}
@Test
fun testInfoBPII() {
val slotIMessages = mutableListOf<String>()
every { logger.info(capture(slotIMessages)) } answers {}
val testBeanPII = TestBeanPII()
Log.infoB("Hello", testBeanPII)
verify(exactly = 2) { logger.info(ofType(String::class)) }
assertEquals("Hello", slotIMessages[0])
val wantBean = """{
"fieldNoPII": "no secret"
}""".trimMargin()
assertEquals(wantBean, slotIMessages[1])
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍 updated.

@stellar-jenkins
Copy link

Reference Server Preview is available here:
https://anchor-ref-pr262.previews.kube001.services.stellar-ops.com/
SEP Server Preview is available here:
https://anchor-sep-pr262.previews.kube001.services.stellar-ops.com/

@lijamie98 lijamie98 merged commit bbe5b6c into main May 19, 2022
@lijamie98 lijamie98 deleted the 2022-05-17-enrich-logging branch May 19, 2022 10:14
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.

None yet

3 participants