99 "github.com/amir20/dozzle/internal/agent"
1010 "github.com/amir20/dozzle/internal/docker"
1111 "github.com/puzpuzpuz/xsync/v3"
12+ lop "github.com/samber/lo/parallel"
1213
1314 log "github.com/sirupsen/logrus"
1415)
@@ -26,24 +27,39 @@ func NewRetriableClientManager(agents []string, certs tls.Certificate, clients .
2627
2728 clientMap := make (map [string ]ClientService )
2829 for _ , client := range clients {
29- if _ , ok := clientMap [client .Host ().ID ]; ok {
30- log .Warnf ("duplicate client found for host %s" , client .Host ().ID )
30+ host , err := client .Host ()
31+ if err != nil {
32+ log .Warnf ("error fetching host info for client %s: %v" , host .ID , err )
33+ continue
34+ }
35+
36+ if _ , ok := clientMap [host .ID ]; ok {
37+ log .Warnf ("duplicate client found for host %s" , host .ID )
3138 } else {
32- clientMap [client . Host () .ID ] = client
39+ clientMap [host .ID ] = client
3340 }
3441 }
3542
3643 failed := make ([]string , 0 )
3744 for _ , endpoint := range agents {
38- if agent , err := agent .NewClient (endpoint , certs ); err == nil {
39- if _ , ok := clientMap [agent .Host ().ID ]; ok {
40- log .Warnf ("duplicate client found for host %s" , agent .Host ().ID )
41- } else {
42- clientMap [agent .Host ().ID ] = NewAgentService (agent )
43- }
44- } else {
45+ agent , err := agent .NewClient (endpoint , certs )
46+ if err != nil {
4547 log .Warnf ("error creating agent client for %s: %v" , endpoint , err )
4648 failed = append (failed , endpoint )
49+ continue
50+ }
51+
52+ host , err := agent .Host ()
53+ if err != nil {
54+ log .Warnf ("error fetching host info for agent %s: %v" , endpoint , err )
55+ failed = append (failed , endpoint )
56+ continue
57+ }
58+
59+ if _ , ok := clientMap [host .ID ]; ok {
60+ log .Warnf ("duplicate client found for host %s" , host .ID )
61+ } else {
62+ clientMap [host .ID ] = NewAgentService (agent )
4763 }
4864 }
4965
@@ -70,29 +86,36 @@ func (m *RetriableClientManager) RetryAndList() ([]ClientService, []error) {
7086 if len (m .failedAgents ) > 0 {
7187 newFailed := make ([]string , 0 )
7288 for _ , endpoint := range m .failedAgents {
73- if agent , err := agent .NewClient (endpoint , m .certs ); err == nil {
74- m .clients [agent .Host ().ID ] = NewAgentService (agent )
75-
76- m .subscribers .Range (func (ctx context.Context , channel chan <- docker.Host ) bool {
77- host := agent .Host ()
78- host .Available = true
79-
80- // We don't want to block the subscribers in event.go
81- go func () {
82- select {
83- case channel <- host :
84- case <- ctx .Done ():
85- }
86- }()
87-
88- return true
89- })
90-
91- } else {
89+ agent , err := agent .NewClient (endpoint , m .certs )
90+ if err != nil {
9291 log .Warnf ("error creating agent client for %s: %v" , endpoint , err )
9392 errors = append (errors , err )
9493 newFailed = append (newFailed , endpoint )
94+ continue
9595 }
96+
97+ host , err := agent .Host ()
98+ if err != nil {
99+ log .Warnf ("error fetching host info for agent %s: %v" , endpoint , err )
100+ errors = append (errors , err )
101+ newFailed = append (newFailed , endpoint )
102+ continue
103+ }
104+
105+ m .clients [host .ID ] = NewAgentService (agent )
106+ m .subscribers .Range (func (ctx context.Context , channel chan <- docker.Host ) bool {
107+ host .Available = true
108+
109+ // We don't want to block the subscribers in event.go
110+ go func () {
111+ select {
112+ case channel <- host :
113+ case <- ctx .Done ():
114+ }
115+ }()
116+
117+ return true
118+ })
96119 }
97120 m .failedAgents = newFailed
98121 }
@@ -128,12 +151,17 @@ func (m *RetriableClientManager) String() string {
128151func (m * RetriableClientManager ) Hosts () []docker.Host {
129152 clients := m .List ()
130153
131- hosts := make ([]docker.Host , 0 , len (clients ))
132- for _ , client := range clients {
133- host := client .Host ()
134- host .Available = true
135- hosts = append (hosts , host )
136- }
154+ hosts := lop .Map (clients , func (client ClientService , _ int ) docker.Host {
155+ host , err := client .Host ()
156+ log .Debugf ("host: %v, err: %v" , host , err )
157+ if err != nil {
158+ host .Available = false
159+ } else {
160+ host .Available = true
161+ }
162+
163+ return host
164+ })
137165
138166 for _ , endpoint := range m .failedAgents {
139167 hosts = append (hosts , docker.Host {
0 commit comments