mirror of
https://github.com/amir20/dozzle.git
synced 2026-01-03 19:45:01 +01:00
chore: uses zerolog instead of logrus (#3203)
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/amir20/dozzle/internal/docker"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type ContainerFilter = func(*docker.Container) bool
|
||||
@@ -36,8 +36,6 @@ func NewMultiHostService(manager ClientManager) *MultiHostService {
|
||||
manager: manager,
|
||||
}
|
||||
|
||||
log.Debugf("created multi host service manager %s", manager)
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
@@ -75,7 +73,7 @@ func (m *MultiHostService) ListAllContainers() ([]docker.Container, []error) {
|
||||
list, err := client.ListContainers()
|
||||
if err != nil {
|
||||
host, _ := client.Host()
|
||||
log.Debugf("error listing containers for host %s: %v", host.ID, err)
|
||||
log.Debug().Err(err).Str("host", host.Name).Msg("error listing containers")
|
||||
host.Available = false
|
||||
errors = append(errors, &HostUnavailableError{Host: host, Err: err})
|
||||
continue
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/puzpuzpuz/xsync/v3"
|
||||
lop "github.com/samber/lo/parallel"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type RetriableClientManager struct {
|
||||
@@ -23,18 +23,16 @@ type RetriableClientManager struct {
|
||||
}
|
||||
|
||||
func NewRetriableClientManager(agents []string, certs tls.Certificate, clients ...ClientService) *RetriableClientManager {
|
||||
log.Debugf("creating retriable client manager with %d clients and %d agents", len(clients), len(agents))
|
||||
|
||||
clientMap := make(map[string]ClientService)
|
||||
for _, client := range clients {
|
||||
host, err := client.Host()
|
||||
if err != nil {
|
||||
log.Warnf("error fetching host info for client %s: %v", host.ID, err)
|
||||
log.Warn().Err(err).Str("host", host.Name).Msg("error fetching host info for client")
|
||||
continue
|
||||
}
|
||||
|
||||
if _, ok := clientMap[host.ID]; ok {
|
||||
log.Warnf("duplicate client found for host %s", host.ID)
|
||||
log.Warn().Str("host", host.Name).Msg("duplicate client found")
|
||||
} else {
|
||||
clientMap[host.ID] = client
|
||||
}
|
||||
@@ -44,20 +42,20 @@ func NewRetriableClientManager(agents []string, certs tls.Certificate, clients .
|
||||
for _, endpoint := range agents {
|
||||
agent, err := agent.NewClient(endpoint, certs)
|
||||
if err != nil {
|
||||
log.Warnf("error creating agent client for %s: %v", endpoint, err)
|
||||
log.Warn().Err(err).Str("endpoint", endpoint).Msg("error creating agent client")
|
||||
failed = append(failed, endpoint)
|
||||
continue
|
||||
}
|
||||
|
||||
host, err := agent.Host()
|
||||
if err != nil {
|
||||
log.Warnf("error fetching host info for agent %s: %v", endpoint, err)
|
||||
log.Warn().Err(err).Str("endpoint", endpoint).Msg("error fetching host info for agent")
|
||||
failed = append(failed, endpoint)
|
||||
continue
|
||||
}
|
||||
|
||||
if _, ok := clientMap[host.ID]; ok {
|
||||
log.Warnf("duplicate client found for host %s", host.ID)
|
||||
log.Warn().Str("host", host.Name).Str("id", host.ID).Msg("duplicate host with same ID found")
|
||||
} else {
|
||||
clientMap[host.ID] = NewAgentService(agent)
|
||||
}
|
||||
@@ -88,7 +86,7 @@ func (m *RetriableClientManager) RetryAndList() ([]ClientService, []error) {
|
||||
for _, endpoint := range m.failedAgents {
|
||||
agent, err := agent.NewClient(endpoint, m.certs)
|
||||
if err != nil {
|
||||
log.Warnf("error creating agent client for %s: %v", endpoint, err)
|
||||
log.Warn().Err(err).Str("endpoint", endpoint).Msg("error creating agent client")
|
||||
errors = append(errors, err)
|
||||
newFailed = append(newFailed, endpoint)
|
||||
continue
|
||||
@@ -96,7 +94,7 @@ func (m *RetriableClientManager) RetryAndList() ([]ClientService, []error) {
|
||||
|
||||
host, err := agent.Host()
|
||||
if err != nil {
|
||||
log.Warnf("error fetching host info for agent %s: %v", endpoint, err)
|
||||
log.Warn().Err(err).Str("endpoint", endpoint).Msg("error fetching host info for agent")
|
||||
errors = append(errors, err)
|
||||
newFailed = append(newFailed, endpoint)
|
||||
continue
|
||||
@@ -153,7 +151,6 @@ func (m *RetriableClientManager) Hosts() []docker.Host {
|
||||
|
||||
hosts := lop.Map(clients, func(client ClientService, _ int) docker.Host {
|
||||
host, err := client.Host()
|
||||
log.Debugf("host: %v, err: %v", host, err)
|
||||
if err != nil {
|
||||
host.Available = false
|
||||
} else {
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
"github.com/samber/lo"
|
||||
lop "github.com/samber/lo/parallel"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type SwarmClientManager struct {
|
||||
@@ -51,17 +51,17 @@ func NewSwarmClientManager(localClient docker.Client, certs tls.Certificate) *Sw
|
||||
|
||||
id, ok := os.LookupEnv("HOSTNAME")
|
||||
if !ok {
|
||||
log.Fatal("HOSTNAME environment variable not set when looking for swarm service name")
|
||||
log.Fatal().Msg("HOSTNAME environment variable not set when looking for swarm service name")
|
||||
}
|
||||
|
||||
container, err := localClient.FindContainer(id)
|
||||
if err != nil {
|
||||
log.Fatalf("error finding container %s: %v", id, err)
|
||||
log.Fatal().Err(err).Msg("error finding own container when looking for swarm service name")
|
||||
}
|
||||
|
||||
serviceName := container.Labels["com.docker.swarm.service.name"]
|
||||
|
||||
log.Debugf("found swarm internal service name: %s", serviceName)
|
||||
log.Debug().Str("service", serviceName).Msg("found swarm service name")
|
||||
|
||||
return &SwarmClientManager{
|
||||
localClient: localClient,
|
||||
@@ -85,12 +85,11 @@ func (m *SwarmClientManager) Subscribe(ctx context.Context, channel chan<- docke
|
||||
func (m *SwarmClientManager) RetryAndList() ([]ClientService, []error) {
|
||||
m.mu.Lock()
|
||||
|
||||
log.Debugf("looking up swarm services: tasks.%s", m.name)
|
||||
ips, err := net.LookupIP(fmt.Sprintf("tasks.%s", m.name))
|
||||
|
||||
errors := make([]error, 0)
|
||||
if err != nil {
|
||||
log.Fatalf("error looking up swarm services: %v", err)
|
||||
log.Fatal().Err(err).Msg("error looking up swarm service tasks")
|
||||
errors = append(errors, err)
|
||||
m.mu.Unlock()
|
||||
return m.List(), errors
|
||||
@@ -102,47 +101,51 @@ func (m *SwarmClientManager) RetryAndList() ([]ClientService, []error) {
|
||||
return host.Endpoint
|
||||
})
|
||||
|
||||
log.Debugf("tasks.dozzle = %v, localIP = %v, clients.endpoints = %v", ips, m.localIPs, lo.Keys(endpoints))
|
||||
ipStrings := lo.Map(ips, func(ip net.IP, _ int) string {
|
||||
return ip.String()
|
||||
})
|
||||
|
||||
log.Debug().Strs(fmt.Sprintf("tasks.%s", m.name), ipStrings).Strs("localIPs", m.localIPs).Strs("clients.endpoints", lo.Keys(endpoints)).Msg("found swarm service tasks")
|
||||
|
||||
for _, ip := range ips {
|
||||
if lo.Contains(m.localIPs, ip.String()) {
|
||||
log.Debugf("skipping local ip %s", ip.String())
|
||||
log.Debug().Stringer("ip", ip).Msg("skipping local IP")
|
||||
continue
|
||||
}
|
||||
|
||||
if _, ok := endpoints[ip.String()+":7007"]; ok {
|
||||
log.Debugf("skipping existing client for %s", ip.String())
|
||||
log.Debug().Stringer("ip", ip).Msg("skipping existing client")
|
||||
continue
|
||||
}
|
||||
|
||||
agent, err := agent.NewClient(ip.String()+":7007", m.certs)
|
||||
if err != nil {
|
||||
log.Warnf("error creating client for %s: %v", ip, err)
|
||||
log.Warn().Err(err).Stringer("ip", ip).Msg("error creating agent client")
|
||||
errors = append(errors, err)
|
||||
continue
|
||||
}
|
||||
|
||||
host, err := agent.Host()
|
||||
if err != nil {
|
||||
log.Warnf("error getting host data for agent %s: %v", ip, err)
|
||||
log.Warn().Err(err).Stringer("ip", ip).Msg("error getting host from agent client")
|
||||
errors = append(errors, err)
|
||||
if err := agent.Close(); err != nil {
|
||||
log.Warnf("error closing local client: %v", err)
|
||||
log.Warn().Err(err).Stringer("ip", ip).Msg("error closing agent client")
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if host.ID == m.localClient.Host().ID {
|
||||
log.Debugf("skipping local client with ID %s", host.ID)
|
||||
log.Debug().Stringer("ip", ip).Msg("skipping local client")
|
||||
if err := agent.Close(); err != nil {
|
||||
log.Warnf("error closing local client: %v", err)
|
||||
log.Warn().Err(err).Stringer("ip", ip).Msg("error closing agent client")
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
client := NewAgentService(agent)
|
||||
m.clients[host.ID] = client
|
||||
log.Infof("added client for %s", host.ID)
|
||||
log.Info().Stringer("ip", ip).Str("id", host.ID).Str("name", host.Name).Msg("added new swarm agent")
|
||||
|
||||
m.subscribers.Range(func(ctx context.Context, channel chan<- docker.Host) bool {
|
||||
host.Available = true
|
||||
|
||||
Reference in New Issue
Block a user