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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/compose/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
"github.com/docker/docker/api/types/network"

"golang.org/x/exp/maps"

logrus "github.com/sirupsen/logrus"
)

func (s *composeService) Generate(ctx context.Context, options api.GenerateOptions) (*types.Project, error) {
Expand Down Expand Up @@ -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)
``

networkConfigs[name] = types.NetworkConfig{}
} else {
networkConfigs[name] = types.NetworkConfig{
Expand Down