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

Add pkg/log package and cleanup logging around the codebase #544

Merged
merged 7 commits into from
Jul 15, 2024

Conversation

neoaggelos
Copy link
Contributor

Summary

Add pkg/log with a standard logging interface and document how we should create logs across the codebase.

Start from https://github.com/canonical/k8s-snap/compare/KU-1080/logging?expand=1#diff-3e6c5854477b8113c122f67474e7fba607496ef206b4a2a0761cdde6cc26b9b9

Replace usage of the standard library "log" with pkg/log

Notes

This is pre-requisite work for the CSRSigning controller for certificate refreshes.

@neoaggelos neoaggelos requested a review from a team as a code owner July 14, 2024 18:31
actionConfig := new(action.Configuration)

if err := actionConfig.Init(h.restClientGetter(namespace), namespace, "", log.Printf); err != nil {
log := log.FromContext(ctx).WithName("helm")
Copy link
Contributor

Choose a reason for hiding this comment

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

Neat!

}

} else if node, err := nodeutil.GetControlPlaneNode(ctx, s, s.Name()); err != nil {
clusterRole = apiv1.ClusterRoleUnknown
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the log here no longer necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, removed log lines that did not provide any useful context here and in some other places

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bschimke95 is this useful to keep around?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would keep around the comment on when this might happen. Let's remove the logs though.

Copy link
Contributor

@bschimke95 bschimke95 left a comment

Choose a reason for hiding this comment

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

LGTM, minor comments.
Great work!

src/k8s/pkg/k8sd/api/cluster_remove.go Show resolved Hide resolved
@@ -58,6 +58,8 @@ func (c *UpdateNodeConfigurationController) retryNewK8sClient(ctx context.Contex
func (c *UpdateNodeConfigurationController) Run(ctx context.Context, getClusterConfig func(context.Context) (types.ClusterConfig, error)) {
c.waitReady()

log := log.FromContext(ctx).WithValues("controller", "updatenodeconfiguration")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: snake case update_node_configuration would probably be easier to read.

continue
case len(newEndpoints) == 0:
log.Println("warning: empty list of endpoints, skipping update")
log.Info("Warning: empty list of endpoints, skipping update")
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be a warning level message instead of prefix this with "Warning"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Logs are either .Info() (with log levels) or .Error() (always printed)

@@ -41,10 +42,15 @@ func startProxy(ctx context.Context, listenURL string, endpointURLs []string) er
MonitorInterval: time.Minute,
}

log.Println("Starting proxy at", listenURL)
log := log.FromContext(ctx).WithValues(
Copy link
Contributor

Choose a reason for hiding this comment

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

This is nice!

Copy link
Contributor

@louiseschmidtgen louiseschmidtgen left a comment

Choose a reason for hiding this comment

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

Great work, loving the improvement on our logs :)

@neoaggelos neoaggelos merged commit a3d112a into main Jul 15, 2024
18 checks passed
@neoaggelos neoaggelos deleted the KU-1080/logging branch July 15, 2024 12:06
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.

3 participants