gokitconsul

package module
v0.0.0-...-235258f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2019 License: MIT Imports: 2 Imported by: 0

README

Welcome to gokitconsul 👋

go kit microservice demo with consul & zipkin

Dependency

  • consul as discover service
  • prometheus monitor service
  • grafana analytics service
  • zipkin as trace service
  • fluentd
  • kibana
  • elasticsearch
  • gateway
    • http → grpc (8000)
    • grpc proxy (8001)

Services

  • pkg/addsvc
  • pkg/foosvc

Install

# build docker image form bindary
make dockers_dev

# clear build (options)
make dockers

Usage

# start full feature
$ make u
docker-compose -f deployments/docker/docker-compose.yaml up -d
Creating network "net" with driver "bridge"
Recreating gokitconsul-elasticsearch ... done
Creating gokitconsul-fluentd         ... done
Recreating gokitconsul-grafana       ... done
Recreating gokitconsul-consul        ... done
Recreating gokitconsul-prometheus    ... done
Recreating gokitconsul-zipkin        ... done
Creating gokitconsul-kibana          ... done
Creating gokitconsul-addsvc          ... done
Creating gokitconsul-gateway         ... done
Creating gokitconsul-foosvc          ... done

or

# run without elasticsearch/fluentd/grafana/kibana/prometheus
$ docker-compose -f deployments/docker/docker-compose-dev.yaml up -d


$ docker ps
CONTAINER ID        IMAGE                                 COMMAND                  CREATED             STATUS              PORTS                                                                                                            NAMES
7da33c5f4ae8        cage1016/gokitconsul-gateway:latest   "/exe"                   4 seconds ago       Up 3 seconds        0.0.0.0:8000-8001->8000-8001/tcp                                                                                 gokitconsul-gateway
c5521d8d8879        cage1016/gokitconsul-foosvc:latest    "/exe"                   4 seconds ago       Up 3 seconds                                                                                                                         gokitconsul-foosvc
3804cea4fa33        cage1016/gokitconsul-addsvc:latest    "/exe"                   6 seconds ago       Up 4 seconds                                                                                                                         gokitconsul-addsvc
0225bdb521a2        grafana/grafana                       "/run.sh"                8 seconds ago       Up 6 seconds        0.0.0.0:3000->3000/tcp                                                                                           gokitconsul-grafana
17d3253f5e98        openzipkin/zipkin                     "/busybox/sh run.sh"     8 seconds ago       Up 7 seconds        9410/tcp, 0.0.0.0:9411->9411/tcp                                                                                 gokitconsul-zipkin
f157f98e2651        prom/prometheus                       "/bin/prometheus --c…"   8 seconds ago       Up 6 seconds        0.0.0.0:9090->9090/tcp                                                                                           gokitconsul-prometheus
240b055c29bb        consul:1.5.1                          "docker-entrypoint.s…"   8 seconds ago       Up 6 seconds        0.0.0.0:8400->8400/tcp, 8301-8302/udp, 0.0.0.0:8500->8500/tcp, 8300-8302/tcp, 8600/udp, 0.0.0.0:8600->8600/tcp   gokitconsul-consul
013a30314238        kibana:6.6.1                          "/usr/local/bin/kiba…"   8 seconds ago       Up 7 seconds        0.0.0.0:5601->5601/tcp                                                                                           gokitconsul-kibana
d67f9970fef9        docker_fluentd                        "tini -- /bin/entryp…"   9 seconds ago       Up 8 seconds        5140/tcp, 0.0.0.0:24224->24224/tcp, 0.0.0.0:24224->24224/udp                                                     gokitconsul-fluentd
9590182d4175        elasticsearch:6.6.1                   "/usr/local/bin/dock…"   10 seconds ago      Up 9 seconds        0.0.0.0:9200->9200/tcp, 9300/tcp                                                                                 gokitconsul-elasticsearch

Test

# sum
$ curl -X "POST" "https://localhost:8000/addsvc/sum" -H 'Content-Type: application/json; charset=utf-8' -d $'{ "a": 133, "b": 10333}'
{"rs":10466,"err":null}

# concat
$ curl -X "POST" "https://localhost:8000/addsvc/concat" -H 'Content-Type: application/json; charset=utf-8' -d $'{ "a": "133", "b": "10333"}'
{"rs":"13310333","err":null}

# foo
$ curl -X "POST" "https://localhost:8000/foosvc/foo" -H 'Content-Type: application/json; charset=utf-8' -d $'{ "s": "😆"}'
{"res":"foo 😆","err":null}

$ curl -X "POST" "https://localhost:8000/foosvc/foo" -H 'Content-Type: application/json; charset=utf-8' -d $'{ "s": "hello gokit 😆"}'
{"error":"result exceeds maximum size"}

# addcli through grpc proxy
$ go run cmd/addcli/main.go -grpc-addr localhost:8001 -method sum 1 22
1 + 22 = 23

$ go run cmd/addcli/main.go -grpc-addr localhost:8001 -method concat 1 22
"1" + "22" = "122"

# foocli throuth grpc proxy
$ go run cmd/foocli/main.go -grpc-addr localhost:8001 world
Foo world = foo world

Consul & zipkin

consult visit http://localhost:8500 Consul

zipkin visit http://localhost:9411 zipkin success

zipkin bad request

prometheus visit http://localhost:9000

grafana visit http://localhost:3000 (admin/password)

kibana visit http://localhost:5601

Stop

# docker-compose down
$ make d

Author

👤 KAI-CHU CHUNG

🤝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!

📝 License

Copyright © 2019 KAI-CHU CHUNG.
This project is MIT licensed.


This README was generated with ❤️ by readme-md-generator

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Version

func Version(service string) http.HandlerFunc

Version exposes an HTTP handler for retrieving service version.

Types

type VersionInfo

type VersionInfo struct {
	Service string `json:"service"`
	Version string `json:"version"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL