A high-performance, distributed traceroute service built with Elixir/OTP that provides both HTTP REST API and NATS message-based network path tracing capabilities.
# Clone the repository
git clone <repository-url>
cd traceroute
# Install dependencies
mix deps.get
# Set up environment
source local-test.env # if available
# Run tests
mix test
# Start the service
mix run --no-halt
# Build the image
docker build -t traceroute:latest .
# Run with CAP_NET_RAW capability for ICMP (recommended - more secure)
docker run --cap-add=NET_RAW -p 4100:4100 traceroute:latest
# Alternative: Run with full privileged access (less secure)
docker run --privileged -p 4100:4100 traceroute:latest
Security Note: The image now runs as a non-root user (appuser:1001) with only the CAP_NET_RAW capability required for ICMP operations. This follows security best practices while maintaining full traceroute functionality.
NATS_HOST - NATS server host (default: "nats")NATS_PORT - NATS server port (default: 4222)HTTP_PORT - HTTP service port (default: 4100)MIX_ENV - Environment (dev/test/prod)The service connects to NATS for distributed message processing:
# Configured in lib/tracer.ex
%{
host: System.get_env("NATS_HOST", "nats"),
port: String.to_integer(System.get_env("NATS_PORT", "4222"))
}
Endpoint: POST /traceroute
Request:
curl -X POST http://localhost:4100/traceroute \
-H "Content-Type: application/json" \
-d '{"host": "google.com"}'
Response:
{
"status": 200,
"body": {
"result": "ok",
"message": "Traceroute successful to google.com",
"next_hop_ip": "172.217.14.46",
"next_hop_hostname": "lga25s78-in-f14.1e100.net",
"next_hop_fqdn": "lga25s78-in-f14.1e100.net"
}
}
Topic: traceroute.request
Message Format:
{
"body": "google.com",
"reply_to": "response.topic"
}
Response: JSON structure similar to HTTP API response
Tracer - Main application supervisorTracer.Worker - Traceroute execution logicTracer.Web.Handler - HTTP request handlerNATS.Listener - NATS message processorTracer.Web.Supervisor - Web server supervisionTracer.Web.Handler โ Tracer.Worker โ ResponseNATS.Listener โ Tracer.Worker โ ReplyTracer.Workertrace/1 - Main traceroute executionclean_timeouts/1 - Filter timeout responsesget_last_hop/1 - Extract meaningful hop informationprocess_results/2 - Format response data# Run all tests
mix test
# Run with coverage
mix test --cover
# Run specific test files
mix test test/trace/worker_test.exs
mix test test/trace/handler_test.exs
# Run excluding privileged tests
mix test --exclude integration
Current coverage: 89.0%
| Module | Coverage | Lines | Missed |
|---|---|---|---|
lib/tracer.ex | 100.0% | 5 | 0 |
lib/trace/supervisor.ex | 100.0% | 3 | 0 |
lib/trace/listener.ex | 100.0% | 5 | 0 |
lib/trace/worker.ex | 92.8% | 28 | 2 |
lib/nats_listener.ex | 90.9% | 11 | 1 |
lib/trace/handler.ex | 88.8% | 9 | 1 |
test/trace/worker_test.exs, test/trace/handler_test.exstest/integration_test.exstest/nats_listener_test.exstest/trace/supervisor_test.exs# Test-only dependencies in mix.exs
{:mox, "~> 1.1", only: :test}, # Mocking
{:stream_data, "~> 1.0", only: :test}, # Property-based testing
{:excoveralls, "~> 0.18", only: :test}, # Coverage reporting
{:ex_machina, "~> 2.8", only: :test} # Test factories
FROM elixir:1.18.4 AS builder
# Multi-stage build for optimized production image
# Includes libssl for cryptographic operations
# devspace.yaml for Kubernetes development
deployments:
- name: traceroute
helm:
chart:
name: ./charts/traceroute
The service provides structured logging:
# Production build
MIX_ENV=prod mix release
# Docker production
docker build --build-arg BUILD_ENV=prod -t traceroute:prod .
# Kubernetes deployment
kubectl apply -f k8s/
.tool-versions)mix setup to install dependenciesmix test# Format code
mix format
# Run static analysis
mix credo
# Type checking (if configured)
mix dialyzer
# Full quality suite
mix quality
See LICENSE file for details.
For issues and support:
Built with โค๏ธ using Elixir/OTP for reliable, concurrent network diagnostics.
Content type
Image
Digest
sha256:010451947โฆ
Size
33.2 MB
Last updated
3 months ago
docker pull calltelemetry/traceroute