Skip to content

Commit

Permalink
chore: Refactor operator logs
Browse files Browse the repository at this point in the history
- Reduce amount of informational log events using Debug level ("Reconciling ...", "Invoking action ...")
- Log error details on state transition to Phase "Error" for Integration, Build, KameletBinding, Pipe
  • Loading branch information
christophd committed Jul 17, 2023
1 parent a8beef5 commit 59b3155
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 22 deletions.
6 changes: 3 additions & 3 deletions e2e/commonwithcustominstall/operator_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestMetrics(t *testing.T) {
err = NewLogWalker(&logs).
AddStep(MatchFields(IgnoreExtras, Fields{
"LoggerName": Equal("camel-k.controller.build"),
"Message": Equal("state transition"),
"Message": Equal("State transition"),
"PhaseFrom": Equal(string(v1.BuildPhaseScheduling)),
"PhaseTo": Equal(string(v1.BuildPhasePending)),
"RequestName": Equal(build.Name),
Expand All @@ -115,7 +115,7 @@ func TestMetrics(t *testing.T) {
}), LogEntryNoop).
AddStep(MatchFields(IgnoreExtras, Fields{
"LoggerName": Equal("camel-k.controller.build"),
"Message": Equal("state transition"),
"Message": Equal("State transition"),
"PhaseFrom": Equal(string(v1.BuildPhaseRunning)),
"PhaseTo": Equal(string(v1.BuildPhaseSucceeded)),
"RequestName": Equal(build.Name),
Expand Down Expand Up @@ -422,7 +422,7 @@ func TestMetrics(t *testing.T) {
err = NewLogWalker(&logs).
AddStep(MatchFields(IgnoreExtras, Fields{
"LoggerName": Equal("camel-k.controller.build"),
"Message": Equal("state transition"),
"Message": Equal("State transition"),
"PhaseFrom": Equal(string(v1.BuildPhaseScheduling)),
"PhaseTo": Equal(string(v1.BuildPhasePending)),
"RequestName": Equal(build.Name),
Expand Down
19 changes: 16 additions & 3 deletions pkg/controller/build/build_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ type reconcileBuild struct {
// Result.Requeue is true, otherwise upon completion it will remove the work from the queue.
func (r *reconcileBuild) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) {
rlog := Log.WithValues("request-namespace", request.Namespace, "request-name", request.Name)
rlog.Info("Reconciling Build")
rlog.Debug("Reconciling Build")

// Make sure the operator is allowed to act on namespace
if ok, err := platform.IsOperatorAllowedOnNamespace(ctx, r.client, request.Namespace); err != nil {
Expand Down Expand Up @@ -176,7 +176,7 @@ func (r *reconcileBuild) Reconcile(ctx context.Context, request reconcile.Reques
a.InjectRecorder(r.recorder)

if a.CanHandle(target) {
targetLog.Infof("Invoking action %s", a.Name())
targetLog.Debugf("Invoking action %s", a.Name())

newTarget, err := a.Handle(ctx, target)
if err != nil {
Expand All @@ -192,10 +192,23 @@ func (r *reconcileBuild) Reconcile(ctx context.Context, request reconcile.Reques

if newTarget.Status.Phase != instance.Status.Phase {
targetLog.Info(
"state transition",
"State transition",
"phase-from", instance.Status.Phase,
"phase-to", newTarget.Status.Phase,
)

if newTarget.Status.Phase == v1.BuildPhaseError || newTarget.Status.Phase == v1.BuildPhaseFailed {
reason := string(newTarget.Status.Phase)

if newTarget.Status.Failure != nil {
reason = newTarget.Status.Failure.Reason
}

targetLog.Info(
"Build error",
"reason", reason,
"error-message", newTarget.Status.Error)
}
}

target = newTarget
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/build/monitor_routine.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (action *monitorRoutineAction) updateBuildStatus(ctx context.Context, build
return err
}
if target.Status.Phase != build.Status.Phase {
action.L.Info("state transition", "phase-from", build.Status.Phase, "phase-to", target.Status.Phase)
action.L.Info("State transition", "phase-from", build.Status.Phase, "phase-to", target.Status.Phase)
}
event.NotifyBuildUpdated(ctx, action.client, action.recorder, build, target)
build.Status = target.Status
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/build/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (action *scheduleAction) patchBuildStatus(ctx context.Context, build *v1.Bu
}

if target.Status.Phase != build.Status.Phase {
action.L.Info("state transition", "phase-from", build.Status.Phase, "phase-to", target.Status.Phase)
action.L.Info("State transition", "phase-from", build.Status.Phase, "phase-to", target.Status.Phase)
}
event.NotifyBuildUpdated(ctx, action.client, action.recorder, build, target)

Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/catalog/catalog_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (r *reconcileCatalog) Reconcile(ctx context.Context, request reconcile.Requ

if targetPhase != phaseFrom {
targetLog.Info(
"state transition",
"State transition",
"phase-from", phaseFrom,
"phase-to", target.Status.Phase,
)
Expand Down
15 changes: 12 additions & 3 deletions pkg/controller/integration/integration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ type reconcileIntegration struct {
// Result.Requeue is true, otherwise upon completion it will remove the work from the queue.
func (r *reconcileIntegration) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) {
rlog := Log.WithValues("request-namespace", request.Namespace, "request-name", request.Name)
rlog.Info("Reconciling Integration")
rlog.Debugf("Reconciling Integration")

// Make sure the operator is allowed to act on namespace
if ok, err := platform.IsOperatorAllowedOnNamespace(ctx, r.client, request.Namespace); err != nil {
Expand Down Expand Up @@ -354,7 +354,7 @@ func (r *reconcileIntegration) Reconcile(ctx context.Context, request reconcile.
a.InjectLogger(targetLog)

if a.CanHandle(target) {
targetLog.Infof("Invoking action %s", a.Name())
targetLog.Debugf("Invoking action %s", a.Name())

newTarget, err := a.Handle(ctx, target)
if err != nil {
Expand Down Expand Up @@ -398,10 +398,19 @@ func (r *reconcileIntegration) update(ctx context.Context, base *v1.Integration,

if target.Status.Phase != base.Status.Phase {
log.Info(
"state transition",
"State transition",
"phase-from", base.Status.Phase,
"phase-to", target.Status.Phase,
)

if target.Status.Phase == v1.IntegrationPhaseError {
if cond := target.Status.GetCondition(v1.IntegrationConditionReady); cond != nil && cond.Status == corev1.ConditionFalse {
log.Info(
"Integration error",
"reason", cond.GetReason(),
"error-message", cond.GetMessage())
}
}
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/integrationkit/integrationkit_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func (r *reconcileIntegrationKit) Reconcile(ctx context.Context, request reconci

if targetPhase != instance.Status.Phase {
targetLog.Info(
"state transition",
"State transition",
"phase-from", instance.Status.Phase,
"phase-to", targetPhase,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (r *reconcileIntegrationPlatform) Reconcile(ctx context.Context, request re

if targetPhase != phaseFrom {
targetLog.Info(
"state transition",
"State transition",
"phase-from", phaseFrom,
"phase-to", target.Status.Phase,
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/kamelet/kamelet_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (r *reconcileKamelet) Reconcile(ctx context.Context, request reconcile.Requ
continue
}

targetLog.Infof("Invoking action %s", a.Name())
targetLog.Debugf("Invoking action %s", a.Name())

phaseFrom := target.Status.Phase

Expand All @@ -186,7 +186,7 @@ func (r *reconcileKamelet) Reconcile(ctx context.Context, request reconcile.Requ

if targetPhase != phaseFrom {
targetLog.Info(
"state transition",
"State transition",
"phase-from", phaseFrom,
"phase-to", target.Status.Phase,
)
Expand Down
15 changes: 12 additions & 3 deletions pkg/controller/kameletbinding/kameletbinding_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ type ReconcileKameletBinding struct {
// Result.Requeue is true, otherwise upon completion it will remove the work from the queue.
func (r *ReconcileKameletBinding) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) {
rlog := Log.WithValues("request-namespace", request.Namespace, "request-name", request.Name)
rlog.Info("Reconciling KameletBinding")
rlog.Debug("Reconciling KameletBinding")

// Make sure the operator is allowed to act on namespace
if ok, err := platform.IsOperatorAllowedOnNamespace(ctx, r.client, request.Namespace); err != nil {
Expand Down Expand Up @@ -190,7 +190,7 @@ func (r *ReconcileKameletBinding) Reconcile(ctx context.Context, request reconci
a.InjectLogger(targetLog)

if a.CanHandle(target) {
targetLog.Infof("Invoking action %s", a.Name())
targetLog.Debugf("Invoking action %s", a.Name())

target, err = a.Handle(ctx, target)
if err != nil {
Expand Down Expand Up @@ -229,10 +229,19 @@ func (r *ReconcileKameletBinding) update(ctx context.Context, base *v1alpha1.Kam

if target.Status.Phase != base.Status.Phase {
log.Info(
"state transition",
"State transition",
"phase-from", base.Status.Phase,
"phase-to", target.Status.Phase,
)

if target.Status.Phase == v1alpha1.KameletBindingPhaseError {
if cond := target.Status.GetCondition(v1alpha1.KameletBindingIntegrationConditionError); cond != nil {
log.Info(
"Integration error",
"reason", cond.GetReason(),
"error-message", cond.GetMessage())
}
}
}

return nil
Expand Down
15 changes: 12 additions & 3 deletions pkg/controller/pipe/pipe_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ type ReconcilePipe struct {
// Result.Requeue is true, otherwise upon completion it will remove the work from the queue.
func (r *ReconcilePipe) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) {
rlog := Log.WithValues("request-namespace", request.Namespace, "request-name", request.Name)
rlog.Info("Reconciling Pipe")
rlog.Debug("Reconciling Pipe")

// Make sure the operator is allowed to act on namespace
if ok, err := platform.IsOperatorAllowedOnNamespace(ctx, r.client, request.Namespace); err != nil {
Expand Down Expand Up @@ -190,7 +190,7 @@ func (r *ReconcilePipe) Reconcile(ctx context.Context, request reconcile.Request
a.InjectLogger(targetLog)

if a.CanHandle(target) {
targetLog.Infof("Invoking action %s", a.Name())
targetLog.Debugf("Invoking action %s", a.Name())

target, err = a.Handle(ctx, target)
if err != nil {
Expand Down Expand Up @@ -229,10 +229,19 @@ func (r *ReconcilePipe) update(ctx context.Context, base *v1.Pipe, target *v1.Pi

if target.Status.Phase != base.Status.Phase {
log.Info(
"state transition",
"State transition",
"phase-from", base.Status.Phase,
"phase-to", target.Status.Phase,
)

if target.Status.Phase == v1.PipePhaseError {
if cond := target.Status.GetCondition(v1.PipeIntegrationConditionError); cond != nil {
log.Info(
"Integration error",
"reason", cond.GetReason(),
"error-message", cond.GetMessage())
}
}
}

return nil
Expand Down

0 comments on commit 59b3155

Please sign in to comment.