Skip to content

Commit

Permalink
Add log caches to reduce log noise
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonBaeumer committed Feb 22, 2023
1 parent 9b42aca commit b4a141d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
7 changes: 6 additions & 1 deletion fleetshard/pkg/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package runtime
import (
"context"
"fmt"
"sync/atomic"
"time"

"github.com/golang/glog"
Expand All @@ -27,6 +28,8 @@ import (
// TODO(SimonBaeumer): set a unique identifier for the map key, currently the instance name is used
type reconcilerRegistry map[string]*centralReconciler.CentralReconciler

var reconciledCentralCountCache *int64

var backoff = wait.Backoff{
Duration: 1 * time.Second,
Factor: 1.5,
Expand Down Expand Up @@ -119,7 +122,9 @@ func (r *Runtime) Start() error {
}

// Start for each Central its own reconciler which can be triggered by sending a central to the receive channel.
glog.Infof("Received %d centrals", len(list.Items))
if atomic.CompareAndSwapInt64(reconciledCentralCountCache, *reconciledCentralCountCache, int64(len(list.Items))) {
glog.Infof("Received central count changed: received %d centrals", len(list.Items))
}
for _, central := range list.Items {
if _, ok := r.reconcilers[central.Id]; !ok {
r.reconcilers[central.Id] = centralReconciler.NewCentralReconciler(r.k8sClient, central,
Expand Down
9 changes: 6 additions & 3 deletions internal/dinosaur/pkg/workers/clusters_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package workers

import (
"fmt"
"sync/atomic"

dinosaurConstants "github.com/stackrox/acs-fleet-manager/internal/dinosaur/constants"
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/clusters/types"
Expand Down Expand Up @@ -59,6 +60,8 @@ const (
clusterAdminRoleName = "cluster-admin"
)

var readyClusterCountCache *int64

var clusterMetricsStatuses = []api.ClusterStatus{
api.ClusterAccepted,
api.ClusterProvisioning,
Expand Down Expand Up @@ -322,8 +325,8 @@ func (c *ClusterManager) processReadyClusters() []error {
errs = append(errs, errors.Wrap(listErr, "failed to list ready clusters"))
return errs
}
if len(readyClusters) > 0 {
glog.V(10).Infof("ready clusters count = %d", len(readyClusters))
if atomic.CompareAndSwapInt64(readyClusterCountCache, *readyClusterCountCache, int64(len(readyClusters))) {
glog.V(10).Infof("ready clusters count = %d", atomic.LoadInt64(readyClusterCountCache))
}

for _, readyCluster := range readyClusters {
Expand Down Expand Up @@ -472,9 +475,9 @@ func (c *ClusterManager) reconcileClusterInstanceType(cluster api.Cluster) error
if err != nil {
return errors.Wrapf(err, "failed to update instance type in database for cluster %s", cluster.ClusterID)
}
logger.Logger.V(10).Infof("supported instance type for cluster = %s successful updated", cluster.ClusterID)
}

logger.Logger.V(10).Infof("supported instance type for cluster = %s successful updated", cluster.ClusterID)
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import (
"github.com/stackrox/acs-fleet-manager/pkg/metrics"
"github.com/stackrox/acs-fleet-manager/pkg/services/sso"
"github.com/stackrox/acs-fleet-manager/pkg/workers"
"sync/atomic"
)

const readyCentralWorkerType = "ready_dinosaur"

var readyCentralCountCache *int64

// ReadyDinosaurManager represents a dinosaur manager that periodically reconciles dinosaur requests
type ReadyDinosaurManager struct {
workers.BaseWorker
Expand Down Expand Up @@ -49,20 +52,14 @@ func (k *ReadyDinosaurManager) Stop() {

// Reconcile ...
func (k *ReadyDinosaurManager) Reconcile() []error {

var encounteredErrors []error

readyDinosaurs, serviceErr := k.dinosaurService.ListByStatus(constants2.CentralRequestStatusReady)
if serviceErr != nil {
encounteredErrors = append(encounteredErrors, errors.Wrap(serviceErr, "failed to list ready centrals"))
}
if len(readyDinosaurs) > 0 {
glog.Infof("ready centrals count = %d", len(readyDinosaurs))
}

for _, dinosaur := range readyDinosaurs {
glog.V(10).Infof("ready central id = %s", dinosaur.ID)
// TODO implement reconciliation logic for ready dinosaurs
if atomic.CompareAndSwapInt64(readyCentralCountCache, *readyCentralCountCache, int64(len(readyDinosaurs))) {
glog.Infof("ready centrals count = %d", atomic.LoadInt64(readyCentralCountCache))
}

return encounteredErrors
Expand Down

0 comments on commit b4a141d

Please sign in to comment.