2016 bugsync not picking up correct sweepjson in demo namespace #2478
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!2478
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "refs/pull/2478/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: #2017
Original author: @mfreeman451
Original URL: https://github.com/carverauto/serviceradar/pull/2017
Original created: 2025-11-25T03:07:53Z
Original updated: 2025-11-25T03:41:36Z
Original head: carverauto/serviceradar:2016-bugsync-not-picking-up-correct-sweepjson-in-demo-namespace
Original base: main
Original merged: 2025-11-25T03:41:33Z 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
Bug fix, Enhancement
Description
Simplified device counting logic in stats aggregator to include all non-nil records, preventing legitimate discovered devices from being hidden in UI statistics
Added unified devices upsert logic and periodic cleanup of stale devices not seen within retention period (default 3 days)
Enhanced checker configuration lookup to use checker config's
Addressfield as fallback when request details are emptyImplemented device retention configuration with defaults and integrated cleanup into metrics cleanup routine
Added comprehensive SRQL query support for
device_updatesentity with filtering, time range, and ordering capabilitiesRegenerated mocks with improved parameter naming and new methods for better code maintainability
Extended Helm configuration with new gRPC checker for sync service
Diagram Walkthrough
File Walkthrough
1 files
mock_db.go
Regenerate mocks with improved parameter naming and new methodspkg/db/mock_db.go
arg0→ctx,arg1→pollerID) for better code readability-source=pkg/db/interfaces.goinstead ofmodule path for more maintainable mock generation
MockQueryExecutorinterface implementation withExecuteQuerymethod
CleanupStaleUnifiedDevicesandCountUnifiedDevicestoMockServiceGetDeviceMetricTypestoMockService10 files
cnpg_unified_devices.go
Add unified devices upsert and stale device cleanuppkg/db/cnpg_unified_devices.go
unified_devicestable alongside existingdevice_updatesinsert to maintain current device stateCleanupStaleUnifiedDevicesfunction to periodically removedevices not seen within retention period
current state
values for empty fields
server.go
Use checker config address as fallback for detailspkg/agent/server.go
Addressfield as fallback when request details are empty
and address availability
server.go
Add periodic stale device cleanup to metrics cleanup routinepkg/core/server.go
default
runMetricsCleanupgoroutinedb.go
Add device retention days field to metrics configpkg/models/db.go
DeviceRetentionDaysfield toMetricsstruct with JSON tag andomitempty option
unified_devicestableinterfaces.go
Add cleanup method to service interfacepkg/db/interfaces.go
CleanupStaleUnifiedDevicesmethod signature toServiceinterfaceand error
device_updates.rs
Add device updates query support to SRQLrust/srql/src/query/device_updates.rs
device_updatesentityagent_id, partition, discovery_source, and availability
device_id
mod.rs
Add device_updates module integration to query enginerust/srql/src/query/mod.rs
device_updatesDeviceUpdatesentity handling in query execution matchstatement
DeviceUpdatesentity handling in debug SQL generation matchstatement
models.rs
Add DeviceUpdateRow model with JSON serializationrust/srql/src/models.rs
DeviceUpdateRowstruct with Diesel queryable derive macrosinto_json()method to convertDeviceUpdateRowto JSONrepresentation
information
parser.rs
Add DeviceUpdates entity type to parserrust/srql/src/parser.rs
DeviceUpdatesvariant toEntityenum"device_update", and "updates" aliases
schema.rs
Add device_updates table schema definitionrust/srql/src/schema.rs
device_updatesDiesel table schema with composite primarykey
metadata
2 files
config.go
Add device retention configuration defaultspkg/core/config.go
defaultDeviceRetentionDaysconstant set to 3 daysconfigured
initialization
serviceradar-config.yaml
Add sync service gRPC checker configurationhelm/serviceradar/files/serviceradar-config.yaml
syncservice with 5-minuteresults interval
1 files
stats_aggregator.go
Simplify device counting logic to include all recordspkg/core/stats_aggregator.go
shouldCountRecordfunction to count all non-nil recordswithout filtering sweep-only devices
filtering
statistics
Imported GitHub PR comment.
Original author: @qodo-code-review[bot]
Original URL: https://github.com/carverauto/serviceradar/pull/2017#issuecomment-3573602250
Original created: 2025-11-25T03:08:38Z
PR Compliance Guide 🔍
Below is a summary of compliance checks for this PR:
Data deletion risk
Description: Deleting from unified_devices solely by last_seen < now - retention without partitioning
or safety checks can allow an attacker or misconfiguration to prematurely purge active
devices if clocks or observed times are manipulated, leading to data loss and potential
denial of service.
cnpg_unified_devices.go [421-432]
Referred Code
SSRF risk
Description: Falling back to use checker config 'Address' for request details may cause unintended
service endpoints to be queried if misconfigured, enabling SSRF-like behavior or probing
internal addresses through the agent.
server.go [1749-1761]
Referred Code
🎫 #2016
integration via objectstore blob referenced in NATS KV, not the default local sweep.json.
core/device registry processes them.
accurately in UI stats and analytics counts.
Codebase context is not defined
Follow the guide to enable codebase context checks.
Generic: Meaningful Naming and Self-Documenting Code
Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting
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: Comprehensive Audit Trails
Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.
Status:
Missing audit logs: New critical DB actions (upsert into
unified_devicesand cleanup deletions) do not emitaudit logs identifying actor/context, making reconstruction of actions difficult.
Referred Code
Generic: Robust Error Handling and Edge Case Management
Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation
Status:
Partial failure handling: Batch upsert and insert operations lack per-item error context and retry/compensation, and
cleanup deletion does not validate inputs like zero/negative retention beyond early return
paths.
Referred Code
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:
Log data sensitivity: Newly added logs include
addressand service identifiers which could expose sensitiveendpoint details if logs are externally visible; absence of redaction is unclear.
Referred Code
Generic: Security-First Input Validation and Data Handling
Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities
Status:
Input validation: SRQL filters map directly into Diesel query builders; while parameterized, field
validation is limited to a whitelist and error messages may echo user fields, needing
confirmation no raw SQL or sensitive data exposure occurs.
Referred Code
Compliance status legend
🟢 - Fully Compliant🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label
Imported GitHub PR comment.
Original author: @qodo-code-review[bot]
Original URL: https://github.com/carverauto/serviceradar/pull/2017#issuecomment-3573604090
Original created: 2025-11-25T03:09:39Z
PR Code Suggestions ✨
Explore these optional code suggestions:
Consider a simpler device management design
The suggestion proposes simplifying the device management design by removing the
dual-write pattern. Instead of writing to both
device_updatesandunified_devices, it recommends using only thedevice_updateshypertable andderiving the current state with a materialized view or a
DISTINCT ONquery.Examples:
pkg/db/cnpg_unified_devices.go [94-164]
pkg/core/server.go [514-522]
Solution Walkthrough:
Before:
After:
Suggestion importance[1-10]: 9
__
Why: This is a high-impact architectural suggestion that correctly identifies the complexity of the dual-write pattern and proposes a simpler, more robust alternative using standard database features, which could significantly reduce code complexity and potential data inconsistencies.
Remove redundant default value logic
Remove the redundant conditional block that sets a default value for
deviceRetentionDays.pkg/core/server.go [492-497]
Suggestion importance[1-10]: 5
__
Why: The suggestion correctly identifies redundant logic for setting a default value that is already handled in
normalizeConfig, and removing it improves code maintainability by ensuring a single source of truth.Refactor ordering logic to reduce duplication
Refactor the
apply_orderingfunction to remove duplicated logic for applying thefirst and subsequent ordering clauses by using an indexed loop.
rust/srql/src/query/device_updates.rs [130-169]
Suggestion importance[1-10]: 5
__
Why: The suggestion correctly identifies code duplication and proposes a valid refactoring that improves maintainability, although the proposed implementation is still somewhat verbose.