v0.43.1
This commit is contained in:
1 parent
5b6d4a7903
commit
4d1087e357
160 files changed
+2407
-1933
No files matched your search
@@ -124,9 +124,6 @@ func (c *containerCollector) cpuPercent(id string, stats containerStats) *float6
|
||||
return &value
|
||||
}
|
||||
|
||||
// enrich applies a bounded, short-lived snapshot to every service, including
|
||||
// multiple published ports belonging to the same container. It coalesces
|
||||
// concurrent polls without holding a mutex during Docker API requests.
|
||||
func (c *containerCollector) enrich(ctx context.Context, sock string, services []service) {
|
||||
selected := make(map[string]struct{})
|
||||
order := make([]string, 0, maxStatContainers)
|
||||
@@ -166,7 +163,7 @@ func (c *containerCollector) enrich(ctx context.Context, sock string, services [
|
||||
}
|
||||
}
|
||||
if hit {
|
||||
snapshot := c.cache // immutable until replaced; copies are applied below
|
||||
snapshot := c.cache
|
||||
c.mu.Unlock()
|
||||
applyContainerSnapshot(services, snapshot)
|
||||
return
|
||||
@@ -187,9 +184,6 @@ func (c *containerCollector) enrich(ctx context.Context, sock string, services [
|
||||
|
||||
snapshot := c.fetchSnapshot(ctx, sock, order)
|
||||
c.mu.Lock()
|
||||
// A disconnected client must not replace a complete cache with an
|
||||
// incomplete snapshot. Docker API timeouts still produce a bounded,
|
||||
// temporarily cached partial snapshot to avoid repeated heavy polling.
|
||||
if ctx.Err() == nil {
|
||||
c.cache, c.cacheSock = snapshot, sock
|
||||
c.cacheUntil = time.Now().Add(containerStatsTTL)
|
||||
@@ -207,8 +201,6 @@ func (c *containerCollector) enrich(ctx context.Context, sock string, services [
|
||||
}
|
||||
}
|
||||
|
||||
// fetchSnapshot uses a fixed worker pool rather than a goroutine per container.
|
||||
// Results are indexed so workers never write concurrently into a Go map.
|
||||
func (c *containerCollector) fetchSnapshot(parent context.Context, sock string, order []string) map[string]containerState {
|
||||
ctx, cancel := context.WithTimeout(parent, 4*time.Second)
|
||||
defer cancel()
|
||||
@@ -276,8 +268,6 @@ func (c *containerCollector) inspectContainer(ctx context.Context, sock, id stri
|
||||
return state
|
||||
}
|
||||
|
||||
// Each request owns its service structs. Never hand out pointers to cached
|
||||
// values: a caller modifying an inventory must not mutate a later response.
|
||||
func applyContainerSnapshot(services []service, snapshot map[string]containerState) {
|
||||
for i := range services {
|
||||
dest := services[i].Container
|
||||
|
||||
Reference in new issue
Block a user