mirror of
https://github.com/amir20/dozzle.git
synced 2025-12-21 13:23:07 +01:00
chore: updates sync package to v4 (#3751)
This commit is contained in:
1
go.mod
1
go.mod
@@ -28,7 +28,6 @@ require (
|
|||||||
github.com/go-chi/chi/v5 v5.2.1
|
github.com/go-chi/chi/v5 v5.2.1
|
||||||
github.com/go-chi/jwtauth/v5 v5.3.3
|
github.com/go-chi/jwtauth/v5 v5.3.3
|
||||||
github.com/gorilla/websocket v1.5.3
|
github.com/gorilla/websocket v1.5.3
|
||||||
github.com/puzpuzpuz/xsync/v3 v3.5.1
|
|
||||||
github.com/puzpuzpuz/xsync/v4 v4.0.0
|
github.com/puzpuzpuz/xsync/v4 v4.0.0
|
||||||
github.com/rs/zerolog v1.34.0
|
github.com/rs/zerolog v1.34.0
|
||||||
github.com/samber/lo v1.49.1
|
github.com/samber/lo v1.49.1
|
||||||
|
|||||||
3
go.sum
3
go.sum
@@ -155,8 +155,7 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
|
|||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
||||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/puzpuzpuz/xsync/v3 v3.5.1 h1:GJYJZwO6IdxN/IKbneznS6yPkVC+c3zyY/j19c++5Fg=
|
github.com/puzpuzpuz/xsync/v4 v4.0.0 h1:F1za+MBXzDQtQq+OVgFsojSX4w66rsNDmQNebPFAncA=
|
||||||
github.com/puzpuzpuz/xsync/v3 v3.5.1/go.mod h1:VjzYrABPabuM4KyBh1Ftq6u8nhwY5tBPKP9jpmh0nnA=
|
|
||||||
github.com/puzpuzpuz/xsync/v4 v4.0.0/go.mod h1:VJDmTCJMBt8igNxnkQd86r+8KUeN1quSfNKu5bLYFQo=
|
github.com/puzpuzpuz/xsync/v4 v4.0.0/go.mod h1:VJDmTCJMBt8igNxnkQd86r+8KUeN1quSfNKu5bLYFQo=
|
||||||
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
||||||
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/puzpuzpuz/xsync/v3"
|
"github.com/puzpuzpuz/xsync/v4"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
"golang.org/x/sync/semaphore"
|
"golang.org/x/sync/semaphore"
|
||||||
@@ -20,9 +20,9 @@ type StatsCollector interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ContainerStore struct {
|
type ContainerStore struct {
|
||||||
containers *xsync.MapOf[string, *Container]
|
containers *xsync.Map[string, *Container]
|
||||||
subscribers *xsync.MapOf[context.Context, chan<- ContainerEvent]
|
subscribers *xsync.Map[context.Context, chan<- ContainerEvent]
|
||||||
newContainerSubscribers *xsync.MapOf[context.Context, chan<- Container]
|
newContainerSubscribers *xsync.Map[context.Context, chan<- Container]
|
||||||
client Client
|
client Client
|
||||||
statsCollector StatsCollector
|
statsCollector StatsCollector
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
@@ -38,10 +38,10 @@ func NewContainerStore(ctx context.Context, client Client, statsCollect StatsCol
|
|||||||
log.Debug().Str("host", client.Host().Name).Interface("labels", labels).Msg("initializing container store")
|
log.Debug().Str("host", client.Host().Name).Interface("labels", labels).Msg("initializing container store")
|
||||||
|
|
||||||
s := &ContainerStore{
|
s := &ContainerStore{
|
||||||
containers: xsync.NewMapOf[string, *Container](),
|
containers: xsync.NewMap[string, *Container](),
|
||||||
client: client,
|
client: client,
|
||||||
subscribers: xsync.NewMapOf[context.Context, chan<- ContainerEvent](),
|
subscribers: xsync.NewMap[context.Context, chan<- ContainerEvent](),
|
||||||
newContainerSubscribers: xsync.NewMapOf[context.Context, chan<- Container](),
|
newContainerSubscribers: xsync.NewMap[context.Context, chan<- Container](),
|
||||||
statsCollector: statsCollect,
|
statsCollector: statsCollect,
|
||||||
wg: sync.WaitGroup{},
|
wg: sync.WaitGroup{},
|
||||||
events: make(chan ContainerEvent),
|
events: make(chan ContainerEvent),
|
||||||
@@ -174,18 +174,18 @@ func (s *ContainerStore) FindContainer(id string, labels ContainerLabels) (Conta
|
|||||||
if container, ok := s.containers.Load(id); ok {
|
if container, ok := s.containers.Load(id); ok {
|
||||||
if !container.FullyLoaded {
|
if !container.FullyLoaded {
|
||||||
log.Debug().Str("id", id).Msg("container is not fully loaded, fetching it")
|
log.Debug().Str("id", id).Msg("container is not fully loaded, fetching it")
|
||||||
if newContainer, ok := s.containers.Compute(id, func(c *Container, loaded bool) (*Container, bool) {
|
if newContainer, ok := s.containers.Compute(id, func(c *Container, loaded bool) (*Container, xsync.ComputeOp) {
|
||||||
if loaded {
|
if loaded {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout)
|
ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
if newContainer, err := s.client.FindContainer(ctx, id); err == nil {
|
if newContainer, err := s.client.FindContainer(ctx, id); err == nil {
|
||||||
return &newContainer, false
|
return &newContainer, xsync.UpdateOp
|
||||||
} else {
|
} else {
|
||||||
log.Error().Err(err).Msg("failed to fetch container")
|
log.Error().Err(err).Msg("failed to fetch container")
|
||||||
return c, false
|
return c, xsync.CancelOp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return c, false
|
return c, xsync.CancelOp
|
||||||
}); ok {
|
}); ok {
|
||||||
go func() {
|
go func() {
|
||||||
event := ContainerEvent{
|
event := ContainerEvent{
|
||||||
@@ -314,7 +314,7 @@ func (s *ContainerStore) init() {
|
|||||||
|
|
||||||
case "update":
|
case "update":
|
||||||
started := false
|
started := false
|
||||||
updatedContainer, _ := s.containers.Compute(event.ActorID, func(c *Container, loaded bool) (*Container, bool) {
|
updatedContainer, _ := s.containers.Compute(event.ActorID, func(c *Container, loaded bool) (*Container, xsync.ComputeOp) {
|
||||||
if loaded {
|
if loaded {
|
||||||
newContainer := event.Container
|
newContainer := event.Container
|
||||||
if newContainer.State == "running" && c.State != "running" {
|
if newContainer.State == "running" && c.State != "running" {
|
||||||
@@ -327,9 +327,9 @@ func (s *ContainerStore) init() {
|
|||||||
c.FinishedAt = newContainer.FinishedAt
|
c.FinishedAt = newContainer.FinishedAt
|
||||||
c.Created = newContainer.Created
|
c.Created = newContainer.Created
|
||||||
c.Host = newContainer.Host
|
c.Host = newContainer.Host
|
||||||
return c, false
|
return c, xsync.UpdateOp
|
||||||
} else {
|
} else {
|
||||||
return c, true
|
return c, xsync.CancelOp
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -349,14 +349,14 @@ func (s *ContainerStore) init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case "die":
|
case "die":
|
||||||
s.containers.Compute(event.ActorID, func(c *Container, loaded bool) (*Container, bool) {
|
s.containers.Compute(event.ActorID, func(c *Container, loaded bool) (*Container, xsync.ComputeOp) {
|
||||||
if loaded {
|
if loaded {
|
||||||
log.Debug().Str("id", c.ID).Msg("container died")
|
log.Debug().Str("id", c.ID).Msg("container died")
|
||||||
c.State = "exited"
|
c.State = "exited"
|
||||||
c.FinishedAt = time.Now()
|
c.FinishedAt = time.Now()
|
||||||
return c, false
|
return c, xsync.UpdateOp
|
||||||
} else {
|
} else {
|
||||||
return c, true
|
return c, xsync.CancelOp
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
case "health_status: healthy", "health_status: unhealthy":
|
case "health_status: healthy", "health_status: unhealthy":
|
||||||
@@ -365,24 +365,24 @@ func (s *ContainerStore) init() {
|
|||||||
healthy = "healthy"
|
healthy = "healthy"
|
||||||
}
|
}
|
||||||
|
|
||||||
s.containers.Compute(event.ActorID, func(c *Container, loaded bool) (*Container, bool) {
|
s.containers.Compute(event.ActorID, func(c *Container, loaded bool) (*Container, xsync.ComputeOp) {
|
||||||
if loaded {
|
if loaded {
|
||||||
log.Debug().Str("id", c.ID).Str("health", healthy).Msg("container health status changed")
|
log.Debug().Str("id", c.ID).Str("health", healthy).Msg("container health status changed")
|
||||||
c.Health = healthy
|
c.Health = healthy
|
||||||
return c, false
|
return c, xsync.UpdateOp
|
||||||
} else {
|
} else {
|
||||||
return c, true
|
return c, xsync.CancelOp
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
case "rename":
|
case "rename":
|
||||||
s.containers.Compute(event.ActorID, func(c *Container, loaded bool) (*Container, bool) {
|
s.containers.Compute(event.ActorID, func(c *Container, loaded bool) (*Container, xsync.ComputeOp) {
|
||||||
if loaded {
|
if loaded {
|
||||||
log.Debug().Str("id", event.ActorID).Str("name", event.ActorAttributes["name"]).Msg("container renamed")
|
log.Debug().Str("id", event.ActorID).Str("name", event.ActorAttributes["name"]).Msg("container renamed")
|
||||||
c.Name = event.ActorAttributes["name"]
|
c.Name = event.ActorAttributes["name"]
|
||||||
return c, false
|
return c, xsync.UpdateOp
|
||||||
} else {
|
} else {
|
||||||
return c, true
|
return c, xsync.CancelOp
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,15 +9,15 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/amir20/dozzle/internal/container"
|
"github.com/amir20/dozzle/internal/container"
|
||||||
"github.com/puzpuzpuz/xsync/v3"
|
"github.com/puzpuzpuz/xsync/v4"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DockerStatsCollector struct {
|
type DockerStatsCollector struct {
|
||||||
stream chan container.ContainerStat
|
stream chan container.ContainerStat
|
||||||
subscribers *xsync.MapOf[context.Context, chan<- container.ContainerStat]
|
subscribers *xsync.Map[context.Context, chan<- container.ContainerStat]
|
||||||
client container.Client
|
client container.Client
|
||||||
cancelers *xsync.MapOf[string, context.CancelFunc]
|
cancelers *xsync.Map[string, context.CancelFunc]
|
||||||
stopper context.CancelFunc
|
stopper context.CancelFunc
|
||||||
timer *time.Timer
|
timer *time.Timer
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
@@ -30,9 +30,9 @@ var timeToStop = 6 * time.Hour
|
|||||||
func NewDockerStatsCollector(client container.Client, labels container.ContainerLabels) *DockerStatsCollector {
|
func NewDockerStatsCollector(client container.Client, labels container.ContainerLabels) *DockerStatsCollector {
|
||||||
return &DockerStatsCollector{
|
return &DockerStatsCollector{
|
||||||
stream: make(chan container.ContainerStat),
|
stream: make(chan container.ContainerStat),
|
||||||
subscribers: xsync.NewMapOf[context.Context, chan<- container.ContainerStat](),
|
subscribers: xsync.NewMap[context.Context, chan<- container.ContainerStat](),
|
||||||
client: client,
|
client: client,
|
||||||
cancelers: xsync.NewMapOf[string, context.CancelFunc](),
|
cancelers: xsync.NewMap[string, context.CancelFunc](),
|
||||||
labels: labels,
|
labels: labels,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/amir20/dozzle/internal/container"
|
"github.com/amir20/dozzle/internal/container"
|
||||||
"github.com/puzpuzpuz/xsync/v3"
|
"github.com/puzpuzpuz/xsync/v4"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
metricsclient "k8s.io/metrics/pkg/client/clientset/versioned"
|
metricsclient "k8s.io/metrics/pkg/client/clientset/versioned"
|
||||||
@@ -18,7 +18,7 @@ var timeToStop = 2 * time.Hour
|
|||||||
type K8sStatsCollector struct {
|
type K8sStatsCollector struct {
|
||||||
client *K8sClient
|
client *K8sClient
|
||||||
metrics *metricsclient.Clientset
|
metrics *metricsclient.Clientset
|
||||||
subscribers *xsync.MapOf[context.Context, chan<- container.ContainerStat]
|
subscribers *xsync.Map[context.Context, chan<- container.ContainerStat]
|
||||||
stopper context.CancelFunc
|
stopper context.CancelFunc
|
||||||
timer *time.Timer
|
timer *time.Timer
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
@@ -32,7 +32,7 @@ func NewK8sStatsCollector(client *K8sClient, labels container.ContainerLabels) (
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &K8sStatsCollector{
|
return &K8sStatsCollector{
|
||||||
subscribers: xsync.NewMapOf[context.Context, chan<- container.ContainerStat](),
|
subscribers: xsync.NewMap[context.Context, chan<- container.ContainerStat](),
|
||||||
client: client,
|
client: client,
|
||||||
labels: labels,
|
labels: labels,
|
||||||
metrics: metricsClient,
|
metrics: metricsClient,
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
"github.com/amir20/dozzle/internal/container"
|
"github.com/amir20/dozzle/internal/container"
|
||||||
container_support "github.com/amir20/dozzle/internal/support/container"
|
container_support "github.com/amir20/dozzle/internal/support/container"
|
||||||
|
|
||||||
"github.com/puzpuzpuz/xsync/v3"
|
"github.com/puzpuzpuz/xsync/v4"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
lop "github.com/samber/lo/parallel"
|
lop "github.com/samber/lo/parallel"
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ type RetriableClientManager struct {
|
|||||||
failedAgents []string
|
failedAgents []string
|
||||||
certs tls.Certificate
|
certs tls.Certificate
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
subscribers *xsync.MapOf[context.Context, chan<- container.Host]
|
subscribers *xsync.Map[context.Context, chan<- container.Host]
|
||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ func NewRetriableClientManager(agents []string, timeout time.Duration, certs tls
|
|||||||
clients: clientMap,
|
clients: clientMap,
|
||||||
failedAgents: failed,
|
failedAgents: failed,
|
||||||
certs: certs,
|
certs: certs,
|
||||||
subscribers: xsync.NewMapOf[context.Context, chan<- container.Host](),
|
subscribers: xsync.NewMap[context.Context, chan<- container.Host](),
|
||||||
timeout: timeout,
|
timeout: timeout,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import (
|
|||||||
"github.com/amir20/dozzle/internal/docker"
|
"github.com/amir20/dozzle/internal/docker"
|
||||||
container_support "github.com/amir20/dozzle/internal/support/container"
|
container_support "github.com/amir20/dozzle/internal/support/container"
|
||||||
|
|
||||||
"github.com/puzpuzpuz/xsync/v3"
|
"github.com/puzpuzpuz/xsync/v4"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
lop "github.com/samber/lo/parallel"
|
lop "github.com/samber/lo/parallel"
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ type SwarmClientManager struct {
|
|||||||
clients map[string]container_support.ClientService
|
clients map[string]container_support.ClientService
|
||||||
certs tls.Certificate
|
certs tls.Certificate
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
subscribers *xsync.MapOf[context.Context, chan<- container.Host]
|
subscribers *xsync.Map[context.Context, chan<- container.Host]
|
||||||
localClient container.Client
|
localClient container.Client
|
||||||
localIPs []string
|
localIPs []string
|
||||||
name string
|
name string
|
||||||
@@ -75,7 +75,7 @@ func NewSwarmClientManager(localClient *docker.DockerClient, certs tls.Certifica
|
|||||||
localClient: localClient,
|
localClient: localClient,
|
||||||
clients: clientMap,
|
clients: clientMap,
|
||||||
certs: certs,
|
certs: certs,
|
||||||
subscribers: xsync.NewMapOf[context.Context, chan<- container.Host](),
|
subscribers: xsync.NewMap[context.Context, chan<- container.Host](),
|
||||||
localIPs: localIPs(),
|
localIPs: localIPs(),
|
||||||
name: serviceName,
|
name: serviceName,
|
||||||
timeout: timeout,
|
timeout: timeout,
|
||||||
|
|||||||
Reference in New Issue
Block a user