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 [Navigator] Logger #27

Merged
merged 2 commits into from
Dec 23, 2023
Merged

Refactor [Navigator] Logger #27

merged 2 commits into from
Dec 23, 2023

Conversation

H0llyW00dzZ
Copy link
Owner

No description provided.

- [+] feat(init_const.go): add constant for unsupported log level message
- [+] feat(navigator): add rate limiter for log output
- [+] fix(navigator): change log level for error messages to info level
@H0llyW00dzZ
Copy link
Owner Author

Perfect Structured logging

$ go run debug.go
2023-12-24T01:02:58.903+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Fetching pods     {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 1"}
2023-12-24T01:02:58.903+0700    INFO    navigator/logger.go:38  🏴‍☠️  invalid parameters       {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 1"}
2023-12-24T01:02:58.904+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Retrying task 1/3 {"sailing": "FetchPods", "shipsnamespace": "default", "crew_worker": 0, "attempt": 1, "max_retries": 3, "task_name": "c check pods running 1"}
2023-12-24T01:02:58.904+0700    INFO    navigator/logger.go:38  ❌ Error during task, attempt 1/3: invalid parameters: labelSelector, fieldSelector, or limit   {"task_name": "check pods running 1", "error": "invalid parameters: labelSelector, fieldSelector, or limit"}
2023-12-24T01:03:00.905+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Fetching pods     {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 1"}
2023-12-24T01:03:00.905+0700    INFO    navigator/logger.go:38  🏴‍☠️  invalid parameters       {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 1"}
2023-12-24T01:03:00.905+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Retrying task 2/3 {"sailing": "FetchPods", "shipsnamespace": "default", "crew_worker": 0, "attempt": 2, "max_retries": 3, "task_name": "c check pods running 1"}
2023-12-24T01:03:00.905+0700    INFO    navigator/logger.go:38  ❌ Error during task, attempt 2/3: invalid parameters: labelSelector, fieldSelector, or limit   {"task_name": "check pods running 1", "error": "invalid parameters: labelSelector, fieldSelector, or limit"}
2023-12-24T01:03:02.915+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Fetching pods     {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 1"}
2023-12-24T01:03:02.915+0700    INFO    navigator/logger.go:38  🏴‍☠️  invalid parameters       {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 1"}
2023-12-24T01:03:02.915+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Retrying task 3/3 {"sailing": "FetchPods", "shipsnamespace": "default", "crew_worker": 0, "attempt": 3, "max_retries": 3, "task_name": "c check pods running 1"}
2023-12-24T01:03:02.915+0700    INFO    navigator/logger.go:38  ❌ Error during task, attempt 3/3: invalid parameters: labelSelector, fieldSelector, or limit   {"task_name": "check pods running 1", "error": "invalid parameters: labelSelector, fieldSelector, or limit"}
2023-12-24T01:03:04.917+0700    INFO    navigator/logger.go:38  ❌ Failed to complete task check pods running 1 after 3 attempts        {"ships_namespace": "default", "task_name": "check pods running 1", "error": "Failed to complete task check pods running 1 after 3 attempts"}
2023-12-24T01:03:04.917+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Fetching pods     {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 2"}
2023-12-24T01:03:04.917+0700    INFO    K8sBlackPearl/debug.go:104      Received result: Failed to complete task check pods running 1 after 3 attempts
2023-12-24T01:03:04.917+0700    INFO    navigator/logger.go:38  🏴‍☠️  invalid parameters       {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 2"}
2023-12-24T01:03:04.917+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Retrying task 1/3 {"sailing": "FetchPods", "shipsnamespace": "default", "crew_worker": 0, "attempt": 1, "max_retries": 3, "task_name": "c check pods running 2"}
2023-12-24T01:03:04.917+0700    INFO    navigator/logger.go:38  ❌ Error during task, attempt 1/3: invalid parameters: labelSelector, fieldSelector, or limit   {"task_name": "check pods running 2", "error": "invalid parameters: labelSelector, fieldSelector, or limit"}
2023-12-24T01:03:06.921+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Fetching pods     {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 2"}
2023-12-24T01:03:06.921+0700    INFO    navigator/logger.go:38  🏴‍☠️  invalid parameters       {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 2"}
2023-12-24T01:03:06.921+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Retrying task 2/3 {"sailing": "FetchPods", "shipsnamespace": "default", "crew_worker": 0, "attempt": 2, "max_retries": 3, "task_name": "c check pods running 2"}
2023-12-24T01:03:06.921+0700    INFO    navigator/logger.go:38  ❌ Error during task, attempt 2/3: invalid parameters: labelSelector, fieldSelector, or limit   {"task_name": "check pods running 2", "error": "invalid parameters: labelSelector, fieldSelector, or limit"}
2023-12-24T01:03:08.927+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Fetching pods     {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 2"}
2023-12-24T01:03:08.927+0700    INFO    navigator/logger.go:38  🏴‍☠️  invalid parameters       {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 2"}
2023-12-24T01:03:08.927+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Retrying task 3/3 {"sailing": "FetchPods", "shipsnamespace": "default", "crew_worker": 0, "attempt": 3, "max_retries": 3, "task_name": "c check pods running 2"}
2023-12-24T01:03:08.927+0700    INFO    navigator/logger.go:38  ❌ Error during task, attempt 3/3: invalid parameters: labelSelector, fieldSelector, or limit   {"task_name": "check pods running 2", "error": "invalid parameters: labelSelector, fieldSelector, or limit"}
2023-12-24T01:03:10.935+0700    INFO    navigator/logger.go:38  ❌ Failed to complete task check pods running 2 after 3 attempts        {"ships_namespace": "default", "task_name": "check pods running 2", "error": "Failed to complete task check pods running 2 after 3 attempts"}
2023-12-24T01:03:10.935+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Fetching pods     {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 3"}
2023-12-24T01:03:10.936+0700    INFO    navigator/logger.go:38  🏴‍☠️  invalid parameters       {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 3"}
2023-12-24T01:03:10.935+0700    INFO    K8sBlackPearl/debug.go:104      Received result: Failed to complete task check pods running 2 after 3 attempts
2023-12-24T01:03:10.936+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Retrying task 1/3 {"sailing": "FetchPods", "shipsnamespace": "default", "crew_worker": 0, "attempt": 1, "max_retries": 3, "task_name": "c check pods running 3"}
2023-12-24T01:03:10.936+0700    INFO    navigator/logger.go:38  ❌ Error during task, attempt 1/3: invalid parameters: labelSelector, fieldSelector, or limit   {"task_name": "check pods running 3", "error": "invalid parameters: labelSelector, fieldSelector, or limit"}
2023-12-24T01:03:12.941+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Fetching pods     {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 3"}
2023-12-24T01:03:12.941+0700    INFO    navigator/logger.go:38  🏴‍☠️  invalid parameters       {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 3"}
2023-12-24T01:03:12.941+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Retrying task 2/3 {"sailing": "FetchPods", "shipsnamespace": "default", "crew_worker": 0, "attempt": 2, "max_retries": 3, "task_name": "c check pods running 3"}
2023-12-24T01:03:12.941+0700    INFO    navigator/logger.go:38  ❌ Error during task, attempt 2/3: invalid parameters: labelSelector, fieldSelector, or limit   {"task_name": "check pods running 3", "error": "invalid parameters: labelSelector, fieldSelector, or limit"}
2023-12-24T01:03:14.945+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Fetching pods     {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 3"}
2023-12-24T01:03:14.945+0700    INFO    navigator/logger.go:38  🏴‍☠️  invalid parameters       {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 3"}
2023-12-24T01:03:14.945+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Retrying task 3/3 {"sailing": "FetchPods", "shipsnamespace": "default", "crew_worker": 0, "attempt": 3, "max_retries": 3, "task_name": "c check pods running 3"}
2023-12-24T01:03:14.945+0700    INFO    navigator/logger.go:38  ❌ Error during task, attempt 3/3: invalid parameters: labelSelector, fieldSelector, or limit   {"task_name": "check pods running 3", "error": "invalid parameters: labelSelector, fieldSelector, or limit"}
2023-12-24T01:03:16.949+0700    INFO    navigator/logger.go:38  ❌ Failed to complete task check pods running 3 after 3 attempts        {"ships_namespace": "default", "task_name": "check pods running 3", "error": "Failed to complete task check pods running 3 after 3 attempts"}
2023-12-24T01:03:16.949+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Fetching pods     {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 4"}
2023-12-24T01:03:16.949+0700    INFO    K8sBlackPearl/debug.go:104      Received result: Failed to complete task check pods running 3 after 3 attempts
2023-12-24T01:03:16.949+0700    INFO    navigator/logger.go:38  🏴‍☠️  invalid parameters       {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 4"}
2023-12-24T01:03:16.950+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Retrying task 1/3 {"sailing": "FetchPods", "shipsnamespace": "default", "crew_worker": 0, "attempt": 1, "max_retries": 3, "task_name": "c check pods running 4"}
2023-12-24T01:03:16.950+0700    INFO    navigator/logger.go:38  ❌ Error during task, attempt 1/3: invalid parameters: labelSelector, fieldSelector, or limit   {"task_name": "check pods running 4", "error": "invalid parameters: labelSelector, fieldSelector, or limit"}
2023-12-24T01:03:18.954+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Fetching pods     {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 4"}
2023-12-24T01:03:18.954+0700    INFO    navigator/logger.go:38  🏴‍☠️  invalid parameters       {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 4"}
2023-12-24T01:03:18.954+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Retrying task 2/3 {"sailing": "FetchPods", "shipsnamespace": "default", "crew_worker": 0, "attempt": 2, "max_retries": 3, "task_name": "c check pods running 4"}
2023-12-24T01:03:18.955+0700    INFO    navigator/logger.go:38  ❌ Error during task, attempt 2/3: invalid parameters: labelSelector, fieldSelector, or limit   {"task_name": "check pods running 4", "error": "invalid parameters: labelSelector, fieldSelector, or limit"}
2023-12-24T01:03:20.963+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Fetching pods     {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 4"}
2023-12-24T01:03:20.963+0700    INFO    navigator/logger.go:38  🏴‍☠️  invalid parameters       {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 4"}
2023-12-24T01:03:20.963+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Retrying task 3/3 {"sailing": "FetchPods", "shipsnamespace": "default", "crew_worker": 0, "attempt": 3, "max_retries": 3, "task_name": "c check pods running 4"}
2023-12-24T01:03:20.964+0700    INFO    navigator/logger.go:38  ❌ Error during task, attempt 3/3: invalid parameters: labelSelector, fieldSelector, or limit   {"task_name": "check pods running 4", "error": "invalid parameters: labelSelector, fieldSelector, or limit"}
2023-12-24T01:03:22.974+0700    INFO    navigator/logger.go:38  ❌ Failed to complete task check pods running 4 after 3 attempts        {"ships_namespace": "default", "task_name": "check pods running 4", "error": "Failed to complete task check pods running 4 after 3 attempts"}
2023-12-24T01:03:22.974+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Fetching pods     {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 5"}
2023-12-24T01:03:22.974+0700    INFO    K8sBlackPearl/debug.go:104      Received result: Failed to complete task check pods running 4 after 3 attempts
2023-12-24T01:03:22.975+0700    INFO    navigator/logger.go:38  🏴‍☠️  invalid parameters       {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 5"}
2023-12-24T01:03:22.975+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Retrying task 1/3 {"sailing": "FetchPods", "shipsnamespace": "default", "crew_worker": 0, "attempt": 1, "max_retries": 3, "task_name": "c check pods running 5"}
2023-12-24T01:03:24.983+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Fetching pods     {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 5"}
2023-12-24T01:03:24.983+0700    INFO    navigator/logger.go:38  🏴‍☠️  invalid parameters       {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 5"}
2023-12-24T01:03:24.983+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Retrying task 2/3 {"sailing": "FetchPods", "shipsnamespace": "default", "crew_worker": 0, "attempt": 2, "max_retries": 3, "task_name": "c check pods running 5"}
2023-12-24T01:03:24.984+0700    INFO    navigator/logger.go:38  ❌ Error during task, attempt 2/3: invalid parameters: labelSelector, fieldSelector, or limit   {"task_name": "check pods running 5", "error": "invalid parameters: labelSelector, fieldSelector, or limit"}
2023-12-24T01:03:26.997+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Fetching pods     {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 5"}
2023-12-24T01:03:26.997+0700    INFO    navigator/logger.go:38  🏴‍☠️  invalid parameters       {"sailing": "FetchPods", "shipsnamespace": "default", "task_name": "check pods running 5"}
2023-12-24T01:03:26.997+0700    INFO    navigator/logger.go:38  🏴‍☠️  Crew Worker 0: Retrying task 3/3 {"sailing": "FetchPods", "shipsnamespace": "default", "crew_worker": 0, "attempt": 3, "max_retries": 3, "task_name": "c check pods running 5"}
2023-12-24T01:03:26.997+0700    INFO    navigator/logger.go:38  ❌ Error during task, attempt 3/3: invalid parameters: labelSelector, fieldSelector, or limit   {"task_name": "check pods running 5", "error": "invalid parameters: labelSelector, fieldSelector, or limit"}
2023-12-24T01:03:29.008+0700    INFO    navigator/logger.go:38  ❌ Failed to complete task check pods running 5 after 3 attempts        {"ships_namespace": "default", "task_name": "check pods running 5", "error": "Failed to complete task check pods running 5 after 3 attempts"}
2023-12-24T01:03:29.009+0700    INFO    K8sBlackPearl/debug.go:104      Received result: Failed to complete task check pods running 5 after 3 attempts

@H0llyW00dzZ H0llyW00dzZ merged commit 96cb1aa into master Dec 23, 2023
2 checks passed
@H0llyW00dzZ H0llyW00dzZ deleted the logger branch December 23, 2023 18:20
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.

1 participant