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

feat: honour go toolchain's verbose flag to print out logs #2624

Merged
merged 10 commits into from
Jul 5, 2024

Conversation

mdelapenya
Copy link
Member

@mdelapenya mdelapenya commented Jul 4, 2024

  • chore: disable logging if the "-v" flag is not present
  • chore: print ryuk is disabled using the logger

What does this PR do?

This PR checks if the verbose flags (v or -test.v) are present in the current execution, keeping the default logger if it's passed. Else, a NOOP logger will be used for all the downstream calls.

If a container defines its own logger in the container request struct, it will be honored.

Finally, we are including the library version in the initial banner in case users want to provide logs.

Why is it important?

Control the verbosity using standard Go flags

Related issues

@mdelapenya mdelapenya requested a review from a team as a code owner July 4, 2024 16:22
@mdelapenya mdelapenya added the chore Changes that do not impact the existing functionality label Jul 4, 2024
@mdelapenya mdelapenya self-assigned this Jul 4, 2024
Copy link

netlify bot commented Jul 4, 2024

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 2d13328
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/6688156ce1b79f0008057171
😎 Deploy Preview https://deploy-preview-2624--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

kiview
kiview previously approved these changes Jul 5, 2024
Copy link
Member

@kiview kiview left a comment

Choose a reason for hiding this comment

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

Since we have this logger abstraction, and we discussed it in the context of tc-java, could we also log out the used tc-go version, to help us with debugging based on user logs?

@mdelapenya
Copy link
Member Author

mdelapenya commented Jul 5, 2024

Since we have this logger abstraction, and we discussed it in the context of tc-java, could we also log out the used tc-go version, to help us with debugging based on user logs?

Indeed. I'll add it to the initial banner:

        2024/07/05 10:58:07 github.com/testcontainers/testcontainers-go - Connected to docker: 
          Server Version: 78+testcontainerscloud (via Testcontainers Desktop 1.15.0)
          API Version: 1.43
          Operating System: Ubuntu 20.04 LTS
          Total Memory: 7407 MB
+          Testcontainers Go version: v0.31.0
          Resolved Docker Host: tcp://127.0.0.1:61939
          Resolved Docker Socket Path: /var/run/docker.sock
          Test SessionID: 8cd3a6626cd58d51a66a9da017b40ba50c7130e74ee889f1a38ea4160e6a6f57
          Test ProcessID: 00327949-4162-4994-b191-746e9b44b300

cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1"}
// force verbosity in subprocesses, so that the output is printed
cmd := exec.Command(os.Args[0], "-test.run=TestHelperContainerStarterProcess", "-test.v=true")
cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=1")
Copy link
Member Author

Choose a reason for hiding this comment

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

Having the environment will make this test more reliable, making it possible to run it locally (e.g., HOME var was not set)

@mdelapenya mdelapenya added enhancement New feature or request and removed chore Changes that do not impact the existing functionality labels Jul 5, 2024
@mdelapenya mdelapenya changed the title chore: honour go toolchain's verbose flag to print out logs feat: honour go toolchain's verbose flag to print out logs Jul 5, 2024
@mdelapenya mdelapenya requested a review from kiview July 5, 2024 09:15
@mdelapenya mdelapenya merged commit 80e57e1 into testcontainers:main Jul 5, 2024
108 checks passed
bartsmykla added a commit to bartsmykla/kuma that referenced this pull request Jul 10, 2024
- Add `-v` flag to transparent-proxy test runs:
  In `testcontainers-go` version 0.32.0, logging is disabled by default
  unless the `-v` flag is used. This change enables verbose logging for
  transparent-proxy tests to provide more detailed output, making it
  easier to debug issues such as test timeouts.

- Increase GitHub Action job timeout to 60 minutes:
  Extended the timeout for the transparent-proxy tests GitHub Action job
  to 60 minutes to accommodate longer test runs and prevent premature
  job termination.

- Adjust test schedule:
  Updated the schedule to run these tests 2 hours earlier, ensuring they
  align better with the team's workflow.

ref. testcontainers/testcontainers-go#2624

Signed-off-by: Bart Smykla <[email protected]>
@mdelapenya mdelapenya deleted the verbose-mode branch July 11, 2024 11:48
mdelapenya added a commit that referenced this pull request Jul 15, 2024
* main:
  fix: log output after context timeout (#2643)
  chore(deps): use "github.com/containerd/platforms" instead (#2638)
  chore(deps): bump google.golang.org/grpc to 1.64.1 (#2635)
  chore(deps): bump certifi from 2024.2.2 to 2024.7.4 (#2631)
  chore: prepare for next minor development cycle (0.33.0)
  chore: use new version (v0.32.0) in modules and examples
  feat: honour go toolchain's verbose flag to print out logs (#2624)
  Fix issues in BuildImage() (#2626)
  docs: indicate version for the Run function (#2627)
  chore: remove duplicated tests for config (#2628)
  Log retried errors (#2613)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement]: Reduce verbose log output
2 participants