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

[Enhancement]- Fix log pollution #585

Merged
merged 4 commits into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion k8sutils/cluster-scaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func ReshardRedisCluster(cr *redisv1beta1.RedisCluster) {
logger.Info("Redis cluster reshard command is", "Command", cmd)

if slot == "0" {
log.Info("Skipped the execution of", "Cmd", cmd)
logger.Info("Skipped the execution of", "Cmd", cmd)
return
}
executeCommand(cr, cmd, cr.ObjectMeta.Name+"-leader-0")
Expand Down
2 changes: 1 addition & 1 deletion k8sutils/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (

// finalizeLogger will generate logging interface
func finalizerLogger(namespace string, name string) logr.Logger {
reqLogger := log.WithValues("Request.Service.Namespace", namespace, "Request.Finalizer.Name", name)
reqLogger := log.V(1).WithValues("Request.Service.Namespace", namespace, "Request.Finalizer.Name", name)
return reqLogger
}

Expand Down
2 changes: 1 addition & 1 deletion k8sutils/poddisruption.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,6 @@ func GetPodDisruptionBudget(namespace string, pdb string) (*policyv1.PodDisrupti

// pdbLogger will generate logging interface for PodDisruptionBudgets
func pdbLogger(namespace string, name string) logr.Logger {
reqLogger := log.WithValues("Request.PodDisruptionBudget.Namespace", namespace, "Request.PodDisruptionBudget.Name", name)
reqLogger := log.V(1).WithValues("Request.PodDisruptionBudget.Namespace", namespace, "Request.PodDisruptionBudget.Name", name)
return reqLogger
}
4 changes: 2 additions & 2 deletions k8sutils/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ func checkRedisNodePresence(cr *redisv1beta1.RedisCluster, nodeList [][]string,

// generateRedisManagerLogger will generate logging interface for Redis operations
func generateRedisManagerLogger(namespace, name string) logr.Logger {
reqLogger := log.WithValues("Request.RedisManager.Namespace", namespace, "Request.RedisManager.Name", name)
reqLogger := log.V(1).WithValues("Request.RedisManager.Namespace", namespace, "Request.RedisManager.Name", name)
return reqLogger
}

Expand Down Expand Up @@ -568,7 +568,7 @@ func CreateMasterSlaveReplication(cr *redisv1beta1.RedisReplication, masterPods

redisClient := configureRedisReplicationClient(cr, masterPods[i])
defer redisClient.Close()
log.Info("Setting the", "pod", masterPods[i], "to slave of", realMasterPod)
logger.Info("Setting the", "pod", masterPods[i], "to slave of", realMasterPod)
err := redisClient.SlaveOf(realMasterPodIP, "6379").Err()
if err != nil {
logger.Error(err, "Failed to set", "pod", masterPods[i], "to slave of", realMasterPod)
Expand Down
6 changes: 3 additions & 3 deletions k8sutils/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ func getRedisPassword(namespace, name, secretKey string) (string, error) {
}

func secretLogger(namespace string, name string) logr.Logger {
reqLogger := log.WithValues("Request.Secret.Namespace", namespace, "Request.Secret.Name", name)
reqLogger := log.V(1).WithValues("Request.Secret.Namespace", namespace, "Request.Secret.Name", name)
return reqLogger
}

func getRedisTLSConfig(cr *redisv1beta1.RedisCluster, redisInfo RedisDetails) *tls.Config {
if cr.Spec.TLS != nil {
reqLogger := log.WithValues("Request.Namespace", cr.Namespace, "Request.Name", cr.ObjectMeta.Name)
reqLogger := log.V(1).WithValues("Request.Namespace", cr.Namespace, "Request.Name", cr.ObjectMeta.Name)
secretName, err := generateK8sClient().CoreV1().Secrets(cr.Namespace).Get(context.TODO(), cr.Spec.TLS.Secret.SecretName, metav1.GetOptions{})
if err != nil {
reqLogger.Error(err, "Failed in getting TLS secret for redis")
Expand Down Expand Up @@ -86,7 +86,7 @@ func getRedisTLSConfig(cr *redisv1beta1.RedisCluster, redisInfo RedisDetails) *t

func getRedisReplicationTLSConfig(cr *redisv1beta1.RedisReplication, redisInfo RedisDetails) *tls.Config {
if cr.Spec.TLS != nil {
reqLogger := log.WithValues("Request.Namespace", cr.Namespace, "Request.Name", cr.ObjectMeta.Name)
reqLogger := log.V(1).WithValues("Request.Namespace", cr.Namespace, "Request.Name", cr.ObjectMeta.Name)
secretName, err := generateK8sClient().CoreV1().Secrets(cr.Namespace).Get(context.TODO(), cr.Spec.TLS.Secret.SecretName, metav1.GetOptions{})
if err != nil {
reqLogger.Error(err, "Failed in getting TLS secret for redis")
Expand Down
2 changes: 1 addition & 1 deletion k8sutils/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func getService(namespace string, service string) (*corev1.Service, error) {
}

func serviceLogger(namespace string, name string) logr.Logger {
reqLogger := log.WithValues("Request.Service.Namespace", namespace, "Request.Service.Name", name)
reqLogger := log.V(1).WithValues("Request.Service.Namespace", namespace, "Request.Service.Name", name)
return reqLogger
}

Expand Down
2 changes: 1 addition & 1 deletion k8sutils/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ func GetStatefulSet(namespace string, stateful string) (*appsv1.StatefulSet, err

// statefulSetLogger will generate logging interface for Statfulsets
func statefulSetLogger(namespace string, name string) logr.Logger {
reqLogger := log.WithValues("Request.StatefulSet.Namespace", namespace, "Request.StatefulSet.Name", name)
reqLogger := log.V(1).WithValues("Request.StatefulSet.Namespace", namespace, "Request.StatefulSet.Name", name)
return reqLogger
}

Expand Down
9 changes: 8 additions & 1 deletion main.go
drivebyer marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"flag"
"os"

"go.uber.org/zap/zapcore"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"
Expand Down Expand Up @@ -52,16 +54,21 @@ func main() {
var metricsAddr string
var enableLeaderElection bool
var probeAddr string
var logVerbosity int
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.IntVar(&logVerbosity, "verbosity", 0, "Log verbosity level, higher value means more logs.")

flag.Parse()

opts := zap.Options{
Development: false,
Level: zapcore.Level(-logVerbosity),
}
opts.BindFlags(flag.CommandLine)
flag.Parse()

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

Expand Down