From 70428baef36d88e02ca67f0efe3c42221935fbe8 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Mon, 10 Jul 2023 15:30:28 +0200 Subject: [PATCH 1/2] api: fix slow version endpoint This endpoint queried the same package versions twice causing it to be slower than info. Because it already called info we can just reuse the package versions from there. Signed-off-by: Paul Holzinger --- pkg/api/handlers/compat/version.go | 35 ++++++++++-------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/pkg/api/handlers/compat/version.go b/pkg/api/handlers/compat/version.go index 0d34fbd98e..dd64841ac6 100644 --- a/pkg/api/handlers/compat/version.go +++ b/pkg/api/handlers/compat/version.go @@ -13,7 +13,6 @@ import ( "github.com/containers/podman/v4/pkg/domain/entities" "github.com/containers/podman/v4/pkg/domain/entities/types" "github.com/containers/podman/v4/version" - "github.com/sirupsen/logrus" ) func VersionHandler(w http.ResponseWriter, r *http.Request) { @@ -45,30 +44,20 @@ func VersionHandler(w http.ResponseWriter, r *http.Request) { "MinAPIVersion": version.APIVersion[version.Libpod][version.MinimalAPI].String(), "Os": goRuntime.GOOS, }, + }, { + Name: "Conmon", + Version: info.Host.Conmon.Version, + Details: map[string]string{ + "Package": info.Host.Conmon.Package, + }, + }, { + Name: fmt.Sprintf("OCI Runtime (%s)", info.Host.OCIRuntime.Name), + Version: info.Host.OCIRuntime.Version, + Details: map[string]string{ + "Package": info.Host.OCIRuntime.Package, + }, }} - if conmon, oci, err := runtime.DefaultOCIRuntime().RuntimeInfo(); err != nil { - logrus.Warnf("Failed to retrieve Conmon and OCI Information: %q", err.Error()) - } else { - additional := []types.ComponentVersion{ - { - Name: "Conmon", - Version: conmon.Version, - Details: map[string]string{ - "Package": conmon.Package, - }, - }, - { - Name: fmt.Sprintf("OCI Runtime (%s)", oci.Name), - Version: oci.Version, - Details: map[string]string{ - "Package": oci.Package, - }, - }, - } - components = append(components, additional...) - } - apiVersion := version.APIVersion[version.Compat][version.CurrentAPI] minVersion := version.APIVersion[version.Compat][version.MinimalAPI] From 97fd03ccdf89d822e5d06c4801e2475400ea53ec Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Mon, 10 Jul 2023 15:41:16 +0200 Subject: [PATCH 2/2] test/e2e: wait for socket Do not use podman info/version as they are expensive and clutter the log for no reason. Just checking if we can connect to the socket should be good enough and much faster. Fix the non existing error checking, so that we actually see an useful error when this does not work. Also change the interval, why wait 2s for a retry lets take 100ms steps instead. Fixes #19010 Signed-off-by: Paul Holzinger --- test/e2e/common_test.go | 1 - test/e2e/libpod_suite_remote_test.go | 21 +++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go index 8264677a25..1e5913aee9 100644 --- a/test/e2e/common_test.go +++ b/test/e2e/common_test.go @@ -57,7 +57,6 @@ type PodmanTestIntegration struct { CgroupManager string Host HostOS TmpDir string - RemoteStartErr error } var LockTmpDir string diff --git a/test/e2e/libpod_suite_remote_test.go b/test/e2e/libpod_suite_remote_test.go index e328830340..ae7d97c059 100644 --- a/test/e2e/libpod_suite_remote_test.go +++ b/test/e2e/libpod_suite_remote_test.go @@ -6,6 +6,7 @@ package integration import ( "errors" "fmt" + "net" "os" "os/exec" "path/filepath" @@ -94,7 +95,8 @@ func (p *PodmanTestIntegration) StartRemoteService() { command.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} p.RemoteCommand = command p.RemoteSession = command.Process - p.RemoteStartErr = p.DelayForService() + err = p.DelayForService() + Expect(err).ToNot(HaveOccurred()) } func (p *PodmanTestIntegration) StopRemoteService() { @@ -145,16 +147,15 @@ func (p *PodmanTestIntegration) RestoreArtifact(image string) error { } func (p *PodmanTestIntegration) DelayForService() error { - var session *PodmanSessionIntegration - for i := 0; i < 5; i++ { - session = p.Podman([]string{"info"}) - session.WaitWithDefaultTimeout() - if session.ExitCode() == 0 { + var err error + var conn net.Conn + for i := 0; i < 100; i++ { + conn, err = net.Dial("unix", strings.TrimPrefix(p.RemoteSocket, "unix:")) + if err == nil { + conn.Close() return nil - } else if i == 4 { - break } - time.Sleep(2 * time.Second) + time.Sleep(100 * time.Millisecond) } - return fmt.Errorf("service not detected, exit code(%d)", session.ExitCode()) + return fmt.Errorf("service socket not detected, timeout after 10 seconds: %w", err) }