This is a small HTTP server that sends back the incoming request with all the metadata in response
10K+
This project is a small HTTP server that returns the incoming request with metadata in the response, including the sender's IP address, all request parameters, and headers. The server's configuration can be modified using environment variables. Additionally, the server supports CPU and memory load testing and provides metrics in Prometheus format. The running server's parameters can be modified via API.
The server can be run as a Docker container or Kubernetes resources for x86 or ARM platforms. It can also be run as compiled binary files or compiled from source code.
kubectl run test --image viktoruj/ping_pong
kubectl run test --image viktoruj/ping_pong --env SERVER_NAME=pingPongServer
kubectl run test --image viktoruj/ping_pong --env ENABLE_DEFAULT_HOSTNAME=false
kubectl run test --image viktoruj/ping_pong --env MEMORY_USAGE_PROFILE='5=60 20=60 1024=360 ' --env ENABLE_LOAD_MEMORY=true
kubectl run test --image viktoruj/ping_pong --env CPU_USAGE_PROFILE='1=400=1=60 1=4=1=60 10=1=4=60' --env ENABLE_LOAD_CPU=true --env ENABLE_LOG_LOAD_CPU=true --env CPU_MAXPROC=2 --env MEMORY_USAGE_PROFILE='5=60 20=60 1024=360 ' --env ENABLE_LOAD_MEMORY=true --env ENABLE_LOG_LOAD_MEMORY=true
kubectl run test --image viktoruj/ping_pong --env DELAY_START=10
kubectl run test --image viktoruj/ping_pong --env RESPONSE_DELAY=3000 --env MAX_RESPONSE_WORKER=10
| ENV VAR | APP VAR | set via API | Description |
|---|---|---|---|
SERVER_NAME | serverName | Yes | The name of the server. Default is ping_pong_server. |
ENABLE_DEFAULT_HOSTNAME | enableDefaultHostName | Yes | Use the default hostname (default = "true"). |
SRV_PORT | serverPort | No | The port on which the server is running. |
METRIC_PORT | metricPort | No | The port where server metrics are available in Prometheus format. You can view the current metrics at {server_address}:{METRIC_PORT}/metrics. |
ENABLE_OUTPUT | enableOutput | Yes | Log to stdout (default = "true"). |
LOG_PATH | logPath | Yes | Write logs to file ${LOG_PATH} (default="" without file output). |
ENABLE_LOAD_MEMORY | enableLoadMemory | Yes | Enable memory usage (default=false). |
MEMORY_USAGE_PROFILE | memoryProfileStr | Yes | Additional memory usage and time for usage. Example: 5=10 7=60 1024=360. |
ENABLE_LOG_LOAD_MEMORY | enableLogLoadMemory | Yes | Logs LOAD_MEMORY function. |
ENABLE_LOAD_CPU | enableLoadCpu | Yes | Enable CPU usage (default=false). |
ENABLE_LOG_LOAD_CPU | enableLogLoadCpu | Yes | Logs LOAD_CPU function. |
CPU_USAGE_PROFILE | cpuProfileStr | Yes | Additional CPU usage iteraction_milion=wait_msec=gorutins=time_sec. Example: 10=1=1=30 1=400=1=60. |
CPU_MAXPROC | cpuMaxProc | Yes | GOMAXPROCS (default = 1). How many cores to use. |
DELAY_START | parsedDelay | No | Delay start in seconds before start app (default = 0). Useful for testing slow start of app and test startup probes. |
RESPONSE_DELAY | responseDelay | Yes | Response delay in milliseconds. |
MAX_RESPONSE_WORKER | maxResponseWorker | Yes | Maximum number of response workers. |
docker run -d -p 8080:8080 viktoruj/ping_pong
The images work on x86 and ARM platforms.
latest - from scratch image with only binary. Dockerfilealpine - alpine image with binary and utils. Dockerfile_alpinedebug - amazon/aws-cli image with utils. Dockerfile_debug_arm and Dockerfile_debug_x86 .sudo xattr -d com.apple.quarantine ping-pong-darwin-amd64
sudo chmod +x ping-pong-darwin-amd64
./ping-pong-darwin-amd64
# or
SERVER_NAME=myCustomServer ./ping-pong-linux-amd64
# check server
curl 127.0.0.1:8080
sudo chmod +x ping-pong-linux-amd64
./ping-pong-linux-amd64
# or
SERVER_NAME=myCustomServer ./ping-pong-linux-amd64
# check server
curl 127.0.0.1:8080
copy ping-pong-android-arm64 to /data/data/com.termux/files/usr/bin/
chmod +x /data/data/com.termux/files/usr/bin/ping-pong-android-arm64
ping-pong-android-arm64
cd docker/ping_pong/app
go mod tidy
go run app.go # or go build app.go
/ping-pong-api/getVar - get all ping-pong variables/ping-pong-api/setVar - set ping-pong variables/ping-pong-api/osInfo - get os info/ping-pong-api/panic - emulate crash app/ping-pong-api/getMetric - get metriccurl {ping-pong ip}:8080/ping-pong-api/getVar -s | jq
{
"cpuMaxProc": 2,
"cpuProfileStr": "1000=1=1=30",
"delayStart": 0,
"enableDefaultHostName": "true",
"enableLoadCpu": "true",
"enableLoadMemory": "false",
"enableLogLoadCpu": "true",
"enableLogLoadMemory": "false",
"enableOutput": "true",
"hostName": "ping_pong_server",
"logPath": "",
"memoryProfiles": null,
"serverName": "ping_pong_server"
}
curl -X POST "http://{ping-pong ip}:8080/ping-pong-api/setVar" -H "Content-Type: application/json" -d '{"enableLoadCpu":"true", "cpuProfileStr":"1000=1=1=30","cpuMaxProc":2}' -s | jq
{
"changes": {
"cpuMaxProc": {
"new": "2",
"old": "1"
},
"cpuProfileStr": {
"new": "1000=1=1=30",
"old": "1000=1=2=30"
},
"enableLoadCpu": {
"new": "true",
"old": "false"
}
},
"status": "Variables updated. Handlers reloaded."
}
curl {ping-pong ip}:8080/ping-pong-api/osInfo -s | jq
{
"architecture": {
"architecture": "amd64",
"goamd64": "v4",
"goarm": ""
},
"cpu": {
"cores": [
{
"core": 1,
"unit": "percentage",
"usage": 13.7
},
{
"core": 2,
"unit": "percentage",
"usage": 7.6
},
.............
curl {ping-pong ip}:8080/ping-pong-api/getMetric -s | jq
{
"goroutines": 6,
"requests_per_minute": 0,
"requests_per_second": 0,
"requests_total": 0
}
curl {ping-pong ip}:8080/ping-pong-api/panic -s
# in app log
Panic occurred: Test panic
exit status 1
Content type
Image
Digest
sha256:32d367cdf…
Size
5.2 MB
Last updated
2 months ago
docker pull viktoruj/ping_pong