Skip to content
This repository was archived by the owner on Jul 7, 2020. It is now read-only.

Remove monitored container causes 404 error #14

Open
ualex73 opened this issue Aug 17, 2019 · 6 comments
Open

Remove monitored container causes 404 error #14

ualex73 opened this issue Aug 17, 2019 · 6 comments

Comments

@ualex73
Copy link
Collaborator

ualex73 commented Aug 17, 2019

If a monitored container is removed with e.g. "docker rm", stats will not work properly.

The logging says:
2019-08-17 06:59:13 INFO (DockerContainerStats) [custom_components.docker_monitor.helpers] Stats runner
2019-08-17 06:59:13 INFO (DockerContainerStats) [custom_components.docker_monitor.helpers] Cannot get get container
2019-08-17 06:59:13 DEBUG (DockerContainerStats) [custom_components.docker_monitor.helpers] Request exception: 404 Client Error: Not Found ("No such container: ssh")
2019-08-17 06:59:13 INFO (DockerContainerStats) [custom_components.docker_monitor.helpers] Cannot get docker container
2019-08-17 06:59:13 DEBUG (DockerContainerStats) [custom_components.docker_monitor.helpers] Request exception: Cannot request container info

I know it is self inflicted, but we should try to handle it nicer ;-)

@Sanderhuisman
Copy link
Owner

Sanderhuisman commented Aug 17, 2019

I will look in this one, I think it is already handled well, but this is the logging output when this case happens.

Edit;
in the helpers file line 303-305 (latest version of develop branch)

            except Exception as ex:
                _LOGGER.info("Cannot get docker container")
                _LOGGER.debug("Request exception: {}".format(ex))

@ualex73
Copy link
Collaborator Author

ualex73 commented Aug 17, 2019

I enabled a backtrace, and the code which gives it is the following one:

    def _reload_container(self):
        try:
            if not self._container:
                self._container = self._client.containers.get(self._name)
            self._container.reload()
        except Exception as ex:
            self._container = None
            _LOGGER.info("Cannot get get container")
            _LOGGER.debug("Request exception: {}".format(ex))
            raise ConnectionError("Cannot request container info")

The "raise" gives it back to the caller, so the following for-loop ends too:

for name, container in self._api._containers.items():

@Sanderhuisman
Copy link
Owner

Ah I see, I made a fix in pull request #15

@ualex73
Copy link
Collaborator Author

ualex73 commented Aug 17, 2019

The "exc_info=True" in the _LOGGER.xxx('...', exc_info=True) was handy here ... Could be handy thing for troubleshooting, if we add it in real error scenarios (which normally shouldn't happen)

@Sanderhuisman
Copy link
Owner

True, but it will spam the log file. With the current trace it is possible to trace the location and extra traces if necessary ;)

You are keeping me busy! 😜

@ualex73
Copy link
Collaborator Author

ualex73 commented Aug 17, 2019

Isn't the plan, but happy to help to make it more robust 👍

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

No branches or pull requests

2 participants