分布式跟踪在dapr里是开箱即用的,不需要对应用作任何一丁点的侵入式编程。之前的开发,如果想实现分式跟踪,就得在应用中埋点,这是一个与业务无关系的动作。dpar通过sidecar可以轻松做到这点,从而让程序员更多精力投入到业务中,又让运维得到可观测性能数据,对服务运维保驾护航。从此以后,开发和运维再没有爱恨情愁,可以友好的做朋友。
接上一篇的docker-compose部署,在docker-compose.yam中只需要增加zipkin在的节点,并且每个服务的sidecar启动时指定zipkin配置即可。
version: '3.4'
services:#┌────────────────────────────────┐#│ ordersystem app + Dapr sidecar │#└────────────────────────────────┘ordersystem:image: ${DOCKER_REGISTRY-}ordersystemdepends_on:- redis- placement - rabbitmq - zipkin build:context: ../dockerfile: OrderSystem/Dockerfileports:- "3500:3500" volumes: - ../OrderSystem:/OrderSystem networks:- b2c-daprordersystem-dapr:image: "daprio/daprd:latest"command: [ "./daprd", "-app-id", "order", "-app-port", "80","-placement-host-address", "placement:50006","-components-path","/components","-config","/home/nonroot/.dapr/config.yaml" ]depends_on:- ordersystemnetwork_mode: "service:ordersystem"volumes: - ../components:/components - ../:/home/nonroot/.dapr #┌───────────────────────────────────┐#│ paymentsystem1 app + Dapr sidecar │#└───────────────────────────────────┘ paymentsystem1:image: ${DOCKER_REGISTRY-}paymentsystemdepends_on:- redis- placement - rabbitmq - zipkin build:context: ../dockerfile: PaymentSystem/Dockerfileports:- "3601:3500"volumes: - ../PaymentSystem:/PaymentSystem networks:- b2c-dapr paymentsystem1-dapr:image: "daprio/daprd:latest"command: [ "./daprd", "-app-id", "pay", "-app-port", "80","-placement-host-address", "placement:50006","-components-path","/components","-config","/home/nonroot/.dapr/config.yaml" ]depends_on:- paymentsystem1network_mode: "service:paymentsystem1"volumes: - ../components:/components - ../:/home/nonroot/.dapr #┌───────────────────────────────────┐#│ paymentsystem2 app + Dapr sidecar │#└───────────────────────────────────┘ paymentsystem2:image: ${DOCKER_REGISTRY-}paymentsystemdepends_on:- redis- placement - rabbitmq - zipkin build:context: ../dockerfile: PaymentSystem/Dockerfilevolumes: - ../PaymentSystem:/PaymentSystem ports:- "3602:3500"networks:- b2c-dapr paymentsystem2-dapr:image: "daprio/daprd:latest"command: [ "./daprd", "-app-id", "pay", "-app-port", "80" ,"-placement-host-address", "placement:50006","-components-path","/components","-config","/home/nonroot/.dapr/config.yaml"]depends_on:- paymentsystem2network_mode: "service:paymentsystem2"volumes: - ../components:/components - ../:/home/nonroot/.dapr #┌───────────────────────────────────┐#│ noticesystem1 app + Dapr sidecar │#└───────────────────────────────────┘ noticesystem1:image: ${DOCKER_REGISTRY-}noticesystemdepends_on:- redis- placement - rabbitmq - zipkin build:context: ../dockerfile: NoticeSystem/Dockerfileports:- "3701:3500"volumes: - ../NoticeSystem:/NoticeSystem networks:- b2c-dapr noticesystem1-dapr:image: "daprio/daprd:latest"command: [ "./daprd", "-app-id", "notice", "-app-port", "80","-placement-host-address", "placement:50006","-components-path","/components","-config","/home/nonroot/.dapr/config.yaml" ]depends_on:- noticesystem1network_mode: "service:noticesystem1"volumes: - ../components:/components - ../:/home/nonroot/.dapr #┌───────────────────────────────────┐#│ noticesystem2 app + Dapr sidecar │#└───────────────────────────────────┘ noticesystem2:image: ${DOCKER_REGISTRY-}noticesystemdepends_on:- redis- placement - rabbitmq - zipkin build:context: ../dockerfile: NoticeSystem/Dockerfileports:- "3702:3500"volumes: - ../NoticeSystem:/NoticeSystem networks:- b2c-dapr noticesystem2-dapr:image: "daprio/daprd:latest"command: [ "./daprd", "-app-id", "notice", "-app-port", "80","-placement-host-address", "placement:50006","-components-path","/components" ,"-config","/home/nonroot/.dapr/config.yaml"]depends_on:- noticesystem2network_mode: "service:noticesystem2"volumes: - ../components:/components - ../:/home/nonroot/.dapr #┌────────────────────────┐#│ Dapr placement service │#└────────────────────────┘ placement:image: "daprio/dapr"command: ["./placement", "-port", "50006"]ports:- "50006:50006"networks:- b2c-dapr#┌──────────────────────────┐#│ Zipkin service │#└──────────────────────────┘ zipkin:image: "openzipkin/zipkin"ports:- "9411:9411"networks:- b2c-dapr#┌───────────────────┐#│ Redis state store │#└───────────────────┘ redis:image: "redis:latest"ports:- "6379:6379"networks:- b2c-dapr#┌──────────────────────┐#│ RabbitMQ │#└──────────────────────┘ rabbitmq:image: "rabbitmq:management"ports:- "15672:15672"- "5672:5672" environment:- RABBITMQ_DEFAULT_USER=admin- RABBITMQ_DEFAULT_PASS=!2021que networks:- b2c-dapr networks:b2c-dapr:
config.yaml,指定了tracing的配置,zipkin的地址是:http://zipkin:9411/api/v2/spans
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:name: daprConfig
spec:tracing:samplingRate: "1"zipkin:endpointAddress: http://zipkin:9411/api/v2/spans
这是一个调用的跟踪结果(一)
这是一个调用的跟踪结果(二)
这是一个调用的跟踪结果(三)
这是一个发布订阅的跟踪结果(一)
这是一个发布订阅的跟踪结果(一)