Skip to content

Commit

Permalink
Don't scrape pods via HTTP if the activator in path
Browse files Browse the repository at this point in the history
  • Loading branch information
yenniechen committed Sep 30, 2024
1 parent 779761a commit 22956a2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
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

0 comments on commit 22956a2

Please sign in to comment.