fixing datetimes for devices #2324
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!2324
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "refs/pull/2324/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: #1780
Original author: @mfreeman451
Original URL: https://github.com/carverauto/serviceradar/pull/1780
Original created: 2025-10-15T18:16:54Z
Original updated: 2025-10-16T03:36:31Z
Original head: carverauto/serviceradar:1765-bugcoreui-missing-date-in-device-view-from-devices-discovered-by-sync-service
Original base: main
Original merged: 2025-10-16T03:36:27Z by @mfreeman451
PR Type
Bug fix, Enhancement
Description
Fixed missing
first_seentimestamp for devices discovered by sync serviceAdded
annotateFirstSeenfunction to preserve earliest device discovery time across updatesUpdated database migration to use
_first_seenmetadata field in aggregation queriesAdded comprehensive test coverage for first_seen timestamp preservation logic
Diagram Walkthrough
File Walkthrough
registry.go
Add first_seen timestamp annotation logic for device updatespkg/registry/registry.go
annotateFirstSeen()function to compute and set_first_seenmetadata field
parseFirstSeenTimestamp()helper supporting multiple dateformats
ProcessBatchDeviceUpdates()workflow
update timestamp
registry_test.go
Add test coverage for first_seen timestamp preservationpkg/registry/registry_test.go
GetUnifiedDevicesByIPsOrIDs()in testhelpers
_first_seenmetadata presence andformat
TestDeviceRegistry_FirstSeenPreservedFromExistingRecord()testcase
00000000000001_consolidated_serviceradar_schema.up.sql
Update database schema to support _first_seen metadata fieldpkg/db/migrations/00000000000001_consolidated_serviceradar_schema.up.sql
SYNCmodifier to allDROP STREAMstatements for proper cleanupunified_devicesmaterialized view to use_first_seenfrommetadata
is_activeandhas_identityfilters
first_seencalculation to useparse_datetime64_best_effort_or_null()on_first_seenmetadataImported GitHub PR comment.
Original author: @qodo-code-review[bot]
Original URL: https://github.com/carverauto/serviceradar/pull/1780#issuecomment-3407713683
Original created: 2025-10-15T18:17:36Z
You are nearing your monthly Qodo Merge usage quota. For more information, please visit here.
PR Compliance Guide 🔍
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.🎫 #1765
recorded initially.
by later bad data.
Codebase context is not defined
Follow the guide to enable codebase context checks.
No custom compliance provided
Follow the guide to enable custom compliance check.
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/1780#issuecomment-3407717536
Original created: 2025-10-15T18:18:51Z
You are nearing your monthly Qodo Merge usage quota. For more information, please visit here.
PR Code Suggestions ✨
Explore these optional code suggestions:
✅
Ensure consistent timestamps within batchesSuggestion Impact:
The commit implemented a two-pass strategy by extracting collection of device IDs, fetching existing first_seen timestamps, computing the batch-wide earliest per device, and then applying that consistent timestamp to all updates. It also added chunked fetching and helper functions, aligning with the suggestion’s intent to ensure consistency within batches.code diff:
Refactor
annotateFirstSeento use a two-pass approach. First, find the earliesttimestamp for each device ID across the entire batch and existing records.
Second, apply this consistent timestamp to all updates for that device to ensure
data consistency.
pkg/registry/registry.go [534-601]
[Suggestion processed]Suggestion importance[1-10]: 8
__
Why: The suggestion correctly identifies a logic flaw where multiple updates for the same device within a single batch could receive inconsistent
_first_seentimestamps, leading to incorrect data. The proposed two-pass approach effectively fixes this data consistency bug.The solution introduces a potential performance bottleneck
The current implementation queries the
unified_devicesview for each updatebatch to preserve the
first_seentimestamp, creating a potential performancebottleneck. A more scalable solution would perform this logic entirely within
the database.
Examples:
pkg/registry/registry.go [184-186]
pkg/registry/registry.go [534-601]
Solution Walkthrough:
Before:
After:
Suggestion importance[1-10]: 7
__
Why: The suggestion correctly identifies a potential performance bottleneck in the read-modify-write pattern introduced, which is a significant architectural concern for a high-throughput system.