db pkg cleanup #2415
No reviewers
Labels
No labels
1week
2weeks
Failed compliance check
IP cameras
NATS
Possible security concern
Review effort 1/5
Review effort 2/5
Review effort 3/5
Review effort 4/5
Review effort 5/5
UI
aardvark
accessibility
amd64
api
arm64
auth
back-end
bgp
blog
bug
build
checkers
ci-cd
cleanup
cnpg
codex
core
dependencies
device-management
documentation
duplicate
dusk
ebpf
enhancement
eta 1d
eta 1hr
eta 3d
eta 3hr
feature
fieldsurvey
github_actions
go
good first issue
help wanted
invalid
javascript
k8s
log-collector
mapper
mtr
needs-triage
netflow
network-sweep
observability
oracle
otel
plug-in
proton
python
question
reddit
redhat
research
rperf
rperf-checker
rust
sdk
security
serviceradar-agent
serviceradar-agent-gateway
serviceradar-web
serviceradar-web-ng
siem
snmp
sysmon
topology
ubiquiti
wasm
wontfix
zen-engine
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
carverauto/serviceradar!2415
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "refs/pull/2415/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from GitHub pull request.
Original GitHub pull request: #1946
Original author: @mfreeman451
Original URL: https://github.com/carverauto/serviceradar/pull/1946
Original created: 2025-11-16T16:54:23Z
Original updated: 2025-11-16T17:03:15Z
Original head: carverauto/serviceradar:updates/db_cleanup
Original base: main
Original merged: 2025-11-16T17:02:55Z by @mfreeman451
User description
IMPORTANT: Please sign the Developer Certificate of Origin
Thank you for your contribution to ServiceRadar. Please note, when contributing, the developer must include
a DCO sign-off statement indicating the DCO acceptance in one commit message. Here
is an example DCO Signed-off-by line in a commit message:
Describe your changes
Issue ticket number and link
Code checklist before requesting a review
PR Type
Enhancement, Bug fix
Description
Remove Proton compatibility shim (
db.Conn,CompatConn) from database layerMigrate all registry queries to native CNPG/pgx with
$nplaceholdersAdd typed
ServiceRegistrationEventstruct and batch insert helperUpdate sysmon API queries to use
QueryCNPGRowsand UTC timestamp normalizationSimplify registry operations by eliminating placeholder rewriting logic
Diagram Walkthrough
File Walkthrough
6 files
Replace direct Conn.Query with QueryCNPGRows helperAdd ServiceRegistrationEvent type and batch insertRemove compat connection errors, add event validation errorReplace QueryCNPGRows with QueryRegistryRows methodMigrate event emission and deletion to native CNPGRemove Proton-style queries, use CNPG helpers directly3 files
Test ServiceRegistrationEvent argument buildingUpdate mock to use QueryRegistryRows interfaceRemove placeholder escaping tests, add event writer tests1 files
Remove CompatConn and placeholder rewriting logic7 files
Update Service interface documentation for CNPGUpdate DELETE example to use ExecCNPGAdd CNPG monitoring dashboards and retention checksAdd KV regression safeguards and CI validation planDocument rationale for removing Proton compatibility layerDefine requirements for Postgres-native registry tablesTrack completion of registry compatibility removal tasksImported GitHub PR comment.
Original author: @qodo-code-review[bot]
Original URL: https://github.com/carverauto/serviceradar/pull/1946#issuecomment-3538944722
Original created: 2025-11-16T16:54:54Z
PR Compliance Guide 🔍
(Compliance updated until commit
github.com/carverauto/serviceradar@1d9cc06b71)Below is a summary of compliance checks for this PR:
No security concerns identified
No security vulnerabilities detected by AI analysis. Human verification advised for critical code.🎫 No ticket provided
Codebase context is not defined
Follow the guide to enable codebase context checks.
Generic: Comprehensive Audit Trails
Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.
Status: Passed
Generic: Meaningful Naming and Self-Documenting Code
Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting
Status: Passed
Generic: Robust Error Handling and Edge Case Management
Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation
Status: Passed
Generic: Secure Error Handling
Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.
Status: Passed
Generic: Secure Logging Practices
Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.
Status: Passed
Generic: Security-First Input Validation and Data Handling
Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities
Status: Passed
Compliance status legend
🟢 - Fully Compliant🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label
Previous compliance checks
Compliance check up to commit 1d9cc06
No security concerns identified
No security vulnerabilities detected by AI analysis. Human verification advised for critical code.🎫 No ticket provided
Codebase context is not defined
Follow the guide to enable codebase context checks.
Generic: Comprehensive Audit Trails
Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.
Status: Passed
Generic: Meaningful Naming and Self-Documenting Code
Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting
Status: Passed
Generic: Robust Error Handling and Edge Case Management
Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation
Status: Passed
Generic: Secure Error Handling
Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.
Status: Passed
Generic: Secure Logging Practices
Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.
Status: Passed
Generic: Security-First Input Validation and Data Handling
Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities
Status: Passed
Imported GitHub PR comment.
Original author: @qodo-code-review[bot]
Original URL: https://github.com/carverauto/serviceradar/pull/1946#issuecomment-3538945649
Original created: 2025-11-16T16:56:06Z
PR Code Suggestions ✨
Explore these optional code suggestions:
Avoid N+1 queries during service purge
Optimize
PurgeInactiveto avoid N+1 queries by creating a private helperfunction that performs the deletion directly, bypassing the redundant status
checks in
DeleteService.pkg/registry/service_registry.go [712-805]
[To ensure code accuracy, apply this suggestion manually]Suggestion importance[1-10]: 8
__
Why: The suggestion correctly identifies a significant N+1 query performance issue in the
PurgeInactivefunction and proposes an effective solution by introducing a dedicated helper to bypass redundant database lookups.Improve error handling in service deletion
Refactor
DeleteServiceto handle errors fromGet...calls immediately withineach
caseblock, rather than using a single deferred error check, to make thecontrol flow more robust.
pkg/registry/service_registry.go [641-677]
[To ensure code accuracy, apply this suggestion manually]Suggestion importance[1-10]: 7
__
Why: The suggestion correctly identifies a potential logic flaw in error handling and proposes a more robust, fail-fast approach that improves code clarity and prevents subtle bugs.
Continue batch processing on single-item error
In
InsertServiceRegistrationEvents, handle errors for individual events bylogging them and continuing the batch process, rather than returning immediately
and failing the entire operation.
pkg/db/cnpg_registry.go [209-216]
Suggestion importance[1-10]: 6
__
Why: The suggestion correctly identifies that a single failing event will abort the entire batch insertion and proposes a more robust error handling strategy that is consistent with other functions in the file.