adding a supervisor for the supervisor #2689
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!2689
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "refs/pull/2689/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: #2336
Original author: @mfreeman451
Original URL: https://github.com/carverauto/serviceradar/pull/2336
Original created: 2026-01-18T07:26:50Z
Original updated: 2026-01-18T07:30:18Z
Original head: carverauto/serviceradar:fix/nats-supervisor
Original base: staging
Original merged: 2026-01-18T07:30:16Z 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
Refactor NATS connection management to use
Gnat.ConnectionSupervisorfor fault toleranceCreate new
ServiceRadar.NATS.Supervisormodule wrapping connection supervisorSimplify
ServiceRadar.NATS.Connectionto provide API-only interfaceEliminate manual reconnection logic and health checks in favor of supervisor-managed auto-reconnect
Diagram Walkthrough
File Walkthrough
application.ex
Update application supervision tree for NATS supervisorelixir/serviceradar_core/lib/serviceradar/application.ex
nats_connection_child()to returnServiceRadar.NATS.Supervisorinstead of
ServiceRadar.NATS.Connectionwith auto-reconnect capability
connection.ex
Refactor to stateless API layer for NATS publishingelixir/serviceradar_core/lib/serviceradar/nats/connection.ex
module
health checks
get()andget!()to query connection PID viaProcess.whereis()publish()to use supervised connection with error handling fordead connections
connected?()andstatus()to query current connection statestart_link()andreconnect()as no-ops for backward compatibilitysupervisor.ex
New supervisor module for fault-tolerant NATS connectionselixir/serviceradar_core/lib/serviceradar/nats/supervisor.ex
Gnat.ConnectionSupervisorTLS, and credentials
ServiceRadar.NATS.Credsreconnection on failure
Imported GitHub PR comment.
Original author: @qodo-code-review[bot]
Original URL: https://github.com/carverauto/serviceradar/pull/2336#issuecomment-3765011492
Original created: 2026-01-18T07:27:26Z
PR Compliance Guide 🔍
Below is a summary of compliance checks for this PR:
Sensitive info exposure
Description: The warning log on credential-read failure includes the raw
creds_filepath(
Logger.warning("Failed to read NATS creds file #{creds_file}: ...")), which can exposesensitive filesystem layout and secret file locations to anyone with log access.
supervisor.ex [160-168]
Referred Code
Insecure TLS options
Description: TLS configuration accepts arbitrary
ssl_optsfrom config (tls_opts whenis_list(tls_opts)), which can enable insecure settings (e.g.,verify: :verify_none) andsilently weaken transport security if misconfigured.
supervisor.ex [142-155]
Referred 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: Security-First Input Validation and Data Handling
Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities
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:
Error details exposed:
get!/0raises an exception string containinginspect(reason), which could leak internaldetails if this propagates to any user-facing boundary.
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 data in logs: Logging
inspect(reason)for NATS credential file read failures may inadvertently logsensitive or overly-informative details depending on the underlying error structure.
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/2336#issuecomment-3765012082
Original created: 2026-01-18T07:28:24Z
PR Code Suggestions ✨
Explore these optional code suggestions:
Catch exceptions in publish
Add a
rescueclause to thetryblock in thepublish/3function to catch andhandle exceptions from
Gnat.pub/4, returning an error tuple instead of crashing.elixir/serviceradar_core/lib/serviceradar/nats/connection.ex [77-91]
Suggestion importance[1-10]: 7
__
Why: This is a valuable suggestion for improving robustness by adding a
rescueclause to handle potential exceptions fromGnat.pub/4, preventing the calling process from crashing.Fail supervisor on bad config
Change the
init/1function to raise an exception on invalid NATS configurationinstead of silently starting without the NATS supervisor.
elixir/serviceradar_core/lib/serviceradar/nats/supervisor.ex [56-75]
[To ensure code accuracy, apply this suggestion manually]Suggestion importance[1-10]: 6
__
Why: The suggestion proposes a "fail-fast" approach, which is a valid strategy. However, the current implementation of silently disabling NATS on configuration error is also a reasonable design choice to prevent the entire application from crashing.
Refactor logic using a
withstatementRefactor the
build_connection_settings/1function to use awithstatement formore idiomatic and readable error handling.
elixir/serviceradar_core/lib/serviceradar/nats/supervisor.ex [78-112]
Suggestion importance[1-10]: 5
__
Why: The suggestion correctly identifies an opportunity to refactor the code using a
withstatement, which is more idiomatic in Elixir and improves readability by flattening the control flow.Return a valid child spec or empty list
Modify
nats_connection_child/0to return an empty list[]instead ofnilwhenNATS is disabled to avoid injecting
nilinto the supervision tree.elixir/serviceradar_core/lib/serviceradar/application.ex [325-331]
Suggestion importance[1-10]: 4
__
Why: While returning
nilis handled by OTP supervisors, the suggestion to return an empty list[]instead is a good practice for consistency, though it may require flattening the children list.