-
Notifications
You must be signed in to change notification settings - Fork 0
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
docs(README.md): Add Middleware section with details on new middlewares. #51
Conversation
…Overlapping Middleware
Warning Rate limit exceeded@flc1125 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 28 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughThe changes in this pull request involve modifications to several files, primarily focusing on the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## 4.x #51 +/- ##
=======================================
Coverage 95.53% 95.53%
=======================================
Files 17 17
Lines 874 874
=======================================
Hits 835 835
Misses 33 33
Partials 6 6 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🧹 Outside diff range and nitpick comments (1)
middleware/distributednooverlapping/README.md (1)
35-37
: Document mutex TTL considerationsThe comment about TTL should be expanded to explain the implications.
Add a note explaining:
// The mutex TTL should be set carefully: // 1. Too short: Job might be executed multiple times if it runs longer than TTL // 2. Too long: If the process crashes, the lock might prevent other instances from running the job // // Recommended: Set TTL to (expected_job_duration * 2) + buffer_time🧰 Tools
🪛 Markdownlint (0.35.0)
36-36: Column: 1
Hard tabs(MD010, no-hard-tabs)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (9)
.gitignore
(1 hunks)README.md
(1 hunks)_example/entry/context/main.go
(0 hunks)_example/entry/middleware/main.go
(0 hunks)_example/middleware/delayoverlapping/main.go
(0 hunks)_example/middleware/nooverlapping/main.go
(0 hunks)_example/middleware/recovery/main.go
(0 hunks)_example/readme/main.go
(0 hunks)middleware/distributednooverlapping/README.md
(1 hunks)
💤 Files with no reviewable changes (6)
- _example/readme/main.go
- _example/middleware/delayoverlapping/main.go
- _example/entry/middleware/main.go
- _example/entry/context/main.go
- _example/middleware/nooverlapping/main.go
- _example/middleware/recovery/main.go
✅ Files skipped from review due to trivial changes (1)
- .gitignore
🧰 Additional context used
🪛 Markdownlint (0.35.0)
middleware/distributednooverlapping/README.md
11-11: Column: 1
Hard tabs
(MD010, no-hard-tabs)
12-12: Column: 1
Hard tabs
(MD010, no-hard-tabs)
13-13: Column: 1
Hard tabs
(MD010, no-hard-tabs)
14-14: Column: 1
Hard tabs
(MD010, no-hard-tabs)
16-16: Column: 1
Hard tabs
(MD010, no-hard-tabs)
17-17: Column: 1
Hard tabs
(MD010, no-hard-tabs)
18-18: Column: 1
Hard tabs
(MD010, no-hard-tabs)
19-19: Column: 1
Hard tabs
(MD010, no-hard-tabs)
23-23: Column: 1
Hard tabs
(MD010, no-hard-tabs)
27-27: Column: 1
Hard tabs
(MD010, no-hard-tabs)
28-28: Column: 1
Hard tabs
(MD010, no-hard-tabs)
32-32: Column: 1
Hard tabs
(MD010, no-hard-tabs)
36-36: Column: 1
Hard tabs
(MD010, no-hard-tabs)
40-40: Column: 1
Hard tabs
(MD010, no-hard-tabs)
41-41: Column: 1
Hard tabs
(MD010, no-hard-tabs)
42-42: Column: 1
Hard tabs
(MD010, no-hard-tabs)
46-46: Column: 1
Hard tabs
(MD010, no-hard-tabs)
47-47: Column: 1
Hard tabs
(MD010, no-hard-tabs)
48-48: Column: 1
Hard tabs
(MD010, no-hard-tabs)
50-50: Column: 1
Hard tabs
(MD010, no-hard-tabs)
52-52: Column: 1
Hard tabs
(MD010, no-hard-tabs)
53-53: Column: 1
Hard tabs
(MD010, no-hard-tabs)
54-54: Column: 1
Hard tabs
(MD010, no-hard-tabs)
55-55: Column: 1
Hard tabs
(MD010, no-hard-tabs)
56-56: Column: 1
Hard tabs
(MD010, no-hard-tabs)
58-58: Column: 1
Hard tabs
(MD010, no-hard-tabs)
59-59: Column: 1
Hard tabs
(MD010, no-hard-tabs)
61-61: Column: 1
Hard tabs
(MD010, no-hard-tabs)
62-62: Column: 1
Hard tabs
(MD010, no-hard-tabs)
64-64: Column: 1
Hard tabs
(MD010, no-hard-tabs)
_, _ = c.AddJob("* * * * * *", &basicJob{"one"}) | ||
_, _ = c.AddJob("* * * * * *", &basicJob{"two"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling for job registration
The example ignores potential errors when adding jobs.
-_, _ = c.AddJob("* * * * * *", &basicJob{"one"})
-_, _ = c.AddJob("* * * * * *", &basicJob{"two"})
+if _, err := c.AddJob("* * * * * *", &basicJob{"one"}); err != nil {
+ log.Fatal("Failed to add job one:", err)
+}
+if _, err := c.AddJob("* * * * * *", &basicJob{"two"}); err != nil {
+ log.Fatal("Failed to add job two:", err)
+}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
_, _ = c.AddJob("* * * * * *", &basicJob{"one"}) | |
_, _ = c.AddJob("* * * * * *", &basicJob{"two"}) | |
if _, err := c.AddJob("* * * * * *", &basicJob{"one"}); err != nil { | |
log.Fatal("Failed to add job one:", err) | |
} | |
if _, err := c.AddJob("* * * * * *", &basicJob{"two"}); err != nil { | |
log.Fatal("Failed to add job two:", err) | |
} |
🧰 Tools
🪛 Markdownlint (0.35.0)
58-58: Column: 1
Hard tabs
(MD010, no-hard-tabs)
59-59: Column: 1
Hard tabs
(MD010, no-hard-tabs)
rdb := redis.NewClient(&redis.Options{ | ||
Addr: "localhost:6379", | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling for Redis connection
The example should demonstrate proper error handling for production use.
rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
})
+
+if err := rdb.Ping(context.Background()).Err(); err != nil {
+ log.Fatal("Failed to connect to Redis:", err)
+}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
rdb := redis.NewClient(&redis.Options{ | |
Addr: "localhost:6379", | |
}) | |
rdb := redis.NewClient(&redis.Options{ | |
Addr: "localhost:6379", | |
}) | |
if err := rdb.Ping(context.Background()).Err(); err != nil { | |
log.Fatal("Failed to connect to Redis:", err) | |
} |
🧰 Tools
🪛 Markdownlint (0.35.0)
46-46: Column: 1
Hard tabs
(MD010, no-hard-tabs)
47-47: Column: 1
Hard tabs
(MD010, no-hard-tabs)
48-48: Column: 1
Hard tabs
(MD010, no-hard-tabs)
…Overlapping Middleware
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (8)
middleware/otel/README.md (5)
1-3
: Fix grammatical error in the introductionThere's a grammatical error in the middleware description.
-The `otel` is a middleware for that provides observability with OpenTelemetry. +The `otel` middleware provides observability with OpenTelemetry.
33-36
: Add meaningful implementation in Run methodThe current Run method contains a placeholder comment without actual implementation. Consider adding a realistic example that demonstrates how tracing works with a real task.
func (b *basicJob) Run(ctx context.Context) error { - // do something + // Simulate some work that can be traced + time.Sleep(100 * time.Millisecond) + fmt.Println("Job executed:", time.Now()) return nil }🧰 Tools
🪛 Markdownlint (0.35.0)
34-34: Column: 1
Hard tabs(MD010, no-hard-tabs)
35-35: Column: 1
Hard tabs(MD010, no-hard-tabs)
39-41
: Add explanatory comments for OpenTelemetry setupThe OpenTelemetry configuration could benefit from more detailed comments explaining the purpose of each component.
- // configure otel, the following is just a demonstration provider. + // Configure OpenTelemetry with an in-memory exporter for demonstration + // In production, you would typically use an exporter that sends data + // to your observability backend (e.g., Jaeger, Zipkin) imsb := tracetest.NewInMemoryExporter() tp := trace.NewTracerProvider(trace.WithSyncer(imsb))🧰 Tools
🪛 Markdownlint (0.35.0)
39-39: Column: 1
Hard tabs(MD010, no-hard-tabs)
40-40: Column: 1
Hard tabs(MD010, no-hard-tabs)
41-41: Column: 1
Hard tabs(MD010, no-hard-tabs)
54-55
: Add explanation for the sleep durationThe purpose of the sleep duration should be explained to help readers understand the example better.
+ // Wait for 10 seconds to collect some spans for demonstration time.Sleep(10 * time.Second) fmt.Println("spans:", len(imsb.GetSpans()))
🧰 Tools
🪛 Markdownlint (0.35.0)
54-54: Column: 1
Hard tabs(MD010, no-hard-tabs)
55-55: Column: 1
Hard tabs(MD010, no-hard-tabs)
59-63
: Add context to the output sectionThe output section would be more helpful with an explanation of what the spans represent and how they relate to the job execution.
output: ```shell +# Shows the number of spans collected over 10 seconds +# (1 span per second due to the "* * * * * *" schedule) spans: 10</blockquote></details> <details> <summary>middleware/distributednooverlapping/README.md (3)</summary><blockquote> `16-20`: **Document version requirements** Please add version requirements for the dependencies: - Minimum required version of `go-cron` - Compatible Redis versions - Go version requirements <details> <summary>🧰 Tools</summary> <details> <summary>🪛 Markdownlint (0.35.0)</summary> 16-16: Column: 1 Hard tabs (MD010, no-hard-tabs) --- 17-17: Column: 1 Hard tabs (MD010, no-hard-tabs) --- 18-18: Column: 1 Hard tabs (MD010, no-hard-tabs) --- 19-19: Column: 1 Hard tabs (MD010, no-hard-tabs) </details> </details> --- `35-37`: **Review mutex TTL duration** The current TTL of 60 hours seems excessive for a job that runs every second and takes 1 second to complete. Consider reducing the TTL to a more reasonable duration: ```diff -func (j *basicJob) GetMutexTTL() time.Duration { - return time.Hour * 60 // the ttl suggests greater than the running time of the job -} +func (j *basicJob) GetMutexTTL() time.Duration { + return time.Second * 5 // 5x the expected running time for safety +}
🧰 Tools
🪛 Markdownlint (0.35.0)
36-36: Column: 1
Hard tabs(MD010, no-hard-tabs)
68-76
: Add explanation for the example outputThe output section would be more helpful with explanations of:
- Why certain jobs run at specific times
- How the distributed locking prevents overlap
- What the timing patterns indicate
Add explanatory text before the output:
The output below demonstrates: - Jobs running sequentially without overlap - Distributed locking ensuring only one instance runs at a time - Alternating execution between job instances
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
middleware/distributednooverlapping/README.md
(1 hunks)middleware/otel/README.md
(1 hunks)
🧰 Additional context used
🪛 Markdownlint (0.35.0)
middleware/distributednooverlapping/README.md
11-11: Column: 1
Hard tabs
(MD010, no-hard-tabs)
12-12: Column: 1
Hard tabs
(MD010, no-hard-tabs)
13-13: Column: 1
Hard tabs
(MD010, no-hard-tabs)
14-14: Column: 1
Hard tabs
(MD010, no-hard-tabs)
16-16: Column: 1
Hard tabs
(MD010, no-hard-tabs)
17-17: Column: 1
Hard tabs
(MD010, no-hard-tabs)
18-18: Column: 1
Hard tabs
(MD010, no-hard-tabs)
19-19: Column: 1
Hard tabs
(MD010, no-hard-tabs)
23-23: Column: 1
Hard tabs
(MD010, no-hard-tabs)
27-27: Column: 1
Hard tabs
(MD010, no-hard-tabs)
28-28: Column: 1
Hard tabs
(MD010, no-hard-tabs)
32-32: Column: 1
Hard tabs
(MD010, no-hard-tabs)
36-36: Column: 1
Hard tabs
(MD010, no-hard-tabs)
40-40: Column: 1
Hard tabs
(MD010, no-hard-tabs)
41-41: Column: 1
Hard tabs
(MD010, no-hard-tabs)
42-42: Column: 1
Hard tabs
(MD010, no-hard-tabs)
46-46: Column: 1
Hard tabs
(MD010, no-hard-tabs)
47-47: Column: 1
Hard tabs
(MD010, no-hard-tabs)
48-48: Column: 1
Hard tabs
(MD010, no-hard-tabs)
50-50: Column: 1
Hard tabs
(MD010, no-hard-tabs)
52-52: Column: 1
Hard tabs
(MD010, no-hard-tabs)
53-53: Column: 1
Hard tabs
(MD010, no-hard-tabs)
54-54: Column: 1
Hard tabs
(MD010, no-hard-tabs)
55-55: Column: 1
Hard tabs
(MD010, no-hard-tabs)
56-56: Column: 1
Hard tabs
(MD010, no-hard-tabs)
58-58: Column: 1
Hard tabs
(MD010, no-hard-tabs)
59-59: Column: 1
Hard tabs
(MD010, no-hard-tabs)
61-61: Column: 1
Hard tabs
(MD010, no-hard-tabs)
62-62: Column: 1
Hard tabs
(MD010, no-hard-tabs)
64-64: Column: 1
Hard tabs
(MD010, no-hard-tabs)
middleware/otel/README.md
11-11: Column: 1
Hard tabs
(MD010, no-hard-tabs)
12-12: Column: 1
Hard tabs
(MD010, no-hard-tabs)
13-13: Column: 1
Hard tabs
(MD010, no-hard-tabs)
15-15: Column: 1
Hard tabs
(MD010, no-hard-tabs)
16-16: Column: 1
Hard tabs
(MD010, no-hard-tabs)
17-17: Column: 1
Hard tabs
(MD010, no-hard-tabs)
18-18: Column: 1
Hard tabs
(MD010, no-hard-tabs)
25-25: Column: 1
Hard tabs
(MD010, no-hard-tabs)
26-26: Column: 1
Hard tabs
(MD010, no-hard-tabs)
30-30: Column: 1
Hard tabs
(MD010, no-hard-tabs)
34-34: Column: 1
Hard tabs
(MD010, no-hard-tabs)
35-35: Column: 1
Hard tabs
(MD010, no-hard-tabs)
39-39: Column: 1
Hard tabs
(MD010, no-hard-tabs)
40-40: Column: 1
Hard tabs
(MD010, no-hard-tabs)
41-41: Column: 1
Hard tabs
(MD010, no-hard-tabs)
43-43: Column: 1
Hard tabs
(MD010, no-hard-tabs)
44-44: Column: 1
Hard tabs
(MD010, no-hard-tabs)
45-45: Column: 1
Hard tabs
(MD010, no-hard-tabs)
46-46: Column: 1
Hard tabs
(MD010, no-hard-tabs)
47-47: Column: 1
Hard tabs
(MD010, no-hard-tabs)
49-49: Column: 1
Hard tabs
(MD010, no-hard-tabs)
51-51: Column: 1
Hard tabs
(MD010, no-hard-tabs)
52-52: Column: 1
Hard tabs
(MD010, no-hard-tabs)
54-54: Column: 1
Hard tabs
(MD010, no-hard-tabs)
55-55: Column: 1
Hard tabs
(MD010, no-hard-tabs)
🔇 Additional comments (3)
middleware/distributednooverlapping/README.md (3)
1-4
: Enhance the introduction section with more details
The introduction should be expanded to include key features, requirements, and implementation details as previously suggested.
46-48
: Add error handling for Redis connection
The Redis connection setup should include proper error handling.
🧰 Tools
🪛 Markdownlint (0.35.0)
46-46: Column: 1
Hard tabs
(MD010, no-hard-tabs)
47-47: Column: 1
Hard tabs
(MD010, no-hard-tabs)
48-48: Column: 1
Hard tabs
(MD010, no-hard-tabs)
58-59
: Add error handling for job registration
The example ignores potential errors when adding jobs.
🧰 Tools
🪛 Markdownlint (0.35.0)
58-58: Column: 1
Hard tabs
(MD010, no-hard-tabs)
59-59: Column: 1
Hard tabs
(MD010, no-hard-tabs)
otel.WithTracerProvider(tp), // custom otel.TracerProvider | ||
)) | ||
|
||
_, _ = c.AddJob("* * * * * *", &basicJob{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Handle errors from AddJob
The error returned from AddJob should be properly handled instead of being silently ignored.
- _, _ = c.AddJob("* * * * * *", &basicJob{})
+ if _, err := c.AddJob("* * * * * *", &basicJob{}); err != nil {
+ log.Fatal("Failed to add job:", err)
+ }
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
_, _ = c.AddJob("* * * * * *", &basicJob{}) | |
if _, err := c.AddJob("* * * * * *", &basicJob{}); err != nil { | |
log.Fatal("Failed to add job:", err) | |
} |
🧰 Tools
🪛 Markdownlint (0.35.0)
49-49: Column: 1
Hard tabs
(MD010, no-hard-tabs)
func (j *basicJob) GetMutexKey() string { | ||
return "basic:job" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Make mutex key unique per job instance
The current implementation uses a static mutex key "basic:job" for all jobs. This could cause unnecessary blocking between different job instances.
Consider using the job's slug in the mutex key:
-func (j *basicJob) GetMutexKey() string {
- return "basic:job"
-}
+func (j *basicJob) GetMutexKey() string {
+ return fmt.Sprintf("basic:job:%s", j.slug)
+}
Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Markdownlint (0.35.0)
32-32: Column: 1
Hard tabs
(MD010, no-hard-tabs)
Summary by CodeRabbit
New Features
otel
middleware to enhance observability.Chores
.gitignore
file to include_example
and modify.todo
.These updates enhance user understanding of middleware options and ensure cleaner version control management.