Skip to content

Commit

Permalink
feat: tries to use swarm node id if exists then machine-id (#3097)
Browse files Browse the repository at this point in the history
  • Loading branch information
amir20 authored Jul 11, 2024
1 parent 8277902 commit c5771fa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/docker.swarm.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
dozzle:
image: amir20/dozzle:agent
image: amir20/dozzle:pr-3097
environment:
- DOZZLE_LEVEL=debug
- DOZZLE_MODE=swarm
Expand Down
20 changes: 13 additions & 7 deletions internal/docker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,19 @@ func NewClient(cli DockerCLI, filters filters.Args, host Host) Client {
filters: filters,
host: host,
}
var err error
client.info, err = cli.Info(context.Background())
if err != nil {
log.Errorf("unable to get docker info: %v", err)
}

if host.MemTotal == 0 || host.NCPU == 0 {
var err error
client.info, err = cli.Info(context.Background())
if err != nil {
log.Errorf("unable to get docker info: %v", err)
}

host.NCPU = client.info.NCPU
host.MemTotal = client.info.MemTotal
}

log.Debugf("Creating a client with host: %+v", host)

return client
}

Expand All @@ -124,8 +125,13 @@ func NewLocalClient(f map[string][]string, hostname string) (Client, error) {
return nil, err
}

id := info.ID
if info.Swarm.NodeID != "" {
id = info.Swarm.NodeID
}

host := Host{
ID: info.ID,
ID: id,
Name: info.Name,
MemTotal: info.MemTotal,
NCPU: info.NCPU,
Expand Down
2 changes: 1 addition & 1 deletion internal/support/docker/multi_host_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func NewSwarmService(localClient docker.Client, certificates tls.Certificate) *M
}

func closeAgent(agent *agent.Client) {
log.Debugf("closing agent %s", agent.Host().ID)
log.Tracef("closing agent %s", agent.Host())
if err := agent.Close(); err != nil {
log.Warnf("error closing agent: %v", err)
}
Expand Down

0 comments on commit c5771fa

Please sign in to comment.