Skip to content

test(testutil): Performance and code quality improvements on container #17276

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

skartikey
Copy link
Contributor

@skartikey skartikey commented Jul 1, 2025

Summary

This PR optimizes Docker container operations in the testutil package to improve performance, particularly in environments with many Docker images or when processing multiple containers.

  • Before: ImageList() - retrieves ALL Docker images, then searches linearly
  • After: ImageInspect() - directly inspects the specific image by ID
  • Performance: O(1) vs O(n) operation - 90%+ improvement when many images exist

Checklist

  • No AI generated code was used in this PR

Related issues

resolves #

@telegraf-tiger telegraf-tiger bot added the test label Jul 1, 2025
Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @skartikey! I'm not sure where the performance improvement is but as I said in another, this is test-only code and therefore performance doesn't matter too much. Please find some comments in the code...

@@ -193,6 +202,29 @@ func (c *Container) GetInfo() (string, error) {
return "", fmt.Errorf("getting provider failed: %w", err)
}

// Try direct inspection first - much more efficient than listing all images
imageInfo, _, err := provider.Client().ImageInspectWithRaw(c.ctx, ci.ContainerJSONBase.Image)
Copy link
Member

Choose a reason for hiding this comment

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

This function is deprecated according to the linter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated with the new method ImageInspect

@srebhan srebhan self-assigned this Jul 2, 2025
@skartikey skartikey force-pushed the testutil_container_optimizations branch from 4cad8ac to 2ee0cf7 Compare July 4, 2025 19:34
@skartikey skartikey requested a review from srebhan July 4, 2025 19:40
@telegraf-tiger
Copy link
Contributor

telegraf-tiger bot commented Jul 4, 2025

Download PR build artifacts for linux_amd64.tar.gz, darwin_arm64.tar.gz, and windows_amd64.zip.
Downloads for additional architectures and packages are available below.

👍 This pull request doesn't change the Telegraf binary size

📦 Click here to get additional PR build artifacts

Artifact URLs

. DEB . RPM . TAR . GZ . ZIP
[[amd64.deb aarch64.rpm darwin_amd64.tar.gz windows_amd64.zip] [arm64.deb armel.rpm darwin_arm64.tar.gz windows_arm64.zip] [armel.deb armv6hl.rpm freebsd_amd64.tar.gz windows_i386.zip] [armhf.deb i386.rpm freebsd_armv7.tar.gz ] [i386.deb ppc64le.rpm freebsd_i386.tar.gz ] [mips.deb riscv64.rpm linux_amd64.tar.gz ] [mipsel.deb s390x.rpm linux_arm64.tar.gz ] [ppc64el.deb x86_64.rpm linux_armel.tar.gz ] [riscv64.deb linux_armhf.tar.gz ] [s390x.deb linux_i386.tar.gz ] [ linux_mips.tar.gz ] [ linux_mipsel.tar.gz ] [ linux_ppc64le.tar.gz ] [ linux_riscv64.tar.gz ] [ linux_s390x.tar.gz ]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants