mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 09:49:50 +00:00
Merge pull request #22053 from gmarek/resources
Auto commit by PR queue bot
This commit is contained in:
commit
649b6879d7
@ -134,6 +134,7 @@ type resourceGatherWorker struct {
|
|||||||
containerIDs []string
|
containerIDs []string
|
||||||
stopCh chan struct{}
|
stopCh chan struct{}
|
||||||
dataSeries []resourceUsagePerContainer
|
dataSeries []resourceUsagePerContainer
|
||||||
|
finished bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *resourceGatherWorker) singleProbe() {
|
func (w *resourceGatherWorker) singleProbe() {
|
||||||
@ -153,6 +154,7 @@ func (w *resourceGatherWorker) gather(initialSleep time.Duration) {
|
|||||||
defer utilruntime.HandleCrash()
|
defer utilruntime.HandleCrash()
|
||||||
defer w.wg.Done()
|
defer w.wg.Done()
|
||||||
defer Logf("Closing worker for %v", w.nodeName)
|
defer Logf("Closing worker for %v", w.nodeName)
|
||||||
|
defer func() { w.finished = true }()
|
||||||
select {
|
select {
|
||||||
case <-time.After(initialSleep):
|
case <-time.After(initialSleep):
|
||||||
w.singleProbe()
|
w.singleProbe()
|
||||||
@ -223,6 +225,7 @@ func NewResourceUsageGatherer(c *client.Client) (*containerResourceGatherer, err
|
|||||||
containerIDToNameMap: g.containerIDToNameMap,
|
containerIDToNameMap: g.containerIDToNameMap,
|
||||||
containerIDs: g.containerIDs,
|
containerIDs: g.containerIDs,
|
||||||
stopCh: g.stopCh,
|
stopCh: g.stopCh,
|
||||||
|
finished: false,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return &g, nil
|
return &g, nil
|
||||||
@ -236,17 +239,35 @@ func (g *containerResourceGatherer) startGatheringData() {
|
|||||||
func (g *containerResourceGatherer) stopAndSummarize(percentiles []int, constraints map[string]resourceConstraint) *ResourceUsageSummary {
|
func (g *containerResourceGatherer) stopAndSummarize(percentiles []int, constraints map[string]resourceConstraint) *ResourceUsageSummary {
|
||||||
close(g.stopCh)
|
close(g.stopCh)
|
||||||
Logf("Closed stop channel. Waiting for %v workers", len(g.workers))
|
Logf("Closed stop channel. Waiting for %v workers", len(g.workers))
|
||||||
|
finished := make(chan struct{})
|
||||||
|
go func() {
|
||||||
g.workerWg.Wait()
|
g.workerWg.Wait()
|
||||||
|
finished <- struct{}{}
|
||||||
|
}()
|
||||||
|
select {
|
||||||
|
case <-finished:
|
||||||
Logf("Waitgroup finished.")
|
Logf("Waitgroup finished.")
|
||||||
|
case <-time.After(2 * time.Minute):
|
||||||
|
unfinished := make([]string, 0)
|
||||||
|
for i := range g.workers {
|
||||||
|
if !g.workers[i].finished {
|
||||||
|
unfinished = append(unfinished, g.workers[i].nodeName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Logf("Timed out while waiting for waitgroup, some workers failed to finish: %v", unfinished)
|
||||||
|
}
|
||||||
|
|
||||||
if len(percentiles) == 0 {
|
if len(percentiles) == 0 {
|
||||||
Logf("Warning! Empty percentile list for stopAndPrintData.")
|
Logf("Warning! Empty percentile list for stopAndPrintData.")
|
||||||
return &ResourceUsageSummary{}
|
return &ResourceUsageSummary{}
|
||||||
}
|
}
|
||||||
data := make(map[int]resourceUsagePerContainer)
|
data := make(map[int]resourceUsagePerContainer)
|
||||||
for i := range g.workers {
|
for i := range g.workers {
|
||||||
|
if g.workers[i].finished {
|
||||||
stats := computePercentiles(g.workers[i].dataSeries, percentiles)
|
stats := computePercentiles(g.workers[i].dataSeries, percentiles)
|
||||||
data = leftMergeData(stats, data)
|
data = leftMergeData(stats, data)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Workers has been stopped. We need to gather data stored in them.
|
// Workers has been stopped. We need to gather data stored in them.
|
||||||
sortedKeys := []string{}
|
sortedKeys := []string{}
|
||||||
|
Loading…
Reference in New Issue
Block a user