Skip to content

Commit

Permalink
remove periodical sync of Runtime metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
koala7659 committed Oct 25, 2024
1 parent 3c7bb82 commit 8264618
Showing 1 changed file with 7 additions and 35 deletions.
42 changes: 7 additions & 35 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ const defaultExpirationTime = 24 * time.Hour
const defaultGardenerRequestTimeout = 60 * time.Second
const defaultControlPlaneRequeueDuration = 10 * time.Second
const defaultGardenerRequeueDuration = 15 * time.Second
const RuntimeMetricRefreshPeriod = 30 * time.Second

func main() {
var metricsAddr string
Expand Down Expand Up @@ -221,30 +220,20 @@ func main() {
os.Exit(1)
}

refreshRuntimeMetrics := func() {
logger.Info("Refreshing runtime CR metrics")
metrics.ResetRuntimeMetrics()
var RuntimeList infrastructuremanagerv1.RuntimeList
if err = mgr.GetClient().List(context.TODO(), &RuntimeList); err == nil {
for _, rt := range RuntimeList.Items {
metrics.SetRuntimeStates(rt)
}
logger.Info("Refreshing runtime CR metrics")
metrics.ResetRuntimeMetrics()
var RuntimeList infrastructuremanagerv1.RuntimeList
if err = mgr.GetClient().List(context.TODO(), &RuntimeList); err == nil {
for _, rt := range RuntimeList.Items {
metrics.SetRuntimeStates(rt)
}
}

quitChannel := startRuntimeMetricsRefresher(refreshRuntimeMetrics)
defer func() {
logger.Info("Stopping metric refresh process goroutine")
if quitChannel != nil {
quitChannel <- true
}
}()

setupLog.Info("Starting Manager", "kubeconfigExpirationTime", expirationTime, "kubeconfigRotationPeriod", rotationPeriod)

if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
os.Exit(1) //nolint:gocritic
os.Exit(1)
}
}

Expand Down Expand Up @@ -324,20 +313,3 @@ func validateAuditLogDataMap(data map[string]map[string]auditlogging.AuditLogDat

return nil
}

func startRuntimeMetricsRefresher(refreshFunc func()) chan bool {
quitChannel := make(chan bool)
go func() {
for {
time.Sleep(RuntimeMetricRefreshPeriod)
select {
case <-quitChannel:
// println("Received signal to stop metric refresh process")
return
default:
refreshFunc()
}
}
}()
return quitChannel
}

0 comments on commit 8264618

Please sign in to comment.