-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from Kuadrant/enhanced-logging
Enhanced logging
- Loading branch information
Showing
14 changed files
with
357 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,17 +70,18 @@ type RateLimitReconciler struct { | |
// | ||
// For more details, check Reconcile and its Result here: | ||
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile | ||
func (r *RateLimitReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
reqLogger := r.Logger().WithValues("ratelimit", req.NamespacedName) | ||
reqLogger.V(1).Info("Reconciling RateLimit") | ||
func (r *RateLimitReconciler) Reconcile(eventCtx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
logger := r.Logger().WithValues("ratelimit", req.NamespacedName) | ||
logger.V(1).Info("Reconciling RateLimit") | ||
ctx := logr.NewContext(eventCtx, logger) | ||
|
||
limit := &limitadorv1alpha1.RateLimit{} | ||
if err := r.Client().Get(ctx, req.NamespacedName, limit); err != nil { | ||
if errors.IsNotFound(err) { | ||
return ctrl.Result{}, nil | ||
} | ||
|
||
reqLogger.Error(err, "Failed to get RateLimit object.") | ||
logger.Error(err, "Failed to get RateLimit object.") | ||
return ctrl.Result{}, err | ||
} | ||
|
||
|
@@ -102,12 +103,12 @@ func (r *RateLimitReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( | |
return ctrl.Result{}, nil | ||
} | ||
|
||
if err := r.ensureFinalizerIsAdded(ctx, limit, reqLogger); err != nil { | ||
if err := r.ensureFinalizerIsAdded(ctx, limit); err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
|
||
if err := r.createLimitInLimitador(limit); err != nil { | ||
reqLogger.Error(err, "Failed to create rate limit in Limitador.") | ||
logger.Error(err, "Failed to create rate limit in Limitador.") | ||
return ctrl.Result{}, err | ||
} | ||
|
||
|
@@ -166,7 +167,8 @@ func (r *RateLimitReconciler) createLimitInLimitador(limit *limitadorv1alpha1.Ra | |
return limitadorClient.CreateLimit(&limit.Spec) | ||
} | ||
|
||
func (r *RateLimitReconciler) ensureFinalizerIsAdded(ctx context.Context, limit *limitadorv1alpha1.RateLimit, reqLogger logr.Logger) error { | ||
func (r *RateLimitReconciler) ensureFinalizerIsAdded(ctx context.Context, limit *limitadorv1alpha1.RateLimit) error { | ||
logger := logr.FromContext(ctx) | ||
numberOfFinalizers := len(limit.GetFinalizers()) | ||
controllerutil.AddFinalizer(limit, rateLimitFinalizer) | ||
if numberOfFinalizers == len(limit.GetFinalizers()) { | ||
|
@@ -175,7 +177,7 @@ func (r *RateLimitReconciler) ensureFinalizerIsAdded(ctx context.Context, limit | |
} | ||
|
||
if err := r.Client().Update(ctx, limit); err != nil { | ||
reqLogger.Error(err, "Failed to update the rate limit with finalizer") | ||
logger.Error(err, "Failed to update the rate limit with finalizer") | ||
return err | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Logging | ||
|
||
The limitador operator outputs 3 levels of log messages: (from lowest to highest level) | ||
1. `debug` | ||
2. `info` (default) | ||
3. `error` | ||
|
||
`info` logging is restricted to high-level information. Actions like creating, deleteing or updating kubernetes resources will be logged with reduced details about the corresponding objects, and without any further detailed logs of the steps in between, except for errors. | ||
|
||
Only `debug` logging will include processing details. | ||
|
||
To configure the desired log level, set the environment variable `LOG_LEVEL` to one of the supported values listed above. Default log level is `info`. | ||
|
||
Apart from log level, the controller can output messages to the logs in 2 different formats: | ||
- `production` (default): each line is a parseable JSON object with properties `{"level":string, "ts":int, "msg":string, "logger":string, extra values...}` | ||
- `development`: more human-readable outputs, extra stack traces and logging info, plus extra values output as JSON, in the format: `<timestamp-iso-8601>\t<log-level>\t<logger>\t<message>\t{extra-values-as-json}` | ||
|
||
To configure the desired log mode, set the environment variable `LOG_MODE` to one of the supported values listed above. Default log level is `production`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.