-
Notifications
You must be signed in to change notification settings - Fork 85
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
feat: some optimize #622
feat: some optimize #622
Conversation
WalkthroughThe changes introduce new GitHub Actions workflows for automated vulnerability checks and benchmarking of Go applications. The Go version is updated to 1.22, and significant enhancements are made to the session management in the application. These modifications aim to improve performance monitoring, security checks, and session handling within the CI/CD pipeline. Changes
Sequence Diagram(s)sequenceDiagram
participant Developer
participant GitHub Actions
participant Go Environment
participant Vulnerability Check
participant Benchmark Results
participant Session Manager
Developer->>GitHub Actions: Push changes
GitHub Actions->>Go Environment: Setup Go version
GitHub Actions->>Vulnerability Check: Run govulncheck
Vulnerability Check->>GitHub Actions: Return vulnerability results
GitHub Actions->>Go Environment: Run benchmarks
Go Environment->>Benchmark Results: Capture benchmark data
Benchmark Results->>GitHub Actions: Return results
GitHub Actions->>Session Manager: Manage sessions
Session Manager->>GitHub Actions: Return session management results
GitHub Actions->>Developer: Notify results
Assessment against linked issues
Recent review detailsConfiguration used: CodeRabbit UI Files selected for processing (1)
Files skipped from review as they are similar to previous changes (1)
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 ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #622 +/- ##
==========================================
- Coverage 69.95% 69.94% -0.02%
==========================================
Files 184 184
Lines 11267 11296 +29
==========================================
+ Hits 7882 7901 +19
- Misses 2815 2818 +3
- Partials 570 577 +7 ☔ 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: 1
Outside diff range, codebase verification and nitpick comments (5)
session/middleware/start_session.go (1)
57-59
: LGTM!The code changes are approved.
Consider using a
defer
statement to release the session.Instead of explicitly releasing the session at the end of the middleware function, you can use a
defer
statement to ensure that the session is released even if an error occurs or the function returns early.Here's an example of how you can use
defer
:func StartSession() http.Middleware { return func(ctx http.Context) { // ... // Build session s := session.SessionFacade.BuildSession(driver) defer session.SessionFacade.(*session.Manager).ReleaseSession(s.(*session.Session)) // ... } }This way, you don't need to worry about manually releasing the session at the end of the function.
crypt/aes_test.go (2)
61-73
: LGTM! Consider using a larger or variable-sized input.The benchmark setup and loop look correct. The code changes are approved.
To measure performance more realistically, consider using a larger or variable-sized input string instead of the fixed "Goravel" string.
75-91
: LGTM! Consider using a larger input and moving payload generation inside the loop.The benchmark setup and loop look correct. The code changes are approved.
Here are a few suggestions to enhance the benchmark:
- To measure performance more realistically, consider using a larger or variable-sized input string instead of the fixed "Goravel" string.
- Move the payload generation inside the loop to measure the performance of both encryption and decryption in each iteration. This will provide a more accurate representation of the real-world usage scenario.
.github/workflows/benchmark.yml (1)
83-97
: Consider enabling auto-push for publishing benchmark results.The workflow publishes benchmark results to GitHub Pages, which is a good practice for tracking performance over time. However, the
auto-push
option is set tofalse
, which means the results will not be automatically updated on the GitHub Pages site.To ensure that the published benchmark data remains up-to-date, consider setting
auto-push
totrue
:- auto-push: false + auto-push: trueThis change will enable the action to automatically push the updated benchmark results to the repository, keeping the GitHub Pages site in sync with the latest data.
hash/application_test.go (1)
150-150
: Discrepancy in default configuration value forhashing.bcrypt.rounds
.The test configuration in
hash/application_test.go
uses a default value of 10 forhashing.bcrypt.rounds
, while the actual implementation inhash/bcrypt.go
still uses 12. Please verify if the default value inhash/bcrypt.go
should be updated to 10 to maintain consistency across the codebase.
hash/bcrypt.go
: Default value is 12.hash/application_test.go
: Mock configuration returns 10.Analysis chain
Verify the impact of the configuration change on the rest of the codebase.
The change to the default value of the
hashing.bcrypt.rounds
configuration from 12 to 10 is a valid change that aligns with the test suite's requirements. However, it's important to ensure that this change is consistent with the rest of the codebase and does not have any unintended consequences.Run the following script to verify the usage of the
hashing.bcrypt.rounds
configuration in the codebase:Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of the `hashing.bcrypt.rounds` configuration in the codebase. # Test: Search for the usage of the `hashing.bcrypt.rounds` configuration. Expect: Only occurrences of the new default value (10). rg --type go -A 5 $'hashing.bcrypt.rounds'Length of output: 507
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (2)
mocks/auth/Auth.go
is excluded by!mocks/**
mocks/session/Manager.go
is excluded by!mocks/**
Files selected for processing (19)
- .github/workflows/benchmark.yml (1 hunks)
- .github/workflows/mockery.yml (1 hunks)
- contracts/session/manager.go (1 hunks)
- crypt/aes_test.go (1 hunks)
- go.mod (1 hunks)
- hash/application_test.go (3 hunks)
- hash/bcrypt.go (1 hunks)
- http/middleware/throttle_test.go (1 hunks)
- log/logger/daily.go (2 hunks)
- log/logrus_writer_test.go (2 hunks)
- session/driver/file_test.go (2 hunks)
- session/manager.go (2 hunks)
- session/manager_test.go (3 hunks)
- session/middleware/start_session.go (1 hunks)
- session/middleware/start_session_test.go (1 hunks)
- session/service_provider.go (2 hunks)
- session/session.go (1 hunks)
- translation/file_loader_test.go (2 hunks)
- translation/translator_test.go (1 hunks)
Files skipped from review due to trivial changes (1)
- go.mod
Additional context used
actionlint
.github/workflows/benchmark.yml
41-41: shellcheck reported issue in this script: SC2086:info:2:20: Double quote to prevent globbing and word splitting
(shellcheck)
Additional comments not posted (45)
contracts/session/manager.go (1)
9-9
: LGTM!The change to the
Extend
method signature is approved for the following reasons:
- It introduces error handling into the method's functionality, allowing it to signal potential issues during the extension of the session manager with a custom driver.
- The adjustment enhances the robustness of the interface by enabling callers to handle errors that may arise when attempting to extend the session manager.
- The change is consistent with the AI-generated summary.
session/service_provider.go (1)
27-30
: Verify the impact of removing the GC timer setup on session management and resource cleanup.The changes streamline the
Boot
method by eliminating the GC timer setup, which may impact session management and resource cleanup within the application. The removal of thestartGcTimer
function indicates a shift in how session lifecycle management is handled, potentially leading to uncollected sessions if the GC process is no longer initiated.Run the following script to verify the impact of the changes:
hash/bcrypt.go (1)
16-16
: Approve the change to increase the default number of hashing rounds.The change to increase the default number of hashing rounds from 10 to 12 is approved.
Increasing the number of hashing rounds enhances security against brute-force attacks by making the hashing function more computationally expensive. This change aligns with the goal of implementing optimizations and improving security within the Goravel framework.
However, it's important to note that increasing the number of hashing rounds may have performance implications due to the increased computational cost. It is recommended to monitor the impact of this change on the overall performance of the system, especially in scenarios with high volumes of password hashing operations.
Consider conducting performance tests and benchmarks to assess the trade-off between security and performance. If the performance impact is significant and unacceptable, you may need to find a balance by adjusting the number of rounds or exploring alternative hashing algorithms that provide a better balance between security and performance.
session/middleware/start_session.go (1)
53-53
: LGTM!The code changes are approved.
log/logger/daily.go (2)
17-17
: LGTM!The code changes are approved.
47-47
: LGTM!The code changes are approved.
session/driver/file_test.go (1)
111-128
: LGTM!The benchmarking function is correctly implemented and follows the standard benchmarking practices in Go. It accurately measures the performance of file read and write operations in a controlled benchmark environment. The cleanup operation is also correctly executed after the benchmark operations to ensure a clean state for subsequent tests or benchmarks.
The code changes are approved.
session/manager.go (6)
19-32
: LGTM!The addition of the
sessionPool
field and its initialization in theNewManager
function looks good. Utilizingsync.Pool
for efficient session management is a great optimization.
39-48
: LGTM!The refactoring of the
BuildSession
method looks good. Utilizing theAcquireSession
method and explicitly setting the session properties improves code clarity. The simplified session ID handling is also a nice touch.
71-78
: LGTM!The modifications to the
Extend
method look good. Returning an error when a driver with the same name already exists is a nice addition for better error handling. Starting the garbage collection timer for the session driver is also a good practice.
80-83
: LGTM!The introduction of the
AcquireSession
method is a great addition. It provides a clean and efficient way to retrieve a session from the pool.
85-87
: LGTM!The introduction of the
ReleaseSession
method is a great addition. It provides a clean way to release a session back to the pool. Resetting the session before releasing it is a good practice.
105-122
: LGTM!The introduction of the
startGcTimer
method is a great addition for resource management. The method is well-structured and handles the case when the interval is zero or negative. Periodically invoking the garbage collection process for the session driver is a good practice.translation/file_loader_test.go (4)
22-23
: LGTM!The code changes are approved. Refactoring the test suite to use the
suite
package is a good practice for organizing test code.
25-34
: LGTM!The code changes are approved. The
SetupSuite
method is a good place to set up the test environment and the method is creating test files and setting up the test environment correctly.
36-38
: LGTM!The code changes are approved. The
TearDownSuite
method is a good place to clean up the test environment and the method is removing the test files correctly.
105-122
: LGTM!The code changes are approved. The
Benchmark_Load
function is a good way to measure the performance of theLoad
method and the function is setting up the test suite, running the benchmark, and then tearing down the suite correctly..github/workflows/benchmark.yml (1)
11-15
: Appropriate permissions requested.The workflow requests write permissions for repository contents and pull requests, which aligns with its purpose of updating benchmark data and posting comments.
hash/application_test.go (7)
14-14
: LGTM!The addition of the
config
field to theApplicationTestSuite
struct is a valid change that allows for better management of configuration settings during tests.
19-19
: LGTM!The changes to the
TestApplicationTestSuite
function are valid. Moving the setup of hashers to theSetupTest
method is a better approach as it centralizes the configuration setup, ensuring that it is done consistently before each test.
23-28
: LGTM!The changes to the
SetupTest
method are valid. Initializings.config
and populating the hashers with the appropriate instances ofargon2id
andbcrypt
using the newconfig
field centralizes the configuration setup, ensuring that it is done consistently before each test.
30-32
: LGTM!The addition of the
TearDownSuite
method is a valid change that ensures all expected interactions with the mock configuration are validated after the test suite has run.
80-97
: LGTM!The addition of the
BenchmarkMakeHash
function is a valid change that enhances the test suite by providing performance metrics for theMake
function of each hasher.
99-119
: LGTM!The addition of the
BenchmarkCheckHash
function is a valid change that enhances the test suite by providing performance metrics for theCheck
function of each hasher.
121-140
: LGTM!The addition of the
BenchmarkNeedsRehash
function is a valid change that enhances the test suite by providing performance metrics for theNeedsRehash
function of each hasher.session/manager_test.go (8)
28-35
: LGTM!The changes are approved:
- The receiver name change from
m
tos
improves consistency in naming conventions.- Retrieving the
session.gc_interval
configuration ensures that garbage collection intervals are accounted for during tests.
37-38
: LGTM!The changes are approved:
- Asserting expectations on the mock configuration in the
TearDownSuite
method ensures that all expected calls were made.- This addition strengthens the reliability of the tests by confirming that the mock interactions are as intended.
41-78
: LGTM!The changes are approved:
- The receiver name change from
m
tos
improves consistency in naming conventions.- Retrieving the
session.gc_interval
configuration ensures that this value is consistently used in the tests.- The logic remains largely the same, and there are no issues.
81-89
: LGTM!The changes are approved:
- The receiver name change from
m
tos
improves consistency in naming conventions.- Retrieving the
session.gc_interval
configuration ensures that this value is consistently used in the tests.- The logic for extending the session manager with a custom driver remains intact, and there are no issues.
92-96
: LGTM!The changes are approved:
- The receiver name change from
m
tos
improves consistency in naming conventions.- The logic remains the same, and there are no issues.
99-101
: LGTM!The changes are approved:
- The receiver name change from
m
tos
improves consistency in naming conventions.- The logic remains the same, and there are no issues.
104-106
: LGTM!The changes are approved:
- The receiver name change from
m
tos
improves consistency in naming conventions.- The logic remains the same, and there are no issues.
108-140
: LGTM!The changes are approved:
- The new
BenchmarkSession_ReadWrite
benchmark provides a standardized approach to performance testing.- The benchmark setup is correct, and the read/write operations are being tested properly.
- The benchmark teardown is also correct, destroying the session and removing the storage directory.
session/session.go (1)
275-281
: LGTM!The
reset
method is a useful addition to theSession
struct. It correctly resets the state of aSession
instance by clearing its fields and reinitializing theattributes
map. The method name clearly conveys its purpose and it can be beneficial for scenarios where a session needs to be reinitialized without creating a new instance.The code changes are approved.
session/middleware/start_session_test.go (1)
46-46
: LGTM!The code change is approved. It enhances the test's coverage by explicitly defining the garbage collection interval for sessions during the test execution.
translation/translator_test.go (3)
450-469
: LGTM!The benchmark function
Benchmark_Choice
is correctly implemented and follows the standard benchmarking pattern in Go. It measures the performance of theChoice
method of theTranslator
by initializing a newTranslatorTestSuite
, setting up the test context, preparing a mock loader to return a specific translation structure, and running theChoice
method in a loop forb.N
iterations.
471-490
: LGTM!The benchmark function
Benchmark_Get
is correctly implemented and follows the standard benchmarking pattern in Go. It measures the performance of theGet
method of theTranslator
by initializing a newTranslatorTestSuite
, setting up the test context, preparing a mock loader to return a specific translation string, and running theGet
method in a loop forb.N
iterations.
492-511
: LGTM!The benchmark function
Benchmark_Has
is correctly implemented and follows the standard benchmarking pattern in Go. It measures the performance of theHas
method of theTranslator
by initializing a newTranslatorTestSuite
, setting up the test context, preparing a mock loader to return a specific translation structure, and running theHas
method in a loop forb.N
iterations.http/middleware/throttle_test.go (1)
279-359
: LGTM!The new benchmarking function
Benchmark_Throttle
is well-structured and covers multiple scenarios to test the performance of theThrottle
function. The use of mock objects and expectations helps ensure the correctness of the interactions during the benchmarks.log/logrus_writer_test.go (6)
433-443
: LGTM!The code changes are approved.
445-455
: LGTM!The code changes are approved.
457-467
: LGTM!The code changes are approved.
469-479
: LGTM!The code changes are approved.
481-483
: LGTM!The code changes are approved. The comment provides a valid reason for not implementing the benchmarking function.
485-498
: LGTM!The code changes are approved. The
defer
statement is used correctly to recover from the panic caused by thePanic
method.
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: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (6)
- .github/workflows/benchmark.yml (1 hunks)
- .github/workflows/mockery.yml (1 hunks)
- session/manager.go (2 hunks)
- session/manager_test.go (2 hunks)
- support/file/file_test.go (1 hunks)
- validation/errors_test.go (1 hunks)
Files skipped from review due to trivial changes (2)
- support/file/file_test.go
- validation/errors_test.go
Files skipped from review as they are similar to previous changes (3)
- .github/workflows/mockery.yml
- session/manager.go
- session/manager_test.go
Additional context used
actionlint
.github/workflows/benchmark.yml
39-39: shellcheck reported issue in this script: SC2086:info:2:20: Double quote to prevent globbing and word splitting
(shellcheck)
Additional comments not posted (5)
.github/workflows/benchmark.yml (5)
18-21
: LGTM!The "Fetch Repository" step is correctly configured to fetch the repository with the last commit.
23-27
: LGTM!The "Install Go" step is correctly configured to install Go 1.22.x.
29-30
: LGTM!The "Run Benchmark" step is correctly configured to run benchmarks and capture the output.
37-41
: LGTM!The "Get Main branch SHA" step is correctly retrieving the SHA of the main branch.
The static analysis hint about quoting the SHA variable can be ignored because the SHA does not contain spaces or glob characters that require quoting.
Tools
actionlint
39-39: shellcheck reported issue in this script: SC2086:info:2:20: Double quote to prevent globbing and word splitting
(shellcheck)
43-102
: LGTM!The remaining steps are correctly configured to:
- Compare benchmark results with the main branch
- Store benchmark results for the main branch
- Publish benchmark results to GitHub Pages
- Update the benchmark results cache
The steps use appropriate conditions to execute based on the branch and cache hit.
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.
Many optimizations, Great PR 👍 But it's a bit hard to review, please split it into some small PRs next time.
rotatelogs.WithRotationCount(uint(daily.config.GetInt(channel+".days"))), | ||
rotatelogs.WithClock(rotatelogs.NewClock(carbon.Now().StdTime())), |
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.
This is a bug fix.
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: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
mocks/session/Manager.go
is excluded by!mocks/**
Files selected for processing (9)
- contracts/session/manager.go (1 hunks)
- go.mod (1 hunks)
- session/manager.go (2 hunks)
- session/manager_test.go (2 hunks)
- session/middleware/start_session.go (1 hunks)
- session/session.go (1 hunks)
- support/docker/postgres.go (2 hunks)
- support/docker/postgres_test.go (2 hunks)
- translation/file_loader_test.go (2 hunks)
Files skipped from review due to trivial changes (2)
- support/docker/postgres.go
- support/docker/postgres_test.go
Files skipped from review as they are similar to previous changes (6)
- go.mod
- session/manager.go
- session/manager_test.go
- session/middleware/start_session.go
- session/session.go
- translation/file_loader_test.go
Additional comments not posted (2)
contracts/session/manager.go (2)
9-9
: Approved change to method signature inExtend
.The change from returning a
Manager
to anerror
in theExtend
method is a good practice in error handling. It simplifies the interface and makes the error states clear to the users of this method.
11-11
: Good addition withReleaseSession
.Adding the
ReleaseSession
method to theManager
interface is a beneficial enhancement for managing session lifecycles and resource cleanup. This method will help in properly releasing sessions back to the pool, which is crucial for effective resource management.
FYI, please pin me when this PR is ready. |
Already prepared. |
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.
Great, almost complete, only two questions.
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.
Em, if we can‘t check the result, what's the meaning of it?
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.
Em, if we can‘t check the result, what's the meaning of it?
Move the test cases previously used for concurrency testing to the benchmark.
And although the results cannot be viewed directly, CI will automatically compare them with previous results.
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.
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.
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.
Perfect 👍 Please remember to create a PR for goravel/goravel.
📑 Description
Closes goravel/goravel/issues/480
Closes goravel/goravel/issues/481
Closes goravel/goravel/issues/325
Summary by CodeRabbit
Summary by CodeRabbit
New Features
Chores
✅ Checks