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

WIP: PoC Container Stats #1885

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pablochacin
Copy link
Contributor

@pablochacin pablochacin commented Nov 2, 2023

What does this PR do?

This PR is a proof of concept for gathering resource consumption stats for a container.

This is a WIP. The intention is to show the general approach and highlight some issues that need to be addressed.

Open Issues:

  • The new function was added to the Docker provider because adding it to the Container interface would break other implementations of the interface such as the reaperContainer
  • Calculating the CPU percentage requires two samples of the stats. Currently, this is implemented by issuing two requests separate by a hardcoded waiting time of 1s.
    One alternative implementation could be passing the previous sample to the stats call. If it is nil, the instantaneous stats will be returned (with the CPU% as 0)
 base := provider.Stats(containerId, nil)     // returns CPU percentage = 0
 // execute test
 stats := provider.Stats(containerId, base)  // returns CPU percentage
  • Testing the new feature is challenging. A container's resource consumption varies depending on many factors. Therefore, the statistics retrieved from a container cannot just be compared with an expected value.

  • This code has not yet been tested for Windows

Why is it important?

In some use cases, it would be convenient to have access to the container's stats to measure the resource (memory, CPU) consumption to detect regressions or establish a comparison between alternative implementations or configurations.

Related issues

How to test this PR

In its current form, the suggested way to test is by looking at the CPU stats and see if vales are "reasonable" .
Automating tests is an ongoing effort.

Follow-ups

Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
Copy link

netlify bot commented Nov 2, 2023

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 354f604
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/6543679ea44c9b000849e5cb
😎 Deploy Preview https://deploy-preview-1885--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.

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.

[Feature]: Expose containers stats
1 participant