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

update structured logging #210

Merged
Changes from all 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
40 changes: 20 additions & 20 deletions controllers/horizon_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ func (r *HorizonReconciler) GetScheme() *runtime.Scheme {
return r.Scheme
}

// GetLog returns a logger object with a prefix of "conroller.name" and aditional controller context fields
func GetLog(ctx context.Context) logr.Logger {
// GetLog returns a logger object with a prefix of "controller.name" and additional controller context fields
func (r *HorizonReconciler) GetLogger(ctx context.Context) logr.Logger {
return log.FromContext(ctx).WithName("Controllers").WithName("Horizon")
}

Expand Down Expand Up @@ -129,7 +129,7 @@ func (r *HorizonReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
r.Client,
r.Kclient,
r.Scheme,
GetLog(ctx),
r.GetLogger(ctx),
)

if err != nil {
Expand Down Expand Up @@ -246,12 +246,12 @@ func (r *HorizonReconciler) SetupWithManager(mgr ctrl.Manager) error {
}

func (r *HorizonReconciler) reconcileDelete(ctx context.Context, instance *horizonv1beta1.Horizon, helper *helper.Helper) (ctrl.Result, error) {
l := GetLog(ctx)
l.Info("Reconciling Service delete")
Log := r.GetLogger(ctx)
Log.Info("Reconciling Service delete")

// Service is deleted so remove the finalizer.
controllerutil.RemoveFinalizer(instance, helper.GetFinalizer())
l.Info("Reconciled Service delete successfully")
Log.Info("Reconciled Service delete successfully")

return ctrl.Result{}, nil
}
Expand All @@ -262,8 +262,8 @@ func (r *HorizonReconciler) reconcileInit(
helper *helper.Helper,
serviceLabels map[string]string,
) (ctrl.Result, error) {
l := GetLog(ctx)
l.Info("Reconciling Service init")
Log := r.GetLogger(ctx)
Log.Info("Reconciling Service init")

//
// expose the service (create service and return the created endpoint URL)
Expand Down Expand Up @@ -360,35 +360,35 @@ func (r *HorizonReconciler) reconcileInit(

// expose service - end

l.Info("Reconciled Service init successfully")
Log.Info("Reconciled Service init successfully")
return ctrl.Result{}, nil
}

func (r *HorizonReconciler) reconcileUpdate(ctx context.Context, instance *horizonv1beta1.Horizon, helper *helper.Helper) (ctrl.Result, error) {
l := GetLog(ctx)
l.Info("Reconciling Service update")
Log := r.GetLogger(ctx)
Log.Info("Reconciling Service update")

// TODO: should have minor update tasks if required
// - delete dbsync hash from status to rerun it?

l.Info("Reconciled Service update successfully")
Log.Info("Reconciled Service update successfully")
return ctrl.Result{}, nil
}

func (r *HorizonReconciler) reconcileUpgrade(ctx context.Context, instance *horizonv1beta1.Horizon, helper *helper.Helper) (ctrl.Result, error) {
l := GetLog(ctx)
l.Info("Reconciling Service upgrade")
Log := r.GetLogger(ctx)
Log.Info("Reconciling Service upgrade")

// TODO: should have major version upgrade tasks
// -delete dbsync hash from status to rerun it?

l.Info("Reconciled Service upgrade successfully")
Log.Info("Reconciled Service upgrade successfully")
return ctrl.Result{}, nil
}

func (r *HorizonReconciler) reconcileNormal(ctx context.Context, instance *horizonv1beta1.Horizon, helper *helper.Helper) (ctrl.Result, error) {
l := GetLog(ctx)
l.Info("Reconciling Service")
Log := r.GetLogger(ctx)
Log.Info("Reconciling Service")

// Service account, role, binding
rbacResult, err := configureHorizonRbac(ctx, helper, instance)
Expand Down Expand Up @@ -573,7 +573,7 @@ func (r *HorizonReconciler) reconcileNormal(ctx context.Context, instance *horiz
}
// create Deployment - end

l.Info("Reconciled Service successfully")
Log.Info("Reconciled Service successfully")
return ctrl.Result{}, nil
}

Expand Down Expand Up @@ -656,7 +656,7 @@ func (r *HorizonReconciler) createHashOfInputHashes(
}
if hashMap, changed = util.SetHash(instance.Status.Hash, common.InputHashName, hash); changed {
instance.Status.Hash = hashMap
GetLog(ctx).Info(fmt.Sprintf("Input maps hash %s - %s", common.InputHashName, hash))
r.GetLogger(ctx).Info(fmt.Sprintf("Input maps hash %s - %s", common.InputHashName, hash))
}
return hash, changed, nil
}
Expand All @@ -678,7 +678,7 @@ func (r *HorizonReconciler) ensureHorizonSecret(
return err
}
if k8s_errors.IsNotFound(err) || !validateHorizonSecret(scrt) {
GetLog(ctx).Info("Creating Horizon Secret")
r.GetLogger(ctx).Info("Creating Horizon Secret")
// Create k8s secret to store Horizon Secret
tmpl := []util.Template{
{
Expand Down