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

Add exception details to the toComposeNetwork log. #12271

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

shencangsheng
Copy link

Description

When creating a compose, the latest version still frequently encounters issues where containers cannot join the network. #11601

Issue

I found in the source code that when there is an exception during network allocation, an empty network is assigned directly without logging.

Proposal

I would like to add a log message in this case to help identify and resolve the issue.

@@ -222,6 +224,7 @@ func (s *composeService) toComposeNetwork(networks map[string]*network.EndpointS
for name, net := range networks {
inspect, err := s.apiClient().NetworkInspect(context.Background(), name, network.InspectOptions{})
if err != nil {
logrus.Warnf("Failed to inspect network %s: %v", name, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO would be legitimate to just return err
As inspected container which we guess network from exists, not being able to inspect network should just demonstrate and API call or engine failure

Copy link
Author

@shencangsheng shencangsheng Nov 8, 2024

Choose a reason for hiding this comment

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

@ndeloof

As described, the containers orchestrated by docker compose up in my production environment have experienced network loss issues more than once. This problem persists even in the latest version and has troubled me for a long time. I have not been able to find any relevant error logs anywhere to pinpoint the issue. Even in the cli, no anomalies are recorded, which is very frustrating for me.

image

Would it be more appropriate to print the logs in the NetworkInspect method of cli?

// NetworkInspect returns the information for a specific network configured in the docker host.
func (cli *Client) NetworkInspect(ctx context.Context, networkID string, options network.InspectOptions) (network.Inspect, error) {
	networkResource, _, err := cli.NetworkInspectWithRaw(ctx, networkID, options)
	if err != nil {
		logrus.Warnf("Failed to inspect network %v", err)
	}
	return networkResource, err
}

Copy link
Contributor

Choose a reason for hiding this comment

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

generate command is not designed to be used as a diagnostic tool! You can wrap engine error to give more context, but I don't expect this will give you more than "not found":

  return fmt.Errorf("failed to inspect network %s: %w", networkID, err)
``

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