Docker-Compose

Table of contents

  1. Run
  2. Configuration
  3. Loggers
    1. Seq
    2. ELK
  4. Examples

Run

version: "3"
services:
  echo-server:
    image: ealen/echo-server:0.9.2
    ports:
      - 3000:80
➜ docker-compose up -d
➜ curl -I localhost:3000
HTTP/1.1 200 OK

Configuration

You can use environment variables More information

version: "3"
services:
  echo-server:
    image: ealen/echo-server:0.9.2
    environment:
      - ENABLE__ENVIRONMENT=false
    ports:
      - 3000:80

Loggers

More information

Seq

version: "3"
services:
  # ----------------------------------
  # ECHO-SERVER
  # ----------------------------------
  echo:
    image: ealen/echo-server:0.9.2
    restart: unless-stopped
    environment:
      PORT: 80
      LOGS__SEQ__ENABLED: "true"
      LOGS__SEQ__SERVER: "http://seq:5341"
    ports:
      - 3000:80

  # ----------------------------------
  # SEQ
  # ----------------------------------
  seq:
    image: datalust/seq:latest
    restart: unless-stopped
    environment:
      ACCEPT_EULA: "Y"
    ports:
      - 3010:80

ELK

# ./logstash/logstash.conf
input {
  tcp {
    port => 8089
  }
}

output {
  elasticsearch { hosts => ["elasticsearch:9200"] }
}
version: "3"
services:
  # ----------------------------------
  # ECHO-SERVER
  # ----------------------------------
  echo:
    image: ealen/echo-server:0.9.2
    restart: unless-stopped
    logging:
      driver: syslog
      options:
        syslog-address: "tcp://localhost:8089"
    environment:
      - "LOGS__FORMAT=object"
    depends_on:
      - logstash
    ports:
      - 3000:80

  # ----------------------------------
  # ELK
  # ----------------------------------
  elasticsearch:
    image: elasticsearch:7.7.0
    hostname: elasticsearch
    restart: unless-stopped
    environment:
      - "discovery.type=single-node"
  kibana:
    image: kibana:7.7.0
    hostname: kibana
    restart: unless-stopped
    depends_on:
      - elasticsearch
    ports:
      - 3010:5601
  logstash:
    image: logstash:7.7.0
    hostname: logstash
    restart: unless-stopped
    volumes:
      - ./logstash:/usr/share/logstash/pipeline/
    depends_on:
      - elasticsearch
    ports:
      - 8089:8089

Examples

Custom responses

Query Header Content Conditions
?echo_code= X-ECHO-CODE HTTP code 200, 404 200 <= CODE <= 599
    404-401 or 200-500-301  
?echo_body= X-ECHO-BODY Body message  
?echo_env_body= X-ECHO-ENV-BODY The key of environment variable Enable environment true
?echo_header= X-ECHO-HEADER Response Header Lang: en-US Enable header true
?echo_time= X-ECHO-TIME Wait time in ms 0 <= TIME <= 60.000
?echo_file= X-ECHO-FILE Path of Directory or File Enable file true

You can change commands and conditions.

Custom HTTP Status Code

➜ curl -I --header 'X-ECHO-CODE: 404' localhost:3000
➜ curl -I localhost:3000/?echo_code=404

HTTP/1.1 404 Not Found
➜ curl -I --header 'X-ECHO-CODE: 404-300' localhost:3000
➜ curl -I localhost:3000/?echo_code=404-300

HTTP/1.1 404 Not Found
HTTP/1.1 300 Multiple Choices
for i in {1..10}do
➜    curl -I localhost:3000/?echo_code=200-400-500
➜ done

HTTP/1.1 500 Internal Server Error
HTTP/1.1 400 Bad Request
HTTP/1.1 200 OK
HTTP/1.1 500 Internal Server Error
HTTP/1.1 200 OK
HTTP/1.1 500 Internal Server Error

Custom Body

➜ curl --header 'X-ECHO-BODY: amazing' localhost:3000
➜ curl localhost:3000/?echo_body=amazing

"amazing"

Custom Body with environment variable value

➜ curl --header 'X-ECHO-ENV-BODY: HOSTNAME' localhost:3000
➜ curl localhost:3000/?echo_env_body=HOSTNAME

"c53a9ed79fa2"
for i in {1..10}do
➜    curl localhost:3000/?echo_env_body=HOSTNAME
➜ done

"c53a9ed79fa2"
"f10c3af61e40"
"c53a9ed79fa2"
"f10c3af61e40"
"c53a9ed79fa2"

Custom Headers

➜ curl --header 'X-ECHO-HEADER: One:1' localhost:3000
➜ curl localhost:3000/?echo_header=One:1

HTTP/1.1 200 OK
One: 1
➜ curl --header 'X-ECHO-HEADER: One:1, Two:2' localhost:3000
➜ curl "localhost:3000/?echo_header=One:1,%20Two:2"

HTTP/1.1 200 OK
One: 1
Two: 2

Custom response latency

➜ curl --header 'X-ECHO-TIME: 5000' localhost:3000
➜ curl "localhost:3000/?echo_time=5000"

⏳... 5000 ms

You can change default validations with

ENVIRONMENT CLI Default
CONTROLS__TIMES__MIN –controls:times:min 0
CONTROLS__TIMES__MAX –controls:times:max 60000

(Latency is defined in milliseconds)

File/Folder explorer

➜ curl --header 'X-ECHO-FILE: /' localhost:3000
➜ curl "localhost:3000/?echo_file=/"

["app", "bin", "etc", "usr", "var"]

Combine custom actions

➜ curl --header 'X-ECHO-CODE: 401' --header 'X-ECHO-BODY: Oups' localhost:3000
➜ curl "localhost:3000/?echo_body=Oups&echo_code=401"

HTTP/1.1 401 Unauthorized
"Oups"