fixing dashboard errors of missing devices from stats cards #2411
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!2411
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "refs/pull/2411/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: #1937
Original author: @mfreeman451
Original URL: https://github.com/carverauto/serviceradar/pull/1937
Original created: 2025-11-12T18:38:59Z
Original updated: 2025-11-14T18:18:29Z
Original head: carverauto/serviceradar:1936-bugdocker-agent-detail-showing-clientside-react-error
Original base: main
Original merged: 2025-11-14T18:17:40Z 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
Fixed dashboard errors by improving poller device registration with source IP tracking
Enhanced stats aggregator to fallback to service components when no canonical records exist
Added device planner query validation to prevent aggregation queries from using planner
Fixed React client-side errors in device detail and traces dashboard components
Diagram Walkthrough
File Walkthrough
pollers.go
Add source IP tracking to poller device registrationpkg/core/pollers.go
hostIPparameter tostorePollerStatusfunction to pass source IPfrom requests
registerPollerAsDeviceto accept and resolve host IP withfallback logic checking ServiceRegistry metadata
storePollerStatusto avoidduplicate registrations
req.SourceIpor empty string whenregistering pollers
stats_aggregator.go
Improve stats aggregator with service component fallbackpkg/core/stats_aggregator.go
processRecordclosure for bettercode organization
pointer dereferences
canonical records exist
sole available records
route.ts
Add query validation for device planner routingweb/src/app/api/query/route.ts
extractPrimaryStreamfunction to parse stream names from SRQLqueries
shouldUseDevicePlannerfunction to validate query eligibilityfor device planner
stats:) and non-device streamsDeviceDetail.tsx
Fix discovery sources handling for object arraysweb/src/components/Devices/DeviceDetail.tsx
DiscoverySourceinterface to handle structured discovery sourceobjects
DeviceRecordtype to support discovery sources as objectarrays
ensureArrayfunction to handle both string and object arrayformats
sourcefield from discovery source objects to preventrendering errors
TracesDashboard.tsx
Add null safety handling for trace ID displayweb/src/components/Observability/TracesDashboard.tsx
traceIdparameter inTraceIdCellcomponentundefined
stats_aggregator_test.go
Add test for service component fallback logicpkg/core/stats_aggregator_test.go
TestStatsAggregatorFallsBackToServiceComponentstoverify service component handling
only available records
components
Imported GitHub PR comment.
Original author: @qodo-code-review[bot]
Original URL: https://github.com/carverauto/serviceradar/pull/1937#issuecomment-3523395883
Original created: 2025-11-12T18:40:05Z
PR Compliance Guide 🔍
(Compliance updated until commit
github.com/carverauto/serviceradar@00abea0042)Below is a summary of compliance checks for this PR:
Sensitive information exposure
Description: Potential logging of host IP addresses in info-level logs and capability events may expose
sensitive infrastructure details; consider redacting or lowering log level where IPs are
included.
pollers.go [418-456]
Referred Code
Insecure transport usage
Description: Downloading onboarding package over HTTP client without explicit TLS configuration or
certificate pinning could allow MITM if Core API URL is non-TLS or insecure; ensure HTTPS
and proper TLS verification are enforced in runtime configs.
download.go [169-213]
Referred Code
🎫 #1936
null/array/object variations.
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: Robust Error Handling and Edge Case Management
Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation
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 actions like registering pollers as devices and updating poller status do not
emit explicit audit trail logs identifying actor/context beyond generic info logs, and may
require structured auditing.
Referred Code
Generic: Secure Error Handling
Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.
Status:
Verbose Errors: Returned errors propagate raw response messages from Core API to CLI output which may
expose internal details to end users depending on usage context.
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:
Token In Logs: Info logs after downloading or loading packages include identifiers and context, and code
handles join and download tokens where care is needed to avoid logging secrets though no
explicit redaction is shown.
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:
SQL Safety Check: The
getUserByFieldfunction builds a query with a dynamic field name which could be unsafewithout strict whitelisting though the value is parameterized; ensure
fieldis strictlycontrolled.
Referred Code
Compliance status legend
🟢 - Fully Compliant🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label
Previous compliance checks
Compliance check up to commit 6d99691
No security concerns identified
No security vulnerabilities detected by AI analysis. Human verification advised for critical code.🎫 #1936
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: Robust Error Handling and Edge Case Management
Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation
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
Generic: Comprehensive Audit Trails
Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.
Status:
Action Logging: New critical actions like registering pollers as devices and updating poller status are
performed without explicit additional audit log entries beyond existing info/warn logs,
making it unclear if audit requirements are met.
Referred Code
Generic: Secure Error Handling
Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.
Status:
Error Exposure: The API route proxies queries and may pass backend error messages through the SRQL
response; ensure user-facing errors remain generic and detailed errors are only logged
internally.
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:
Sensitive Logging: New logs include
host_ipfor devices during registration which could be sensitive; confirmlogging of IPs complies with privacy policies and log retention.
Referred Code
Imported GitHub PR comment.
Original author: @qodo-code-review[bot]
Original URL: https://github.com/carverauto/serviceradar/pull/1937#issuecomment-3523400131
Original created: 2025-11-12T18:41:14Z
PR Code Suggestions ✨
Latest suggestions up to
0022a97Fix incomplete INSERT statement
Add the missing
VALUESclause to theinsertUserStatementconstant to fix the SQLsyntax for user creation and update operations.
pkg/db/auth.go [27-98]
[To ensure code accuracy, apply this suggestion manually]Suggestion importance[1-10]: 10
__
Why: This suggestion correctly identifies a critical bug where the
insertUserStatementis missing theVALUESclause, which would cause all user creation and update operations to fail at runtime.Use upsert instead of insert
In
UpdateUser, replace theINSERTstatement with anUPSERT(INSERT ... ONCONFLICT ... DO UPDATE) to correctly update existing user records instead ofcreating duplicates.
pkg/db/auth.go [175-203]
Suggestion importance[1-10]: 9
__
Why: This suggestion correctly points out that using an
INSERTstatement inUpdateUseris a bug that would lead to duplicate data or errors, and it proposes a correctUPSERTpattern to fix it.Reinstate localhost bind safety
Reinstate the
listen_host: 127.0.0.1setting in the configuration file toprevent services from binding to all network interfaces and being accidentally
exposed externally.
packaging/proton/config/config.yaml [31-45]
[To ensure code accuracy, apply this suggestion manually]Suggestion importance[1-10]: 9
__
Why: The suggestion correctly identifies the removal of
listen_host: 127.0.0.1and raises a valid security concern about unintentionally exposing services on all network interfaces, which is a significant regression.Prevent Stop deadlock on watcher
In the
Stopfunction, replace the blocking wait ons.watchDonewith aselectstatement that includes a timeout. This prevents a potential deadlock during
shutdown if the config watcher goroutine exits without closing the channel.
pkg/sweeper/sweeper.go [523-562]
[To ensure code accuracy, apply this suggestion manually]Suggestion importance[1-10]: 8
__
Why: The suggestion correctly identifies a potential deadlock in the
Stopfunction if thewatchDonechannel is not closed, and proposes a robust solution using aselectwith a timeout to prevent the service from hanging on shutdown.Validate mandatory deliver fields
After decoding the
deliverResponseindownloadPackage, add checks to ensure thatdeliver.JoinTokenanddeliver.BundlePEMare not empty. ReturnErrJoinTokenEmptyor
ErrBundlePEMEmptyif they are, to fail fast.pkg/edgeonboarding/download.go [190-207]
[To ensure code accuracy, apply this suggestion manually]Suggestion importance[1-10]: 7
__
Why: The suggestion improves robustness by adding validation for essential fields from an API response, ensuring the program fails early with a clear error message instead of proceeding with invalid data.
Prevent spurious initial reload
In
StartWatch, prevent an unnecessary reload on initial startup by setting thebaseline snapshot and returning early if
prevSnapshotisnil.pkg/config/kv_client.go [467-510]
[To ensure code accuracy, apply this suggestion manually]Suggestion importance[1-10]: 7
__
Why: The suggestion correctly identifies that the current logic triggers an unnecessary reload on startup and proposes a valid fix to prevent this behavior, improving the startup sequence.
Restore correct engine arity
The
Streamengine signature was changed fromStream(1, 1, rand())toStream(1,rand()). Verify if this change in arity is correct and intended, as it mightaffect engine initialization or sharding semantics.
pkg/db/migrations/00000000000001_consolidated_serviceradar_schema.up.sql [49-55]
[To ensure code accuracy, apply this suggestion manually]Suggestion importance[1-10]: 7
__
Why: The suggestion correctly identifies a significant and repeated change to the
Streamengine signature but incorrectly assumes it's an error; the PR seems to intentionally remove the replica parameter for single-instance setups.Let IP resolution occur centrally
In
storePollerStatus, callregisterPollerAsDevicewith an empty string for theIP address instead of
normIP. This allowsregisterPollerAsDeviceto use its morecomprehensive internal logic to resolve the most reliable IP.
pkg/core/pollers.go [418-438]
[To ensure code accuracy, apply this suggestion manually]Suggestion importance[1-10]: 6
__
Why: The suggestion correctly identifies that
registerPollerAsDevicehas more robust IP resolution logic, and passing an empty string forces it to use its fallbacks, improving data quality.Fix missing VALUES in insert
Add the missing
VALUESclause with placeholders to theinsertPollerStatusQueryand provide all corresponding arguments to
batch.Appendto fix the malformedSQL.
pkg/db/pollers.go [391-412]
[To ensure code accuracy, apply this suggestion manually]Suggestion importance[1-10]: 9
__
Why: The suggestion correctly identifies a malformed SQL
INSERTstatement that is missing itsVALUESclause and has an incomplete list of arguments, which would cause a runtime error.Remove Buffer dependency in browser
Replace the Node.js
Bufferdependency with browser-native APIs likeTextEncoderand
btoafor base64url encoding to ensure client-side compatibility and preventruntime errors.
web/src/app/admin/edge-packages/page.tsx [19-250]
[To ensure code accuracy, apply this suggestion manually]Suggestion importance[1-10]: 8
__
Why: The suggestion correctly identifies that using Node's
Bufferin a Next.js client component can cause runtime errors in browsers and provides a robust, browser-native alternative to prevent potential crashes.Support more config kinds
Extend
cloneConfigValueto supportmapandslicetypes in addition topointerand
structto make the configuration snapshot logic more robust forhot-reloading.
pkg/config/kv_client.go [540-562]
Suggestion importance[1-10]: 7
__
Why: The suggestion correctly points out that the
cloneConfigValuefunction is incomplete and only handlesstructandpointertypes, which limits the hot-reloading feature.Preserve shard/replica semantics
Explicitly set
shardsandreplicasin theStreamengineSETTINGSto avoidpotential misconfiguration due to the changed engine signature.
pkg/db/migrations/00000000000001_consolidated_serviceradar_schema.up.sql [311-314]
Suggestion importance[1-10]: 5
__
Why: The suggestion correctly identifies a semantic change in the
Streamengine signature and proposes making the replica count explicit for robustness, which is a valid consideration during a version upgrade.Make Stop idempotent and thread-safe
Implement thread-safe, idempotent shutdown logic in
Stop()by usingsync.Oncetoprevent panics from closing the
s.donechannel multiple times concurrently.pkg/sweeper/sweeper.go [523-538]
[To ensure code accuracy, apply this suggestion manually]Suggestion importance[1-10]: 7
__
Why: The suggestion correctly identifies a potential panic from concurrent calls to
Stop()and proposes a valid solution usingsync.Onceto ensure the shutdown logic is idempotent and thread-safe.Validate URL in structured token
Validate that
coreApiUrlis an absolute URL before including it in thestructured token payload to prevent generating malformed tokens that would fail
during client bootstrapping.
web/src/app/admin/edge-packages/page.tsx [252-267]
[To ensure code accuracy, apply this suggestion manually]Suggestion importance[1-10]: 7
__
Why: The suggestion correctly points out a potential issue where an invalid
coreApiUrlcould lead to a malformed token, and proposes adding validation to improve the robustness of the token generation logic.Safer JSON negotiation default
Modify
shouldReturnJSONto treat a missing or wildcard (/)Acceptheader as arequest for JSON, improving compatibility with generic HTTP clients.
pkg/core/api/edge_onboarding.go [642-658]
Suggestion importance[1-10]: 6
__
Why: The suggestion improves the content negotiation logic by correctly handling the
*/*Acceptheader and defaulting to JSON, which enhances compatibility with generic HTTP clients.Previous suggestions
✅ Suggestions up to commit
e2c4260Harden discovery source parsing
Harden the parsing of
discovery_sourcesby rejecting objects with unknown keysand adding limits on token length and total byte size to mitigate security risks
from malicious input.
web/src/components/Devices/DeviceDetail.tsx [60-253]
Suggestion importance[1-10]: 7
__
Why: The suggestion provides valid security hardening for parsing
discovery_sourcesby adding checks for disallowed keys and imposing byte limits, which helps prevent potential DoS or unexpected UI behavior from malicious data.✅
Fix aggregation detection and routingSuggestion Impact:
The commit updated the AGGREGATION_PATTERN to explicitly list token boundary characters, aligning with the suggestion to improve aggregation detection. Other parts of the suggestion (comment stripping and multi-stream handling) were not implemented in this diff.code diff:
Improve the query routing logic by adding support for stripping comments and
ensuring the device planner is not used for queries involving multiple streams.
web/src/app/api/query/route.ts [13-76]
[Suggestion processed]Suggestion importance[1-10]: 6
__
Why: The suggestion correctly identifies that the routing logic could be more robust by handling comments and multi-stream queries, which could prevent incorrect routing to the device planner.
✅
Prevent service-device record coalescingSuggestion Impact:
The commit changed the key selection logic to prioritize DeviceID for service devices (models.IsServiceDevice), matching the suggestion to avoid coalescing with hosts.code diff:
To prevent undercounting, modify the canonical record selection logic to use the
unique
DeviceIDas the key for service devices, ensuring they are not mergedwith other device records.
pkg/core/stats_aggregator.go [454-574]
[Suggestion processed]Suggestion importance[1-10]: 7
__
Why: This suggestion correctly identifies a potential edge case where service devices could be incorrectly merged with host devices if they share a
canonicalID. The proposed change makes the new device counting logic more robust by explicitly using the uniqueDeviceIDfor service components, ensuring they are always counted separately.✅ Suggestions up to commit
8a76746✅
Avoid misrouting when "stats:" appears in valuesSuggestion Impact:
The commit updated the aggregation regex to require a token boundary and added logic to check that matches are not inside quotes, then used this check in shouldUseDevicePlanner—addressing the misrouting issue as suggested.code diff:
Improve the regex for detecting aggregations in
shouldUseDevicePlannerto avoidincorrectly identifying "stats:" within string values, ensuring queries are
routed correctly.
web/src/app/api/query/route.ts [11-37]
[Suggestion processed]Suggestion importance[1-10]: 6
__
Why: The suggestion correctly identifies a potential flaw in the regex and proposes a more robust solution to prevent false positives, improving the reliability of the query routing logic.
✅
Sanitize discovery_sources normalizationSuggestion Impact:
The commit implements a secure refactor of ensureArray: adds plain object checks, whitelists allowed keys, caps array size via MAX_DISCOVERY_SOURCES, and tokenizes strings—matching the suggestion’s intent.code diff:
Refactor the
ensureArrayfunction to more securely handlediscovery_sourcesbyvalidating object shapes, only accepting whitelisted keys, and capping the
output array length.
web/src/components/Devices/DeviceDetail.tsx [192-221]
[Suggestion processed]Suggestion importance[1-10]: 4
__
Why: The suggestion provides a more robust and secure implementation for the
ensureArrayfunction by adding stricter type checking and length capping, though the described risks are somewhat theoretical.✅
Keep service devices uniquely canonicalSuggestion Impact:
The commit changed the key selection logic to prioritize DeviceID for service devices, then canonicalID, matching the suggestion’s intent to uniquely key service devices.code diff:
In
selectCanonicalRecords, modify the key selection logic to always userecord.DeviceIDas the canonical key for service devices. This prevents themfrom being incorrectly merged with other device records that might share the
same canonical ID alias.
pkg/core/stats_aggregator.go [454-572]
Suggestion importance[1-10]: 9
__
Why: This suggestion identifies a critical edge case where service devices could be incorrectly deduplicated against other devices if they share a common alias (like an IP address), leading to undercounting. Forcing service devices to use their unique
DeviceIDas the canonical key is a robust solution to ensure they are always counted separately, which aligns with the PR's intent.✅
Validate and normalize host IPsSuggestion Impact:
The commit added a normalizeHostIP function and applied it across the code: when storing poller status, when registering pollers and services, and when resolving host IPs, including metadata and fallback cases. It also replaced raw req.SourceIp usage with the normalized IP in multiple paths.code diff:
Add a function to normalize and validate the
hostIPbefore it is stored or usedfor device registration. This function should handle trimming, stripping IPv6
brackets and ports, and use
net.ParseIPfor validation.[pkg/core/pollers.go [389-410]](https://github.com/carverauto/serviceradar/pull/1937/files#diff-fe81e2a32f1ac64bcdc6f25f55c5fa918d17bad8c0546f2cf80c757ff40...
Imported GitHub PR comment.
Original author: @qodo-code-review[bot]
Original URL: https://github.com/carverauto/serviceradar/pull/1937#issuecomment-3523729101
Original created: 2025-11-12T20:13:08Z
Persistent suggestions updated to latest commit
96ebe5aImported GitHub PR comment.
Original author: @qodo-code-review[bot]
Original URL: https://github.com/carverauto/serviceradar/pull/1937#issuecomment-3523760389
Original created: 2025-11-12T20:23:16Z
Persistent suggestions updated to latest commit
8a76746