Skip to content

Fix logs operator command, prevent aborting streaming after 30s#14

Open
mclasmeier wants to merge 2 commits into
mainfrom
mc/operator-logs
Open

Fix logs operator command, prevent aborting streaming after 30s#14
mclasmeier wants to merge 2 commits into
mainfrom
mc/operator-logs

Conversation

@mclasmeier
Copy link
Copy Markdown
Collaborator

As a prerequisite, the first commit changes the codebase to leverage a Logger interface.

Before:
image

After:
image
Doesn't terminate after 30s.

If the cluster cannot be reached, we fail early:
image

Comment thread internal/logger/logger.go
// New creates a new Logger instance
func New() *Logger {
return &Logger{
type LoggerImpl struct {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this type needs to be exported, even if returned by another exported function.

Comment thread internal/logger/logger.go
// getTimestamp returns the elapsed time since logger creation in MM:SS format
func (l *Logger) getTimestamp() string {
// NewWithTimestamps creates a new Logger instance with timestamps.
func NewWithTimestamps() *LoggerImpl {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are we reinventing the wheel here instead of using one of the many logging libraries available?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This logger provides a high-level logging interface specifically built for the different messaging and formatting styles (colors, timestamps, etc.) for the roxie UX.
Do you think this would be a use-case for relying on a standard logger?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't know, are you saying there are no loggers out there which support timestamps and colors? 🤔

Comment thread cmd/logs.go

// Create kubectl command with context
kubectlCmd := exec.CommandContext(ctx, "kubectl", kubectlArgs...)
// Create kubectl command without context - allows indefinite streaming.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't we use a context with cancel instead and call defer cancel() here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

You mean something like context.Background()? What would be the advantage over not providing a context?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I meant background wrapped in https://pkg.go.dev/context#WithCancel
Or is it not worth bothering to cancel() because the only way to exit is to die anway?

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