Skip to content

Conversation

wallrj
Copy link
Member

@wallrj wallrj commented Oct 11, 2024

No description provided.

@wallrj wallrj changed the title [VC-35738] Prototype: Use structured logging everywhere WIP: [VC-35738] Prototype: Use structured logging everywhere Oct 11, 2024
Base automatically changed from fix-gke-e2e-test to master October 11, 2024 15:15
Signed-off-by: Richard Wall <[email protected]>
Long: `The agent will periodically gather data for the configured data
gatherers and send it to a remote backend for evaluation`,
Run: agent.Run,
RunE: agent.Run,
Copy link
Member Author

Choose a reason for hiding this comment

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

I'll break this PR up in to some smaller chunks.
Changing these to RunE allows me to remove all the use of log.Fatal in the code.

Copy link
Member

Choose a reason for hiding this comment

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

This seems like a good idea.

That said, doing this will systematically show the "usage" section regardless of whether the error is due to a problem with a flag, or if the problem occurred while actually running the command... This problem is documented in spf13/cobra#340. The solution seems to be to set SilenceUsage to true on the root cobra command.

Copy link
Member Author

Choose a reason for hiding this comment

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

serverMux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
serverMux.HandleFunc("/debug/pprof/profile", pprof.Profile)
serverMux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
serverMux.HandleFunc("/debug/pprof/trace", pprof.Trace)
Copy link
Member Author

Choose a reason for hiding this comment

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

Another small PR will be to remove this extra pprof server and simply add it to the main server.

Copy link
Member Author

Choose a reason for hiding this comment

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

if err != nil && !errors.Is(err, http.ErrServerClosed) {
logs.Log.Fatalf("failed to run pprof profiler: %s", err)
}
}()
Copy link
Member Author

Choose a reason for hiding this comment

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

To remove this particular instance of log.Fatalf I need to replace these unmanaged go routines with a errgroup.Go so that I can catch the errors and return them.

Comment on lines +95 to +96
// The goal is to satisfy some Kubernetes distributions, like OpenShift,
// that require a liveness and health probe to be present for each pod.
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure what "health" probe means here.
I thought that only liveness probe was required by OpenShift?
ReadinessProbe makes no sense for venafi-kubernetes-agent.

Copy link
Member

Choose a reason for hiding this comment

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

My mistake, I confused "health probe" with "readiness probe". It should say "readiness probe" here.

group, gctx := errgroup.WithContext(ctx)

defer func() {
// TODO: replace Fatalf log calls with Errorf and return the error
Copy link
Member Author

Choose a reason for hiding this comment

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

YES!

Comment on lines +15 to +19
var Log *log.Logger

func init() {
Log = slog.NewLogLogger(slog.Default().Handler(), slog.LevelDebug)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

I can start by just doing this, I think.

Then replacing the and ultimately removing the use of Log

// Type is only used in help text
func (e *logFormat) Type() string {
return "string"
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This was copied from cert-manager/approver-policy

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.

2 participants