Code Monkey home page Code Monkey logo

demo-resilience's Introduction

Demo resilience

Demo resilience is a demo project showing how to use resilience4j & spring boot.

Resilience patterns are applied to a Spring Boot application which connects with two services implemented with Node.js

Components Diagram

Build

  • Spring Boot Project
./gradlew bootJar
  • External service image
docker build external-service -t external-service

Local Run

  • Run external services
# run service-a
docker stop service-a
docker rm service-a
docker run -d \
-p 8081:80 \
-v "$(pwd)/src/main/k8s/config/service-a":"/usr/src/app/config" \
--name service-a \
external-service:latest

# test service-a
curl -X GET http://localhost:8081/message -H "Accept: application/json"
curl -X POST http://localhost:8081/message -H "Content-type: application/json" -d '{"sample-attr": "test"}'

# run service-b
docker stop service-b
docker rm service-b
docker run -d \
-p 8082:80 \
-v "$(pwd)/src/main/k8s/config/service-b":"/usr/src/app/config" \
--name service-b \
external-service:latest

# test service-b
curl -X GET http://localhost:8082/message -H "Accept: application/json"
curl -X POST http://localhost:8082/message -H "Content-type: application/json" -d '{"sample-attr": "test"}'
  • Run Spring Boot Project
# start service
./gradlew bootRun -Pargs="-Dservices.backendA.base-url=http://localhost:8081,-Dservices.backendB.base-url=http://localhost:8082"

# test service
curl -X GET http://localhost:8080/serviceA -H "Accept: application/json"
curl -X POST http://localhost:8080/serviceA -H "Content-type: application/json" -d '{"sample-attr": "test"}'

curl -X GET http://localhost:8080/serviceB -H "Accept: application/json"
curl -X POST http://localhost:8080/serviceB -H "Content-type: application/json" -d '{"sample-attr": "test"}'
  • Test
# stop service-a
docker stop service-a

# stop service-b
docker stop service-b

Local Run (KinD + skaffold)

install skaffold

curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/v1.12.1/skaffold-linux-amd64
sudo install skaffold /usr/local/bin/

install kustomize

curl -s "https://raw.githubusercontent.com/\
kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"  | bash
sudo chown root:root kustomize
sudo mv kustomize /usr/local/bin/

Install KindD

sudo curl -Lo /usr/local/bin/kind https://kind.sigs.k8s.io/dl/v0.8.1/kind-$(uname)-amd64 && sudo chmod +x /usr/local/bin/kind
# see: https://kind.sigs.k8s.io/docs/user/ingress/
cat <<EOF | kind create cluster --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  kubeadmConfigPatches:
  - |
    kind: InitConfiguration
    nodeRegistration:
      kubeletExtraArgs:
        node-labels: "ingress-ready=true"
  extraPortMappings:
  - containerPort: 80
    hostPort: 80
    protocol: TCP
  - containerPort: 443
    hostPort: 443
    protocol: TCP
EOF

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/kind/deploy.yaml

Run Skaffold

  • Edit hosts file
# edit hosts file
sudo vi /etc/hosts
cat /etc/hosts | grep localhost
127.0.0.1       localhost demo-resilience.local-k8s
  • Run
skaffold dev --trigger notify
  • Test services (Node Port)
kubectl get nodes -o wide
# external-ip = 172.18.0.2
# service a
curl -X POST http://172.18.0.2:30080/message -H "Content-type: application/json" -d '{"sample-attr": "test"}'
# service b
curl -X POST http://172.18.0.2:30081/message -H "Content-type: application/json" -d '{"sample-attr": "test"}'
  • test
curl http://demo-resilience.local-k8s/api/actuator/health
curl http://demo-resilience.local-k8s/api/actuator/prometheus

#service A
curl http://demo-resilience.local-k8s/api/serviceA
curl -X POST http://demo-resilience.local-k8s/api/serviceA -H "Content-type: application/json" -d '{"sample-attr": "test"}'

#service A
curl http://demo-resilience.local-k8s/api/serviceB
curl -X POST http://demo-resilience.local-k8s/api/serviceB -H "Content-type: application/json" -d '{"sample-attr": "test"}'


#disable service a
kubectl patch service service-a -p '{"spec":{"selector":{"name": "service-unknown"}}}'
#enable service a
kubectl patch service service-a -p '{"spec":{"selector":{"name": "service-a"}}}'

Prometheus

Check the Prometheus server.

Grafana

Configure the Grafana.

load test

./gradlew gatlingRun

# trigger chaos

# https://www.npmjs.com/package/chaos-monkey
#Browse to http/s://{host}/chaos and trigger some chaos
#Invoke the API POST: http/s://{host}/chaos/random

monitoring

demo-resilience's People

Watchers

Sergi Calvet avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.