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

Added debug logs for render command #5328

Merged
merged 2 commits into from Feb 6, 2024

Conversation

lsviben
Copy link
Contributor

@lsviben lsviben commented Feb 2, 2024

Description of your changes

Adds debug logs to crossplane beta render.

For render the output is expected to be a valid yaml file, so we should be carefull where and when to log. Actually we dont need to do anything special as the CLI logger is already active only when --verbose flag is provider, plus it logs by default to stderr, so users can filter the command output from the logs if needed.

How it looks like:
crossplane beta render ... - no changes

crossplane beta render ... --verbose:

~/go/crossplane/_output/bin/darwin_arm64/crank beta render example/inline/xr.yaml example/inline/composition.yaml example/inline/functions.yaml --verbose
2024-02-02T12:44:53+01:00	DEBUG	Starting Docker container runtime	{"image": "xpkg.upbound.io/crossplane-contrib/function-go-templating:v0.4.0"}
2024-02-02T12:44:53+01:00	DEBUG	Creating Docker container	{"image": "xpkg.upbound.io/crossplane-contrib/function-go-templating:v0.4.0", "address": "127.0.0.1:54299"}
2024-02-02T12:44:55+01:00	DEBUG	Container left running	{"container": "80dd5af1330130f12abe20acb273f4520b8dd2174f267b41b66b30a769faec6d", "image": "xpkg.upbound.io/crossplane-contrib/function-go-templating:v0.4.0"}
---
apiVersion: example.crossplane.io/v1beta1
kind: XR
metadata:
  name: example
...

crossplane beta render ... --verbose 2>

~/go/crossplane/_output/bin/darwin_arm64/crank beta render example/inline/xr.yaml example/inline/composition.yaml example/inline/functions.yaml --verbose 2> echo
---
apiVersion: example.crossplane.io/v1beta1
kind: XR
metadata:
  name: example
status:
  dummy: cool-status
---
...

crossplane beta render ... --verbose 1>

~/go/crossplane/_output/bin/darwin_arm64/crank beta render example/inline/xr.yaml example/inline/composition.yaml example/inline/functions.yaml --verbose 1> echo
2024-02-02T12:44:53+01:00	DEBUG	Starting Docker container runtime	{"image": "xpkg.upbound.io/crossplane-contrib/function-go-templating:v0.4.0"}
2024-02-02T10:48:59+01:00	DEBUG	Creating Docker container	{"image": "xpkg.upbound.io/crossplane-contrib/function-go-templating:v0.4.0", "address": "127.0.0.1:53294"}
2024-02-02T10:48:59+01:00	DEBUG	Image not found, pulling	{"image": "xpkg.upbound.io/crossplane-contrib/function-go-templating:v0.4.0"}
2024-02-02T10:49:03+01:00	DEBUG	Container left running	{"container": "caeb76d7b427194a148b3af42191ee1c9bf90c59231c9b49f938bcab45c34e90", "image": "xpkg.upbound.io/crossplane-contrib/function-go-templating:v0.4.0"}

Fixes #4809

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable to ensure this PR is ready for review.
  • [] Added or updated unit tests.
  • [] Added or updated e2e tests.
  • [] Linked a PR or a docs tracking issue to document this change.
  • [] Added backport release-x.y labels to auto-backport this PR.

Need help with this checklist? See the cheat sheet.

@lsviben lsviben requested review from phisco and a team as code owners February 2, 2024 10:12
@lsviben lsviben requested a review from bobh66 February 2, 2024 10:12
@lsviben
Copy link
Contributor Author

lsviben commented Feb 2, 2024

Added logs in just a few places around pulling and starting functions.

I am not that familiar with the render code so feel free to reccomend other places where its useful. Ill go through it as well myself.

Signed-off-by: lsviben <sviben.lovro@gmail.com>
Signed-off-by: lsviben <sviben.lovro@gmail.com>
Copy link
Contributor

@phisco phisco left a comment

Choose a reason for hiding this comment

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

LGTM thanks @lsviben!

@phisco phisco requested a review from negz February 2, 2024 13:57
Copy link
Member

@negz negz left a comment

Choose a reason for hiding this comment

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

Just a few nits, but looks good to me. Thank you! Feel free to take or leave any of the suggestions.

// Run our Functions.
conns := map[string]*grpc.ClientConn{}
for _, fn := range in.Functions {
runtime, err := GetRuntime(fn)
if err != nil {
return Outputs{}, errors.Wrapf(err, "cannot get runtime for Function %q", fn.GetName())
}
rctx, err := runtime.Start(ctx)
rctx, err := runtime.Start(ctx, logger)
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to pass the logger in GetRuntime? So it would be a field of the runtime struct rather than an argument to the Start method?

@@ -49,7 +50,7 @@ const (
// A Runtime runs a Function.
type Runtime interface {
// Start the Function.
Start(ctx context.Context) (RuntimeContext, error)
Start(ctx context.Context, logger logging.Logger) (RuntimeContext, error)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Start(ctx context.Context, logger logging.Logger) (RuntimeContext, error)
Start(ctx context.Context, l logging.Logger) (RuntimeContext, error)

Nit. Or log if l is too short, but "logger logging logger" stutters a lot. 😄 In other contexts I can live with it because the logger variable tends to live for a lot of lines (you can't always easily see what it is from its type). Maybe log everywhere would be a good compromise though? 🤔

@phisco
Copy link
Contributor

phisco commented Feb 6, 2024

@lsviben I'm going to merge this so that it's in the first RC for 1.15, feel free to address the nits above in a follow up PR.

@phisco phisco merged commit 4184da0 into crossplane:master Feb 6, 2024
17 checks passed
Copy link

github-actions bot commented Feb 6, 2024

Backport failed for release-1.15: couldn't find remote ref release-1.15.
Please ensure that this Github repo has a branch named release-1.15.

@lsviben lsviben mentioned this pull request Feb 13, 2024
3 tasks
@lsviben
Copy link
Contributor Author

lsviben commented Feb 13, 2024

@lsviben I'm going to merge this so that it's in the first RC for 1.15, feel free to address the nits above in a follow up PR.

Follow up PR: #5384

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Have crossplane beta render emit debug logs
3 participants