Closed mrheinen closed 2 months ago
โฑ๏ธ Estimated effort to review: 4 ๐ต๐ต๐ต๐ตโช |
๐งช PR contains tests |
๐ Security concerns No apparent security concerns were introduced in this PR. The switch from WHOIS to RDAP generally improves security as RDAP is a more standardized and secure protocol. However, it's important to ensure that the RDAP client is configured to use HTTPS for secure communication with RDAP servers. |
โก Key issues to review Error Handling The error handling in the `DoWhoisWork` method could be improved. It currently logs warnings but doesn't handle retries or failures comprehensively. Data Processing The RDAP response processing in `DoWhoisWork` method might need more robust parsing and error checking, especially when dealing with the `Country` field. Schema Change The `Whois` struct has been significantly modified. Ensure that this change is compatible with existing data and that any necessary database migrations are implemented. |
Preparing PR description...
Preparing review...
Category | Suggestion | Score |
Best practice |
Ensure proper initialization order of components___ **Consider initializingjRunner with dbc before creating as . This ensures that jRunner has access to the database client when it's created.** [cmd/api/api_server.go [117-119]](https://github.com/mrheinen/lophiid/pull/8/files#diff-9bfccb4639f2f956c54c30543b7cdbd9fa139a3a768eb254245febfaa970514bR117-R119) ```diff +dbc := database.NewKSQLClient(&db) +jRunner := javascript.NewGojaJavascriptRunner(dbc, javascript.CreateGoJaMetrics(reg)) +as := api.NewApiServer(dbc, jRunner, id.String()) - ``` - [ ] **Apply this suggestion** Suggestion importance[1-10]: 8Why: Initializing jRunner with dbc before creating as ensures proper dependency injection and prevents potential issues with uninitialized components. | 8 |
Error handling |
Handle potential errors from printing RDAP response___ **Consider handling the error returned byrdapPrinter.Print(resNetwork) to ensure any printing errors are caught and logged.** [pkg/whois/rdap.go [126-129]](https://github.com/mrheinen/lophiid/pull/8/files#diff-e28100c5c0bcf097b7a414bde2c3d8f1b0fa075281de07b908ace5e022520848R126-R129) ```diff -rdapPrinter.Print(resNetwork) +if err := rdapPrinter.Print(resNetwork); err != nil { + slog.Warn("Failed to print RDAP response", slog.String("error", err.Error())) +} if _, err := c.dbClient.Insert( ``` - [ ] **Apply this suggestion** Suggestion importance[1-10]: 7Why: Error handling for rdapPrinter.Print() improves robustness and helps in identifying and logging potential issues during RDAP response printing. | 7 |
Enhancement |
Add context parameter for better control over RDAP queries___ **Consider adding a context parameter to theLookupIP method to allow for cancellation and timeout control of the RDAP query.** [pkg/whois/rdap.go [156]](https://github.com/mrheinen/lophiid/pull/8/files#diff-e28100c5c0bcf097b7a414bde2c3d8f1b0fa075281de07b908ace5e022520848R156-R156) ```diff -func (c *CachedRdapManager) LookupIP(ip string) error { +func (c *CachedRdapManager) LookupIP(ctx context.Context, ip string) error { ``` - [ ] **Apply this suggestion** Suggestion importance[1-10]: 6Why: Adding a context parameter allows for better control over RDAP queries, enabling timeouts and cancellations, but it's not a critical change for functionality. | 6 |
Testing |
Improve test assertions for more precise metric checking___ **Consider adding more specific assertions for the metrics values in the test cases.Instead of just checking if the metric is not zero, assert the exact expected value.** [pkg/whois/rdap_test.go [172-175]](https://github.com/mrheinen/lophiid/pull/8/files#diff-d8fca80ecd2f638442d11e2e4bd8a8e55a78e942b83fb0eea8dc609a9ce66049R172-R175) ```diff metric := testutil.ToFloat64(metrics.whoisRetriesExceededCount) -if int(metric) != 1 { - t.Errorf("expected 1, got %f", metric) +expectedMetricValue := float64(1) +if metric != expectedMetricValue { + t.Errorf("expected %.2f, got %.2f", expectedMetricValue, metric) } ``` - [ ] **Apply this suggestion** Suggestion importance[1-10]: 5Why: More specific assertions in tests can improve the precision of metric checking, but the current implementation is already functional and this change is mainly for test quality improvement. | 5 |
**Action:** build |
**Failed stage:** [Build](https://github.com/mrheinen/lophiid/actions/runs/10370128601/job/28707350436) [โ] |
**Failure summary:**
The action failed due to compilation errors in the Go code:whois.FakeWhoisManager in the file pkg/backend/backend_test.go .backend_test.go .FakeWhoisManager type or function is not properly imported or defined in the whois package. |
Relevant error logs:```yaml 1: ##[group]Operating System 2: Ubuntu ... 603: [224 / 291] GoCompilePkg external/com_github_dop251_goja/goja.a; 3s linux-sandbox ... (2 actions, 1 running) 604: [231 / 291] GoCompilePkg external/com_github_dop251_goja/goja.a; 4s linux-sandbox ... (2 actions, 1 running) 605: [234 / 291] GoCompilePkg external/com_github_dop251_goja/goja.a; 5s linux-sandbox ... (2 actions running) 606: [241 / 291] GoCompilePkg external/com_github_dop251_goja/goja.a; 6s linux-sandbox ... (2 actions, 1 running) 607: [242 / 291] GoCompilePkg external/com_github_dop251_goja/goja.a; 7s linux-sandbox ... (2 actions, 1 running) 608: [243 / 291] GoCompilePkg external/com_github_dop251_goja/goja.a; 9s linux-sandbox ... (2 actions running) 609: [257 / 291] GoCompilePkg backend_service/backend_service.a; 0s linux-sandbox ... (2 actions running) 610: [267 / 291] GoLink pkg/vt/vt_test_/vt_test; 0s linux-sandbox ... (2 actions, 1 running) 611: ERROR: /home/runner/work/lophiid/lophiid/pkg/backend/BUILD.bazel:40:8: GoCompilePkg pkg/backend/backend_test.internal.a failed: (Exit 1): builder failed: error executing GoCompilePkg command (from target //pkg/backend:backend_test) bazel-out/k8-opt-exec-ST-d57f47055a04/bin/external/go_sdk/builder_reset/builder compilepkg -sdk external/go_sdk -installsuffix linux_amd64 -src pkg/backend/backend.go -src pkg/backend/client.go -src ... (remaining 83 arguments skipped) 612: Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging 613: ##[error]pkg/backend/backend_test.go:184:26: undefined: whois.FakeWhoisManager 614: ##[error]pkg/backend/backend_test.go:220:24: undefined: whois.FakeWhoisManager 615: ##[error]pkg/backend/backend_test.go:270:24: undefined: whois.FakeWhoisManager 616: ##[error]pkg/backend/backend_test.go:360:26: undefined: whois.FakeWhoisManager 617: ##[error]pkg/backend/backend_test.go:393:24: undefined: whois.FakeWhoisManager 618: ##[error]pkg/backend/backend_test.go:510:24: undefined: whois.FakeWhoisManager 619: ##[error]pkg/backend/backend_test.go:611:24: undefined: whois.FakeWhoisManager 620: ##[error]pkg/backend/backend_test.go:702:26: undefined: whois.FakeWhoisManager 621: ##[error]pkg/backend/backend_test.go:738:24: undefined: whois.FakeWhoisManager 622: ##[error]pkg/backend/backend_test.go:791:24: undefined: whois.FakeWhoisManager 623: ##[error]pkg/backend/backend_test.go:791:24: too many errors 624: compilepkg: error running subcommand external/go_sdk/pkg/tool/linux_amd64/compile: exit status 2 625: Use --verbose_failures to see the command lines of failed build steps. 626: INFO: Elapsed time: 125.235s, Critical Path: 83.14s 627: INFO: 271 processes: 45 internal, 226 linux-sandbox. 628: ERROR: Build did NOT complete successfully 629: ##[error]Process completed with exit code 1. ``` |
So overall the PR code suggestions are not good. The only good this to consider is to refactor DoWhoisWork to return an error but that requires some design changes.
User description
This fixes issue https://github.com/mrheinen/lophiid/issues/3
PR Type
Enhancement
Description
RdapManager
to handle RDAP queries and caching, replacing the previousWhoisManager
.Country
for RDAP data.Changes walkthrough ๐
8 files
api_server.go
Update JavaScript runner initialization
cmd/api/api_server.go
NewGojaJavascriptRunner
function call withdbc
parameterbackend_main.go
Replace whois client with RDAP client
cmd/backend/backend_main.go
lwhois
package withrdap
packageNewCachedWhoisManager
toNewCachedRdapManager
server.go
Add RDAP string to whois response
pkg/api/server.go
RdapString
field to whois responsebackend.go
Update backend to use RDAP manager
pkg/backend/backend.go
WhoisManager
toRdapManager
database.go
Enhance Whois struct with RDAP data
pkg/database/database.go
Country
field toWhois
structRdapString
field for API server usemetrics.go
Add new RDAP lookup metrics
pkg/whois/metrics.go
rdap.go
Implement RDAP manager and client
pkg/whois/rdap.go
WhoisManager
toRdapManager
RequestView.vue
Enhance UI to display RDAP information
ui/src/components/container/RequestView.vue
1 files
rdap_test.go
Update and add tests for RDAP functionality
pkg/whois/rdap_test.go
2 files
BUILD.bazel
Update Bazel dependencies for RDAP
cmd/backend/BUILD.bazel - Replaced `likexian_whois` dependency with `openrdap_rdap`
BUILD.bazel
Update Bazel configuration for RDAP changes
pkg/whois/BUILD.bazel