Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't scrape pods via HTTP if the activator in path #15539

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion pkg/autoscaler/metrics/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ type MetricClient interface {
// StableAndPanicRPS returns both the stable and the panic RPS
// for the given replica as of the given time.
StableAndPanicRPS(key types.NamespacedName, now time.Time) (float64, float64, error)

// Pause pauses the pod scrapper of the collection with specified Key.
Pause(key types.NamespacedName)

// Resume pauses the pod scrapper of the collection with specified Key.
Resume(key types.NamespacedName)
}

// MetricCollector manages collection of metrics for many entities.
Expand Down Expand Up @@ -149,6 +155,26 @@ func (c *MetricCollector) Delete(namespace, name string) {
}
}

// Pause pauses the pod scrapper of the collection with specified Key.
func (c *MetricCollector) Pause(key types.NamespacedName) {
c.collectionsMutex.RLock()
defer c.collectionsMutex.RUnlock()

if collection, exists := c.collections[key]; exists {
collection.pause()
}
}

// Resume resume the pod scrapper of the collection with specified Key.
func (c *MetricCollector) Resume(key types.NamespacedName) {
c.collectionsMutex.RLock()
defer c.collectionsMutex.RUnlock()

if collection, exists := c.collections[key]; exists {
collection.resume()
}
}

// Record records a stat that's been generated outside of the metric collector.
func (c *MetricCollector) Record(key types.NamespacedName, now time.Time, stat Stat) {
c.collectionsMutex.RLock()
Expand Down Expand Up @@ -245,6 +271,8 @@ type (
lastErr error
grp sync.WaitGroup
stopCh chan struct{}
// Pause scrape
pauseCh chan bool
}
)

Expand Down Expand Up @@ -288,7 +316,8 @@ func newCollection(metric *autoscalingv1alpha1.Metric, scraper StatsScraper, clo
metric.Spec.PanicWindow, config.BucketSize),
scraper: scraper,

stopCh: make(chan struct{}),
stopCh: make(chan struct{}),
pauseCh: make(chan bool),
}

key := types.NamespacedName{Namespace: metric.Namespace, Name: metric.Name}
Expand All @@ -299,12 +328,18 @@ func newCollection(metric *autoscalingv1alpha1.Metric, scraper StatsScraper, clo
defer c.grp.Done()

scrapeTicker := clock.NewTicker(scrapeTickInterval)
var pause bool
defer scrapeTicker.Stop()
for {
select {
case <-c.stopCh:
return
case pause = <-c.pauseCh:
case <-scrapeTicker.C():
if pause {
continue
}

scraper := c.getScraper()
if scraper == nil {
// Don't scrape empty target service.
Expand Down Expand Up @@ -414,3 +449,13 @@ func (dst *Stat) average(sample, total float64) {
dst.RequestCount = dst.RequestCount / sample * total
dst.ProxiedRequestCount = dst.ProxiedRequestCount / sample * total
}

// pause pauses the pod scraper of the current collection.
func (c *collection) pause() {
c.pauseCh <- true
}

// resume resumes the pod scraper of the current collection.
func (c *collection) resume() {
c.pauseCh <- false
}
2 changes: 2 additions & 0 deletions pkg/autoscaler/scaling/autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ func (a *autoscaler) Scale(logger *zap.SugaredLogger, now time.Time) ScaleResult
case spec.TargetBurstCapacity > 0:
totCap := float64(originalReadyPodsCount) * spec.TotalValue
excessBCF = math.Floor(totCap - spec.TargetBurstCapacity - observedPanicValue)
case spec.TargetBurstCapacity == -1:
a.metricClient.Pause(metricKey)
}

if debugEnabled {
Expand Down