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

chore: Consistent/Improved logging #152

Merged
merged 2 commits into from
Jun 5, 2024

Conversation

mikenairn
Copy link
Member

@mikenairn mikenairn commented Jun 4, 2024

closes #124

external-dns: Remove logrus logger

Removes the use of logrus in all external-dns code in favour of setting a logr.Logger on all objects.

Constructors are used throughout to create new instances of components (plan, registry and providers), with each requiring the current context, retrieving a logger instance from it with an appropriate logger name added where required.

chore: Consistent/Improved logging

Construct logger in Reconcile functions (DNSRecord and ManagedZone), naming each appropriately, and ensure it is used by all logging statements throughout the call stack for the request.

Initialise external-dns components (registry, plan and providers) using correct context to ensure the appropriate logger is used internally. Removes all references to logrus logger.

Removes the use of logrus in all external-dns code in favour of setting
a `logr.Logger` on all structs.

Constructors are used throughout to create new instances of components
(plan, registry and providers), with each requiring the current context
and a logger instance retrieved from it with an appropriate logger name
added where required.
@@ -156,7 +157,7 @@ func (r *ManagedZoneReconciler) Reconcile(ctx context.Context, req ctrl.Request)
if err != nil {
return ctrl.Result{}, err
}
log.Log.Info("Reconciled ManagedZone", "managedZone", managedZone.Name)
logger.Info("Reconciled ManagedZone")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't we need the managedzone name here, but we do need it in some of the others?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

@mikenairn mikenairn Jun 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't, will update those to remove the duplicate key/values

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should all be updated now to remove adding the details of the current resource at individual log statements. That is already being done as part of the logger setup in Reconcile. Further improvements to the logging and what metadata is included and where will be done as part of #118

Construct logger in Reconcile function (DNSRecord and ManagedZone),
naming each appropriately, and ensure it is used by all logging
statements throughout the call stack for the request.

Initialise external-dns components (registry, plan and providers) using
correct context to ensure the appropriate logger is used internally.
Removes all references to logrus logger.
return false, nil
}
return false, err
}
logger.Info("Deleted DNSRecord in manage zone", "dnsRecord", dnsRecord.Name, "managedZone", managedZone.Name)
logger.Info("Deleted DNSRecord in manage zone", "managedZone", managedZone.Name)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example:

{
  "level": "info",
  "ts": "2024-06-04T16:32:37+01:00",
  "logger": "dnsrecord_controller",
  "msg": "Deleted DNSRecord in manage zone",
  "controller": "dnsrecord",
  "controllerGroup": "kuadrant.io",
  "controllerKind": "DNSRecord",
  "DNSRecord": {
    "name": "t-single-lively-waterfall",
    "namespace": "dnstest"
  },
  "namespace": "dnstest",
  "name": "t-single-lively-waterfall",
  "reconcileID": "81a1838b-c782-4323-8baf-58486cadbcec",
  "managedZone": "dev-mz-aws"
}

Left managedZone here for now although i expect that will be moved and set on the context higher up the stack as part of #117

@mikenairn mikenairn added this pull request to the merge queue Jun 5, 2024
Merged via the queue into Kuadrant:main with commit 82a6451 Jun 5, 2024
11 checks passed
@mikenairn mikenairn deleted the logging_updates branch June 5, 2024 10:07
@mikenairn mikenairn mentioned this pull request Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update logging of external-dns code
2 participants