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

Eliminate redundant getContainers/inspectContainer calls #1350

Merged
merged 5 commits into from
Jul 13, 2023

Conversation

martinpitt
Copy link
Member

Both the initial container scan and each update called getContainers() once and inspectContainer() twice (!!). But this is very redundant: The objects returned by getContainers() and inspectContainer() have a very similar structure. The latter does not have Pid and PodName, but we don't use these properties anyway. The others map in a straightforward way:

  • Names[] → single Name
  • Ports list → NetworkSettings.Ports map
  • Mounts (simple target dir list) → list of objects with lots of info; direct translation is .Destination
  • Started/Exited...AtState.*
  • StateState.Status
  • CommandConfig.Cmd
  • LabelsConfig.Labels
  • ImageIDImage
  • ImageImageName

So change the state keeping to call getContainers() only once at initialization, and from then on only a single inspectContainer() for each state update. Adjust the code for the above property structure changes.


Another big outcome from #1324, and stress-tested there.

@martinpitt martinpitt mentioned this pull request Jul 12, 2023
@martinpitt martinpitt requested a review from marusak July 12, 2023 16:12
);
const items = [];
Object.entries(ports).forEach(([containerPort, hostBindings]) => {
hostBindings.forEach(binding => {
Copy link
Member

Choose a reason for hiding this comment

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

I managed to get error:

Uncaught TypeError: hostBindings is null
    renderContainerPublishedPorts ContainerIntegration.jsx:20
    renderContainerPublishedPorts ContainerIntegration.jsx:19
    ContainerIntegration ContainerIntegration.jsx:97
    React 11

These are my ports:

               "Ports": {
                    "3400/tcp": null,
                    "8080/tcp": [
                         {
                              "HostIp": "",
                              "HostPort": "3404"
                         }
                    ]
               },

I am actually not sure how I created this 🤷‍♂️

Copy link
Member Author

Choose a reason for hiding this comment

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

Eww -- Not sure either, but let's not crash the UI on it. Fixed.

marusak
marusak previously approved these changes Jul 12, 2023
Copy link
Member

@marusak marusak left a comment

Choose a reason for hiding this comment

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

Nice cleanup! I managed to get oops - maybe just some broken container on my side

Both the initial container scan and each update called getContainers()
once and inspectContainer() twice (!!). But this is very redundant: The
objects returned by getContainers() and inspectContainer() have a very
similar structure. The latter does not have `Pid` and `PodName`, but we
don't use these properties anyway. The others map in a straightforward
way:

 * `Names[]` → single `Name`
 * `Ports` list → `NetworkSettings.Ports` map
 * `Mounts` (simple target dir list) →  list of objects with lots of
    info; direct translation is `.Destination`
 * `Started/Exited...At` → `State.*`
 * `State` → `State.Status`
 * `Command` → `Config.Cmd`
 * `Labels` → `Config.Labels`
 * `ImageID` → `Image`
 * `Image` → `ImageName`

So change the state keeping to call getContainers() only once at
initialization, and from then on only a single inspectContainer() for
each state update. Adjust the code for the above property structure
changes.
The function already handles falsy values, and other places also call it
unguarded. This fixes some Coverage complaints.
These cannot be triggered at will from the UI, as it already prevents
actions which won't work.

This reduces the coverage report noise.
image.Env ought to always exist. Fixes a coverage complaint.
@martinpitt
Copy link
Member Author

martinpitt commented Jul 13, 2023

I also took the opportunity to clean up the coverage report. As I touch so much code here, I got a ton of uncovered code complaints.

Update: Hmm -- that link is gone now, apparently each force-push completely deletes and replaces the previous version. Good for reducing the noise in a PR of course, but bad for proving that the proposed changes are necessary..

These only apply to old podman versions (where we don't run coverage),
are "play it safe" fallbacks which Should Not Happen™, or are
transient "Loading..." states which cannot reliably be caught in tests.
@martinpitt martinpitt requested a review from marusak July 13, 2023 05:39
Copy link
Member

@marusak marusak left a comment

Choose a reason for hiding this comment

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

Danke!

@martinpitt martinpitt merged commit 9716042 into cockpit-project:main Jul 13, 2023
@martinpitt martinpitt deleted the api-rework branch July 13, 2023 05:59
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.

2 participants