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

Refactor Logger & add deadcode comment #51

Merged
merged 1 commit into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions navigator/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ var Logger *zap.Logger
var mu sync.Mutex

// tryLog attempts to log a message if the rate limiter allows it.
func tryLog(logFunc func(string, ...zap.Field), emoji string, context string, fields ...zap.Field) {
func tryLog(logFunc func(zapcore.Level, string, ...zap.Field), level zapcore.Level, message string, fields ...zap.Field) {
if logLimiter.Allow() {
logFunc(emoji+" "+context, fields...)
logFunc(level, message, fields...)
}
}

Expand All @@ -50,12 +50,12 @@ func LogWithEmoji(level zapcore.Level, emoji string, context string, rateLimited
return
}

if rateLimited && !logLimiter.Allow() {
return
}

message := emoji + " " + context
logByLevel(level, message, fields...)
if rateLimited {
tryLog(logByLevel, level, message, fields...)
} else {
logByLevel(level, message, fields...)
}
}

// logByLevel logs the message by the appropriate level.
Expand All @@ -78,6 +78,8 @@ func logByLevel(level zapcore.Level, message string, fields ...zap.Field) {
}

// LogInfoWithEmojiRateLimited logs an informational message with rate limiting.
//
// Note: this dead code is left here for future use.
func LogInfoWithEmojiRateLimited(emoji string, context string, fields ...zap.Field) {
LogWithEmoji(zapcore.InfoLevel, emoji, context, true, fields...)
}
Expand Down
2 changes: 2 additions & 0 deletions worker/crew.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ func resolveConflict(ctx context.Context, clientset *kubernetes.Clientset, ships
// It sends a health status message for each pod to the results channel.
// If the context is cancelled during the process, it logs the cancellation
// and sends a corresponding message through the results channel.
//
// Note: this dead code is left here for future use.
func CrewProcessPods(ctx context.Context, pods []corev1.Pod, results chan<- string) {
for _, pod := range pods {
select {
Expand Down
14 changes: 14 additions & 0 deletions worker/track_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func NewTaskStatusMap() *TaskStatusMap {
//
// Parameters:
// - task: The task to add or update in the map.
//
// Note: this deadcode is left here for future use.
func (s *TaskStatusMap) AddTask(task configuration.Task) {
s.mu.Lock()
defer s.mu.Unlock()
Expand All @@ -58,6 +60,8 @@ func (s *TaskStatusMap) AddTask(task configuration.Task) {
// Returns:
// - configuration.Task: The retrieved task.
// - bool: A boolean indicating whether the task was found in the map.
//
// Note: this deadcode is left here for future use.
func (s *TaskStatusMap) GetTask(name string) (configuration.Task, bool) {
s.mu.RLock()
defer s.mu.RUnlock()
Expand All @@ -71,6 +75,8 @@ func (s *TaskStatusMap) GetTask(name string) (configuration.Task, bool) {
//
// Parameters:
// - task: The task with updated information to be stored in the map.
//
// Note: this deadcode is left here for future use.
func (s *TaskStatusMap) UpdateTask(task configuration.Task) {
s.mu.Lock()
defer s.mu.Unlock()
Expand All @@ -83,6 +89,8 @@ func (s *TaskStatusMap) UpdateTask(task configuration.Task) {
//
// Parameters:
// - name: The name of the task to remove.
//
// Note: this deadcode is left here for future use.
func (s *TaskStatusMap) DeleteTask(name string) {
s.mu.Lock()
defer s.mu.Unlock()
Expand All @@ -100,6 +108,8 @@ func (s *TaskStatusMap) DeleteTask(name string) {
//
// Returns:
// - bool: A boolean indicating whether the task was successfully claimed.
//
// Note: this deadcode is left here for future use.
func (s *TaskStatusMap) Claim(taskName string) bool {
s.mu.Lock()
defer s.mu.Unlock()
Expand Down Expand Up @@ -129,6 +139,8 @@ func (s *TaskStatusMap) Release(taskName string) {
//
// Returns:
// - []configuration.Task: A slice containing all tasks from the tasks map.
//
// Note: this deadcode is left here for future use.
func (s *TaskStatusMap) GetAllTasks() []configuration.Task {
s.mu.RLock()
defer s.mu.RUnlock()
Expand All @@ -148,6 +160,8 @@ func (s *TaskStatusMap) GetAllTasks() []configuration.Task {
//
// Returns:
// - bool: A boolean indicating whether the task is currently claimed.
//
// Note: this deadcode is left here for future use.
func (s *TaskStatusMap) IsClaimed(taskName string) bool {
s.mu.RLock()
defer s.mu.RUnlock()
Expand Down