mirror of
https://github.com/zalando-incubator/kube-metrics-adapter.git
synced 2025-10-11 17:59:28 +00:00
add commandline flags to set GC interval and metrics TTL
Signed-off-by: Harman Singh <iamgrewal7@gmail.com>
This commit is contained in:
@@ -62,6 +62,7 @@ type HPAProvider struct {
|
||||
recorder kube_record.EventRecorder
|
||||
logger *log.Entry
|
||||
disregardIncompatibleHPAs bool
|
||||
gcInterval time.Duration
|
||||
}
|
||||
|
||||
// metricCollection is a container for sending collected metrics across a
|
||||
@@ -72,7 +73,7 @@ type metricCollection struct {
|
||||
}
|
||||
|
||||
// NewHPAProvider initializes a new HPAProvider.
|
||||
func NewHPAProvider(client kubernetes.Interface, interval, collectorInterval time.Duration, collectorFactory *collector.CollectorFactory, disregardIncompatibleHPAs bool) *HPAProvider {
|
||||
func NewHPAProvider(client kubernetes.Interface, interval, collectorInterval time.Duration, collectorFactory *collector.CollectorFactory, disregardIncompatibleHPAs bool, metricsTTL time.Duration, gcInterval time.Duration) *HPAProvider {
|
||||
metricsc := make(chan metricCollection)
|
||||
|
||||
return &HPAProvider{
|
||||
@@ -81,12 +82,13 @@ func NewHPAProvider(client kubernetes.Interface, interval, collectorInterval tim
|
||||
collectorInterval: collectorInterval,
|
||||
metricSink: metricsc,
|
||||
metricStore: NewMetricStore(func() time.Time {
|
||||
return time.Now().UTC().Add(15 * time.Minute)
|
||||
return time.Now().UTC().Add(metricsTTL)
|
||||
}),
|
||||
collectorFactory: collectorFactory,
|
||||
recorder: recorder.CreateEventRecorder(client),
|
||||
logger: log.WithFields(log.Fields{"provider": "hpa"}),
|
||||
disregardIncompatibleHPAs: disregardIncompatibleHPAs,
|
||||
gcInterval: gcInterval,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +220,7 @@ func (p *HPAProvider) collectMetrics(ctx context.Context) {
|
||||
go func(ctx context.Context) {
|
||||
for {
|
||||
select {
|
||||
case <-time.After(10 * time.Minute):
|
||||
case <-time.After(p.gcInterval):
|
||||
p.metricStore.RemoveExpired()
|
||||
case <-ctx.Done():
|
||||
p.logger.Info("Stopped metrics store garbage collection.")
|
||||
|
Reference in New Issue
Block a user