From 1de6c1fd16e36a785b535b0f0ba8e29c0b76dedd Mon Sep 17 00:00:00 2001 From: grampelberg Date: Tue, 5 Nov 2019 16:44:16 -0800 Subject: [PATCH 1/7] Move to modules --- Gopkg.lock | 129 ---------------------------------- Gopkg.toml | 9 --- common.mk | 7 +- emojivoto-emoji-svc/Makefile | 2 +- emojivoto-voting-svc/Makefile | 2 +- emojivoto-web/Makefile | 2 +- go.mod | 12 ++++ go.sum | 32 +++++++++ 8 files changed, 49 insertions(+), 146 deletions(-) delete mode 100644 Gopkg.lock delete mode 100644 Gopkg.toml create mode 100644 go.mod create mode 100644 go.sum diff --git a/Gopkg.lock b/Gopkg.lock deleted file mode 100644 index 65abfdf5..00000000 --- a/Gopkg.lock +++ /dev/null @@ -1,129 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - digest = "1:3dd078fda7500c341bc26cfbc6c6a34614f295a2457149fc1045cab767cbcf18" - name = "github.com/golang/protobuf" - packages = [ - "proto", - "protoc-gen-go", - "protoc-gen-go/descriptor", - "protoc-gen-go/generator", - "protoc-gen-go/generator/internal/remap", - "protoc-gen-go/grpc", - "protoc-gen-go/plugin", - "ptypes", - "ptypes/any", - "ptypes/duration", - "ptypes/timestamp", - ] - pruneopts = "" - revision = "aa810b61a9c79d51363740d207bb46cf8e620ed5" - version = "v1.2.0" - -[[projects]] - branch = "master" - digest = "1:7ec13687f85b25087fe05f6ea8dd116013a8263f8eb7e057da7664bc7599d2d4" - name = "golang.org/x/net" - packages = [ - "context", - "http/httpguts", - "http2", - "http2/hpack", - "idna", - "internal/timeseries", - "trace", - ] - pruneopts = "" - revision = "915654e7eabcea33ae277abbecf52f0d8b7a9fdc" - -[[projects]] - branch = "master" - digest = "1:057806b6e218f4ceac80d27ccd8dd80b2c06b0050289aa46e0edfd82cc4faa2c" - name = "golang.org/x/sys" - packages = ["unix"] - pruneopts = "" - revision = "11f53e03133963fb11ae0588e08b5e0b85be8be5" - -[[projects]] - digest = "1:5acd3512b047305d49e8763eef7ba423901e85d5dd2fd1e71778a0ea8de10bd4" - name = "golang.org/x/text" - packages = [ - "collate", - "collate/build", - "internal/colltab", - "internal/gen", - "internal/tag", - "internal/triegen", - "internal/ucd", - "language", - "secure/bidirule", - "transform", - "unicode/bidi", - "unicode/cldr", - "unicode/norm", - "unicode/rangetable", - ] - pruneopts = "" - revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" - version = "v0.3.0" - -[[projects]] - branch = "master" - digest = "1:1aa609a0033ef2927e083f2e5e07203ca35fe21c4a24b563de9fea16ddaae9ba" - name = "google.golang.org/genproto" - packages = ["googleapis/rpc/status"] - pruneopts = "" - revision = "db91494dd46c1fdcbbde05e5ff5eb56df8f7d79a" - -[[projects]] - digest = "1:39d4d828b87d58d114fdc211f0638f32dcae84019fe17d6b48f9b697f4b60213" - name = "google.golang.org/grpc" - packages = [ - ".", - "balancer", - "balancer/base", - "balancer/roundrobin", - "binarylog/grpc_binarylog_v1", - "codes", - "connectivity", - "credentials", - "credentials/internal", - "encoding", - "encoding/proto", - "grpclog", - "internal", - "internal/backoff", - "internal/binarylog", - "internal/channelz", - "internal/envconfig", - "internal/grpcrand", - "internal/grpcsync", - "internal/syscall", - "internal/transport", - "keepalive", - "metadata", - "naming", - "peer", - "resolver", - "resolver/dns", - "resolver/passthrough", - "stats", - "status", - "tap", - ] - pruneopts = "" - revision = "a02b0774206b209466313a0b525d2c738fe407eb" - version = "v1.18.0" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - input-imports = [ - "github.com/golang/protobuf/proto", - "github.com/golang/protobuf/protoc-gen-go", - "golang.org/x/net/context", - "google.golang.org/grpc", - ] - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml deleted file mode 100644 index 2f956b33..00000000 --- a/Gopkg.toml +++ /dev/null @@ -1,9 +0,0 @@ -required = ["github.com/golang/protobuf/protoc-gen-go"] - -[[constraint]] - name = "google.golang.org/grpc" - version = "1.18.0" - -[[constraint]] - name = "github.com/golang/protobuf" - version = "v1.2.0" diff --git a/common.mk b/common.mk index 30930513..c492beb6 100644 --- a/common.mk +++ b/common.mk @@ -1,4 +1,4 @@ -export IMAGE_TAG := v8 +export IMAGE_TAG := v9 .PHONY: package protoc test @@ -10,13 +10,10 @@ clean: mkdir -p $(target_dir) mkdir -p gen -dep: - dep ensure - protoc: protoc -I .. ../proto/*.proto --go_out=plugins=grpc:gen -package: protoc dep compile build-container +package: protoc compile build-container build-container: docker build .. -t "buoyantio/$(svc_name):$(IMAGE_TAG)" --build-arg svc_name=$(svc_name) diff --git a/emojivoto-emoji-svc/Makefile b/emojivoto-emoji-svc/Makefile index 8f6b4bf2..fb900718 100644 --- a/emojivoto-emoji-svc/Makefile +++ b/emojivoto-emoji-svc/Makefile @@ -1,6 +1,6 @@ svc_name := emojivoto-emoji-svc -all: clean protoc dep test package +all: clean protoc test package include ../common.mk diff --git a/emojivoto-voting-svc/Makefile b/emojivoto-voting-svc/Makefile index 1fa57b9a..1ab129d9 100644 --- a/emojivoto-voting-svc/Makefile +++ b/emojivoto-voting-svc/Makefile @@ -1,5 +1,5 @@ svc_name := emojivoto-voting-svc -all: clean protoc dep test package +all: clean protoc test package include ../common.mk diff --git a/emojivoto-web/Makefile b/emojivoto-web/Makefile index f69515ec..c7a35a2e 100644 --- a/emojivoto-web/Makefile +++ b/emojivoto-web/Makefile @@ -1,6 +1,6 @@ svc_name := emojivoto-web -all: clean protoc dep webpack package-web test package +all: clean protoc webpack package-web test package include ../common.mk diff --git a/go.mod b/go.mod new file mode 100644 index 00000000..ade79cd7 --- /dev/null +++ b/go.mod @@ -0,0 +1,12 @@ +module github.com/buoyantio/emojivoto + +go 1.13 + +require ( + github.com/golang/protobuf v1.3.2 + golang.org/x/net v0.0.0-20190110200230-915654e7eabc + golang.org/x/sys v0.0.0-20190116161447-11f53e031339 + golang.org/x/text v0.3.0 + google.golang.org/genproto v0.0.0-20190111180523-db91494dd46c + google.golang.org/grpc v1.18.0 +) diff --git a/go.sum b/go.sum new file mode 100644 index 00000000..07cfbab8 --- /dev/null +++ b/go.sum @@ -0,0 +1,32 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181106065722-10aee1819953/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190110200230-915654e7eabc h1:Yx9JGxI1SBhVLFjpAkWMaO1TF+xyqtHLjZpvQboJGiM= +golang.org/x/net v0.0.0-20190110200230-915654e7eabc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190116161447-11f53e031339 h1:g/Jesu8+QLnA0CPzF3E1pURg0Byr7i6jLoX5sqjcAh0= +golang.org/x/sys v0.0.0-20190116161447-11f53e031339/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190111180523-db91494dd46c h1:LZllHYjdJnynBfmwysp+s4yhMzfc+3BzhdqzAMvwjoc= +google.golang.org/genproto v0.0.0-20190111180523-db91494dd46c/go.mod h1:7Ep/1NZk928CDR8SjdVbjWNpdIf6nzjE3BTgJDr2Atg= +google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio= +google.golang.org/grpc v1.18.0 h1:IZl7mfBGfbhYx2p2rKRtYgDFw6SBz+kclmxYrCksPPA= +google.golang.org/grpc v1.18.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= +honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From 134cfe19b2d0312765ec2e6af374a6d895844a00 Mon Sep 17 00:00:00 2001 From: grampelberg Date: Wed, 6 Nov 2019 09:40:16 -0800 Subject: [PATCH 2/7] Remove broken integration tests --- Makefile | 5 - integration_test/Makefile | 6 -- integration_test/web_integration_test.go | 117 ----------------------- 3 files changed, 128 deletions(-) delete mode 100644 integration_test/Makefile delete mode 100644 integration_test/web_integration_test.go diff --git a/Makefile b/Makefile index a4590547..b04c8c24 100644 --- a/Makefile +++ b/Makefile @@ -33,11 +33,6 @@ deploy-to-docker-compose: $(MAKE) -C emojivoto-voting-svc build-container docker-compose -f ./docker-compose.yml up -d -integration-tests: deploy-to-docker-compose - WEB_URL=http://localhost:8080 $(MAKE) -C integration_test test - docker-compose stop - docker-compose rm -vf - push-%: docker push buoyantio/emojivoto-$*:$(IMAGE_TAG) diff --git a/integration_test/Makefile b/integration_test/Makefile deleted file mode 100644 index fb5c1a79..00000000 --- a/integration_test/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -.PHONY: test - -all: test - -test: - go test ./... diff --git a/integration_test/web_integration_test.go b/integration_test/web_integration_test.go deleted file mode 100644 index 44086871..00000000 --- a/integration_test/web_integration_test.go +++ /dev/null @@ -1,117 +0,0 @@ -package integration_test - -import ( - "os" - "testing" - "net/http" - "fmt" - "encoding/json" - "io/ioutil" - "net/url" -) - -var appBaseUrl = os.Getenv("WEB_URL") - -func TestVotes(t *testing.T) { - if appBaseUrl == "" { - t.Fatalf("Please set env var WEB_URL, currently [%s]", appBaseUrl) - } - - leaderboardList := getLeaderboard(t) - - if len(leaderboardList) != 0 { - t.Fatalf("Expected leaderboard to be empty, got [%v]", leaderboardList) - } - - allEligibleEmoji := getEmojilist(t) - if len(allEligibleEmoji) < 10 { - t.Fatal("Expected some emoji to be eligible, got 0") - } - - someArbitratyIndex := len(allEligibleEmoji) - 1 - emojiToBeFirst := allEligibleEmoji[someArbitratyIndex-1] - emojiToBeSecond := allEligibleEmoji[someArbitratyIndex-2] - emojiToBeThird := allEligibleEmoji[someArbitratyIndex-3] - - postVoteFor(t, emojiToBeFirst) - postVoteFor(t, emojiToBeSecond) - postVoteFor(t, emojiToBeThird) - - postVoteFor(t, emojiToBeFirst) - postVoteFor(t, emojiToBeSecond) - postVoteFor(t, emojiToBeThird) - - postVoteFor(t, emojiToBeFirst) - postVoteFor(t, emojiToBeSecond) - - postVoteFor(t, emojiToBeFirst) - - leaderboardList = getLeaderboard(t) - - if len(leaderboardList) != 3 { - t.Fatalf("Expected leaderboard to have 3 emoji, got [%v]", leaderboardList) - } - - firstItem := leaderboardList[0] - if firstItem["shortcode"] != emojiToBeFirst["shortcode"] { - t.Fatalf("Expected 2st emoji in list to be [%v], was [%v]", emojiToBeFirst, firstItem) - } - - secondItem := leaderboardList[1] - if secondItem["shortcode"] != emojiToBeSecond["shortcode"] { - t.Fatalf("Expected 2st emoji in list to be [%v], was [%v]", emojiToBeSecond, secondItem) - } - - thirdItem := leaderboardList[2] - if secondItem["shortcode"] != emojiToBeSecond["shortcode"] { - t.Fatalf("Expected 3rd emoji in list to be [%v], was [%v]", emojiToBeThird, thirdItem) - } -} - -func postVoteFor(t *testing.T, emojiToVoteFor map[string]string) { - - http.Post(fmt.Sprintf("%s/api/vote", appBaseUrl), "", nil) - resp, err := http.PostForm(fmt.Sprintf("%s/api/vote", appBaseUrl), - url.Values{"choice": {emojiToVoteFor["shortcode"]}}) - - if err != nil { - t.Fatal(err) - } - resp.Body.Close() - - if err != nil { - t.Fatal(err) - } - if status := resp.StatusCode; status != http.StatusOK { - t.Fatalf("handler returned wrong status code: got %v want %v", - status, http.StatusOK) - } -} - -func getLeaderboard(t *testing.T) []map[string]string { - return getJsonMapLisp(fmt.Sprintf("%s/api/leaderboard", appBaseUrl), t) -} - -func getEmojilist(t *testing.T) []map[string]string { - return getJsonMapLisp(fmt.Sprintf("%s/api/list", appBaseUrl), t) -} - -func getJsonMapLisp(url string, t *testing.T) []map[string]string { - resp, err := http.Get(url) - if err != nil { - t.Fatal(err) - } - if status := resp.StatusCode; status != http.StatusOK { - t.Fatalf("get to [%s] returned wrong status code: got %v want %v", - url, status, http.StatusOK) - } - var list []map[string]string - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - t.Fatal(err) - } - if err := json.Unmarshal(body, &list); err != nil { - t.Fatalf("Error parsing [%v]: %s",err, string(body)) - } - return list -} From 47a026c2e4085f4e536c2735f3ff3788b0870072 Mon Sep 17 00:00:00 2001 From: grampelberg Date: Wed, 6 Nov 2019 13:35:33 -0800 Subject: [PATCH 3/7] Add tracing to all components, off by default --- emojivoto-emoji-svc/cmd/server.go | 17 ++++- emojivoto-voting-svc/cmd/server.go | 17 ++++- emojivoto-web/cmd/server.go | 21 +++++- emojivoto-web/web/web.go | 21 ++++-- go.mod | 8 +-- go.sum | 110 +++++++++++++++++++++++++---- 6 files changed, 164 insertions(+), 30 deletions(-) diff --git a/emojivoto-emoji-svc/cmd/server.go b/emojivoto-emoji-svc/cmd/server.go index 2b0fd270..1fab8a2e 100644 --- a/emojivoto-emoji-svc/cmd/server.go +++ b/emojivoto-emoji-svc/cmd/server.go @@ -5,14 +5,19 @@ import ( "log" "net" "os" + "time" "github.com/buoyantio/emojivoto/emojivoto-emoji-svc/api" "github.com/buoyantio/emojivoto/emojivoto-emoji-svc/emoji" "google.golang.org/grpc" + "contrib.go.opencensus.io/exporter/ocagent" + "go.opencensus.io/plugin/ocgrpc" + "go.opencensus.io/trace" ) var ( grpcPort = os.Getenv("GRPC_PORT") + ocagentHost = os.Getenv("OC_AGENT_HOST") ) func main() { @@ -21,6 +26,16 @@ func main() { log.Fatalf("GRPC_PORT (currently [%s]) environment variable must me set to run the server.", grpcPort) } + oce, err := ocagent.NewExporter( + ocagent.WithInsecure(), + ocagent.WithReconnectionPeriod(5 * time.Second), + ocagent.WithAddress(ocagentHost), + ocagent.WithServiceName("voting")) + if err != nil { + log.Fatalf("Failed to create ocagent-exporter: %v", err) + } + trace.RegisterExporter(oce) + allEmoji := emoji.NewAllEmoji() lis, err := net.Listen("tcp", fmt.Sprintf(":%s", grpcPort)) @@ -28,7 +43,7 @@ func main() { panic(err) } - grpcServer := grpc.NewServer() + grpcServer := grpc.NewServer(grpc.StatsHandler(&ocgrpc.ServerHandler{})) api.NewGrpServer(grpcServer, allEmoji) log.Printf("Starting grpc server on GRPC_PORT=[%s]", grpcPort) grpcServer.Serve(lis) diff --git a/emojivoto-voting-svc/cmd/server.go b/emojivoto-voting-svc/cmd/server.go index 6794adb7..9b16387f 100644 --- a/emojivoto-voting-svc/cmd/server.go +++ b/emojivoto-voting-svc/cmd/server.go @@ -5,14 +5,19 @@ import ( "log" "net" "os" + "time" "github.com/buoyantio/emojivoto/emojivoto-voting-svc/api" "github.com/buoyantio/emojivoto/emojivoto-voting-svc/voting" "google.golang.org/grpc" + "contrib.go.opencensus.io/exporter/ocagent" + "go.opencensus.io/plugin/ocgrpc" + "go.opencensus.io/trace" ) var ( grpcPort = os.Getenv("GRPC_PORT") + ocagentHost = os.Getenv("OC_AGENT_HOST") ) func main() { @@ -21,6 +26,16 @@ func main() { log.Fatalf("GRPC_PORT (currently [%s]) environment variable must me set to run the server.", grpcPort) } + oce, err := ocagent.NewExporter( + ocagent.WithInsecure(), + ocagent.WithReconnectionPeriod(5 * time.Second), + ocagent.WithAddress(ocagentHost), + ocagent.WithServiceName("voting")) + if err != nil { + log.Fatalf("Failed to create ocagent-exporter: %v", err) + } + trace.RegisterExporter(oce) + poll := voting.NewPoll() lis, err := net.Listen("tcp", fmt.Sprintf(":%s", grpcPort)) @@ -28,7 +43,7 @@ func main() { panic(err) } - grpcServer := grpc.NewServer() + grpcServer := grpc.NewServer(grpc.StatsHandler(&ocgrpc.ServerHandler{})) api.NewGrpServer(grpcServer, poll) log.Printf("Starting grpc server on GRPC_PORT=[%s]", grpcPort) grpcServer.Serve(lis) diff --git a/emojivoto-web/cmd/server.go b/emojivoto-web/cmd/server.go index 07eafffb..a2b6d8c3 100644 --- a/emojivoto-web/cmd/server.go +++ b/emojivoto-web/cmd/server.go @@ -3,10 +3,14 @@ package main import ( "log" "os" + "time" pb "github.com/buoyantio/emojivoto/emojivoto-web/gen/proto" "github.com/buoyantio/emojivoto/emojivoto-web/web" "google.golang.org/grpc" + "contrib.go.opencensus.io/exporter/ocagent" + "go.opencensus.io/plugin/ocgrpc" + "go.opencensus.io/trace" ) var ( @@ -15,6 +19,7 @@ var ( votingsvcHost = os.Getenv("VOTINGSVC_HOST") indexBundle = os.Getenv("INDEX_BUNDLE") webpackDevServerHost = os.Getenv("WEBPACK_DEV_SERVER") + ocagentHost = os.Getenv("OC_AGENT_HOST") ) func main() { @@ -23,6 +28,16 @@ func main() { log.Fatalf("WEB_PORT (currently [%s]) EMOJISVC_HOST (currently [%s]) and VOTINGSVC_HOST (currently [%s]) INDEX_BUNDLE (currently [%s]) environment variables must me set.", webPort, emojisvcHost, votingsvcHost, indexBundle) } + oce, err := ocagent.NewExporter( + ocagent.WithInsecure(), + ocagent.WithReconnectionPeriod(5*time.Second), + ocagent.WithAddress(ocagentHost), + ocagent.WithServiceName("web")) + if err != nil { + log.Fatalf("Failed to create ocagent-exporter: %v", err) + } + trace.RegisterExporter(oce) + votingSvcConn := openGrpcClientConnection(votingsvcHost) votingClient := pb.NewVotingServiceClient(votingSvcConn) defer votingSvcConn.Close() @@ -36,7 +51,11 @@ func main() { func openGrpcClientConnection(host string) *grpc.ClientConn { log.Printf("Connecting to [%s]", host) - conn, err := grpc.Dial(host, grpc.WithInsecure()) + conn, err := grpc.Dial( + host, + grpc.WithInsecure(), + grpc.WithStatsHandler(new(ocgrpc.ClientHandler))) + if err != nil { panic(err) } diff --git a/emojivoto-web/web/web.go b/emojivoto-web/web/web.go index 4cc41d5f..a5df87a2 100644 --- a/emojivoto-web/web/web.go +++ b/emojivoto-web/web/web.go @@ -11,6 +11,7 @@ import ( "strconv" pb "github.com/buoyantio/emojivoto/emojivoto-web/gen/proto" + "go.opencensus.io/plugin/ochttp" ) type WebApp struct { @@ -374,6 +375,12 @@ func writeError(err error, w http.ResponseWriter, r *http.Request, status int) { json.NewEncoder(w).Encode(errorMessage) } +func handle(path string, h func (w http.ResponseWriter, r *http.Request)) { + http.Handle(path, &ochttp.Handler { + Handler: http.HandlerFunc(h), + }) +} + func StartServer(webPort, webpackDevServer, indexBundle string, emojiServiceClient pb.EmojiServiceClient, votingClient pb.VotingServiceClient) { webApp := &WebApp{ emojiServiceClient: emojiServiceClient, @@ -383,13 +390,13 @@ func StartServer(webPort, webpackDevServer, indexBundle string, emojiServiceClie } log.Printf("Starting web server on WEB_PORT=[%s]", webPort) - http.HandleFunc("/", webApp.indexHandler) - http.HandleFunc("/leaderboard", webApp.indexHandler) - http.HandleFunc("/js", webApp.jsHandler) - http.HandleFunc("/img/favicon.ico", webApp.faviconHandler) - http.HandleFunc("/api/list", webApp.listEmojiHandler) - http.HandleFunc("/api/vote", webApp.voteEmojiHandler) - http.HandleFunc("/api/leaderboard", webApp.leaderboardHandler) + handle("/", webApp.indexHandler) + handle("/leaderboard", webApp.indexHandler) + handle("/js", webApp.jsHandler) + handle("/img/favicon.ico", webApp.faviconHandler) + handle("/api/list", webApp.listEmojiHandler) + handle("/api/vote", webApp.voteEmojiHandler) + handle("/api/leaderboard", webApp.leaderboardHandler) // TODO: make static assets dir configurable http.Handle("/dist/", http.StripPrefix("/dist/", http.FileServer(http.Dir("dist")))) diff --git a/go.mod b/go.mod index ade79cd7..cb1135a7 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,8 @@ module github.com/buoyantio/emojivoto go 1.13 require ( + contrib.go.opencensus.io/exporter/ocagent v0.6.0 github.com/golang/protobuf v1.3.2 - golang.org/x/net v0.0.0-20190110200230-915654e7eabc - golang.org/x/sys v0.0.0-20190116161447-11f53e031339 - golang.org/x/text v0.3.0 - google.golang.org/genproto v0.0.0-20190111180523-db91494dd46c - google.golang.org/grpc v1.18.0 + go.opencensus.io v0.22.1 + google.golang.org/grpc v1.22.0 ) diff --git a/go.sum b/go.sum index 07cfbab8..c3d1f218 100644 --- a/go.sum +++ b/go.sum @@ -1,32 +1,112 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +contrib.go.opencensus.io/exporter/ocagent v0.6.0 h1:Z1n6UAyr0QwM284yUuh5Zd8JlvxUGAhFZcgMJkMPrGM= +contrib.go.opencensus.io/exporter/ocagent v0.6.0/go.mod h1:zmKjrJcdo0aYcVS7bmEeSEBLPA9YJp5bjrofdU3pIXs= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/census-instrumentation/opencensus-proto v0.2.1 h1:glEXhBS5PSLLv4IXzLA5yPRVX4bilULVyxxbrfOtDAk= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E= +github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 h1:ZgQEtGgCBiWRM39fZuwSd1LwSqqSW0hOdXCYYDX0R3I= +github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/grpc-ecosystem/grpc-gateway v1.9.4 h1:5xLhQjsk4zqPf9EHCrja2qFZMx+yBqkO3XgJ14bNnU0= +github.com/grpc-ecosystem/grpc-gateway v1.9.4/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= +go.opencensus.io v0.22.1 h1:8dP3SGL7MPB94crU3bEPplMPe83FI4EouesJUeFHv50= +go.opencensus.io v0.22.1/go.mod h1:Ap50jQcDJrx6rB6VgeeFPtuPIf3wMRvRfrfYDO6+BmA= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181106065722-10aee1819953/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190110200230-915654e7eabc h1:Yx9JGxI1SBhVLFjpAkWMaO1TF+xyqtHLjZpvQboJGiM= -golang.org/x/net v0.0.0-20190110200230-915654e7eabc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7 h1:rTIdg5QFRR7XCaK4LCjBiPbx8j4DQRpdYMnGn/bJUEU= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190116161447-11f53e031339 h1:g/Jesu8+QLnA0CPzF3E1pURg0Byr7i6jLoX5sqjcAh0= -golang.org/x/sys v0.0.0-20190116161447-11f53e031339/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7 h1:LepdCS8Gf/MVejFIt8lsiexZATdoGVyp5bcyS+rYoUI= +golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0 h1:9sdfJOzWlkqPltHAuzT2Cp+yrBeY1KRVYgms8soxMwM= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190111180523-db91494dd46c h1:LZllHYjdJnynBfmwysp+s4yhMzfc+3BzhdqzAMvwjoc= -google.golang.org/genproto v0.0.0-20190111180523-db91494dd46c/go.mod h1:7Ep/1NZk928CDR8SjdVbjWNpdIf6nzjE3BTgJDr2Atg= -google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio= -google.golang.org/grpc v1.18.0 h1:IZl7mfBGfbhYx2p2rKRtYgDFw6SBz+kclmxYrCksPPA= -google.golang.org/grpc v1.18.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= -honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190716160619-c506a9f90610 h1:Ygq9/SRJX9+dU0WCIICM8RkWvDw03lvB77hrhJnpxfU= +google.golang.org/genproto v0.0.0-20190716160619-c506a9f90610/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.22.0 h1:J0UbZOIrCAl+fpTOf8YLs4dJo8L/owV4LYVtAXQoPkw= +google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= +gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From 0054a564d8abff9afc7991ffb626e562ba1ab90a Mon Sep 17 00:00:00 2001 From: grampelberg Date: Thu, 7 Nov 2019 10:57:00 -0800 Subject: [PATCH 4/7] Move to kustomize for switching between kind --- README.md | 75 +++++---- emojivoto-daemonset.yml | 190 ---------------------- emojivoto-job.yml | 202 ------------------------ emojivoto-statefulset.yml | 194 ----------------------- emojivoto.yml | 202 ------------------------ kustomize/daemonset/kustomization.yml | 27 ++++ kustomize/daemonset/patch.yml | 6 + kustomize/deployment/emoji.yml | 47 ++++++ kustomize/deployment/kustomization.yml | 6 + kustomize/deployment/ns.yml | 4 + kustomize/deployment/vote-bot.yml | 26 +++ kustomize/deployment/voting.yml | 47 ++++++ kustomize/deployment/web.yml | 54 +++++++ kustomize/job/kustomization.yml | 27 ++++ kustomize/job/patch.yml | 17 ++ kustomize/statefulset/kustomization.yml | 29 ++++ kustomize/statefulset/patch.yml | 3 + kustomize/statefulset/service-name.yml | 27 ++++ 18 files changed, 364 insertions(+), 819 deletions(-) delete mode 100644 emojivoto-daemonset.yml delete mode 100644 emojivoto-job.yml delete mode 100644 emojivoto-statefulset.yml delete mode 100644 emojivoto.yml create mode 100644 kustomize/daemonset/kustomization.yml create mode 100644 kustomize/daemonset/patch.yml create mode 100644 kustomize/deployment/emoji.yml create mode 100644 kustomize/deployment/kustomization.yml create mode 100644 kustomize/deployment/ns.yml create mode 100644 kustomize/deployment/vote-bot.yml create mode 100644 kustomize/deployment/voting.yml create mode 100644 kustomize/deployment/web.yml create mode 100644 kustomize/job/kustomization.yml create mode 100644 kustomize/job/patch.yml create mode 100644 kustomize/statefulset/kustomization.yml create mode 100644 kustomize/statefulset/patch.yml create mode 100644 kustomize/statefulset/service-name.yml diff --git a/README.md b/README.md index 8d3bb6a4..1e0b2c8b 100644 --- a/README.md +++ b/README.md @@ -19,31 +19,33 @@ Deploy the application to Minikube using the Linkerd2 service mesh. 1. Install the `linkerd` CLI -``` +```bash curl https://run.linkerd.io/install | sh ``` -2. Install Linkerd2 +1. Install Linkerd2 -``` +```bash linkerd install | kubectl apply -f - ``` -3. View the dashboard! +1. View the dashboard! -``` +```bash linkerd dashboard ``` -4. Inject, Deploy, and Enjoy +1. Inject, Deploy, and Enjoy -``` -linkerd inject emojivoto.yml | kubectl apply -f - +```bash +kubectl kustomize kustomize/deployment | \ + linkerd inject - | \ + kubectl apply -f - ``` -5. Use the app! +1. Use the app! -``` +```bash minikube -n emojivoto service web-svc ``` @@ -53,7 +55,7 @@ It's also possible to run the app with docker-compose (without Linkerd2). Build and run: -``` +```bash make deploy-to-docker-compose ``` @@ -63,6 +65,7 @@ The web app will be running on port 8080 of your docker host. The `VoteBot` service can generate some traffic for you. It votes on emoji "randomly" as follows: + - It votes for :doughnut: 15% of the time. - When not voting for :doughnut:, it picks an emoji at random @@ -70,7 +73,8 @@ If you're running the app using the instructions above, the VoteBot will have been deployed and will start sending traffic to the vote endpoint. If you'd like to run the bot manually: -``` + +```bash export WEB_HOST=localhost:8080 # replace with your web location go run emojivoto-web/cmd/vote-bot/main.go ``` @@ -78,20 +82,22 @@ go run emojivoto-web/cmd/vote-bot/main.go ## Releasing a new version To update the docker images: + 1. Update the tag name in `common.mk` -2. Update the base image tags in `Makefile` and `Dockerfile` -3. Build base docker image `make build-base-docker-image` -4. Build docker images `make build` -5. Push the docker images to hub.docker.com -```bash -docker login -docker push buoyantio/emojivoto-svc-base:v8 -docker push buoyantio/emojivoto-emoji-svc:v8 -docker push buoyantio/emojivoto-voting-svc:v8 -docker push buoyantio/emojivoto-web:v8 -``` -6. Update `emojivoto.yml`, `docker-compose.yml` +1. Update the base image tags in `Makefile` and `Dockerfile` +1. Build base docker image `make build-base-docker-image` +1. Build docker images `make build` +1. Push the docker images to hub.docker.com + ```bash + docker login + docker push buoyantio/emojivoto-svc-base:v8 + docker push buoyantio/emojivoto-emoji-svc:v8 + docker push buoyantio/emojivoto-voting-svc:v8 + docker push buoyantio/emojivoto-web:v8 + ``` + +1. Update `emojivoto.yml`, `docker-compose.yml` ## Local Development @@ -101,22 +107,26 @@ This app is written with React and bundled with webpack. Use the following to run the emojivoto go services and develop on the frontend. Set up proto files, build apps -``` + +```bash make build ``` Start the voting service -``` + +```bash GRPC_PORT=8081 go run emojivoto-voting-svc/cmd/server.go ``` [In a separate terminal window] Start the emoji service -``` + +```bash GRPC_PORT=8082 go run emojivoto-emoji-svc/cmd/server.go ``` [In a separate terminal window] Bundle the frontend assets -``` + +```bash cd emojivoto-web/webapp yarn install yarn webpack # one time asset-bundling OR @@ -124,7 +134,8 @@ yarn webpack-dev-server --port 8083 # bundle/serve reloading assets ``` [In a separate terminal window] Start the web service -``` + +```bash export WEB_PORT=8080 export VOTINGSVC_HOST=localhost:8081 export EMOJISVC_HOST=localhost:8082 @@ -140,12 +151,14 @@ go run emojivoto-web/cmd/server.go ``` [Optional] Start the vote bot for automatic traffic generation. -``` + +```bash export WEB_HOST=localhost:8080 go run emojivoto-web/cmd/vote-bot/main.go ``` View emojivoto -``` + +```bash open http://localhost:8080 ``` diff --git a/emojivoto-daemonset.yml b/emojivoto-daemonset.yml deleted file mode 100644 index 61afb956..00000000 --- a/emojivoto-daemonset.yml +++ /dev/null @@ -1,190 +0,0 @@ ---- -apiVersion: v1 -kind: Namespace -metadata: - name: emojivoto ---- -kind: ServiceAccount -apiVersion: v1 -metadata: - name: emoji - namespace: emojivoto ---- -kind: ServiceAccount -apiVersion: v1 -metadata: - name: voting - namespace: emojivoto ---- -kind: ServiceAccount -apiVersion: v1 -metadata: - name: web - namespace: emojivoto ---- -apiVersion: apps/v1 -kind: DaemonSet -metadata: - creationTimestamp: null - name: emoji - namespace: emojivoto -spec: - selector: - matchLabels: - app: emoji-svc - template: - metadata: - creationTimestamp: null - labels: - app: emoji-svc - spec: - serviceAccountName: emoji - containers: - - env: - - name: GRPC_PORT - value: "8080" - image: buoyantio/emojivoto-emoji-svc:v8 - name: emoji-svc - ports: - - containerPort: 8080 - name: grpc - resources: - requests: - cpu: 100m ---- -apiVersion: v1 -kind: Service -metadata: - name: emoji-svc - namespace: emojivoto -spec: - selector: - app: emoji-svc - clusterIP: None - ports: - - name: grpc - port: 8080 - targetPort: 8080 ---- -apiVersion: apps/v1 -kind: DaemonSet -metadata: - creationTimestamp: null - name: voting - namespace: emojivoto -spec: - selector: - matchLabels: - app: voting-svc - template: - metadata: - creationTimestamp: null - labels: - app: voting-svc - spec: - serviceAccountName: voting - containers: - - env: - - name: GRPC_PORT - value: "8080" - image: buoyantio/emojivoto-voting-svc:v8 - name: voting-svc - ports: - - containerPort: 8080 - name: grpc - resources: - requests: - cpu: 100m ---- -apiVersion: v1 -kind: Service -metadata: - name: voting-svc - namespace: emojivoto -spec: - selector: - app: voting-svc - clusterIP: None - ports: - - name: grpc - port: 8080 - targetPort: 8080 ---- -apiVersion: apps/v1 -kind: DaemonSet -metadata: - creationTimestamp: null - name: web - namespace: emojivoto -spec: - selector: - matchLabels: - app: web-svc - template: - metadata: - creationTimestamp: null - labels: - app: web-svc - spec: - serviceAccountName: web - containers: - - env: - - name: WEB_PORT - value: "80" - - name: EMOJISVC_HOST - value: emoji-svc.emojivoto:8080 - - name: VOTINGSVC_HOST - value: voting-svc.emojivoto:8080 - - name: INDEX_BUNDLE - value: dist/index_bundle.js - image: buoyantio/emojivoto-web:v8 - name: web-svc - ports: - - containerPort: 80 - name: http - resources: - requests: - cpu: 100m ---- -apiVersion: v1 -kind: Service -metadata: - name: web-svc - namespace: emojivoto -spec: - type: LoadBalancer - selector: - app: web-svc - ports: - - name: http - port: 80 - targetPort: 80 ---- -apiVersion: apps/v1 -kind: DaemonSet -metadata: - creationTimestamp: null - name: vote-bot - namespace: emojivoto -spec: - selector: - matchLabels: - app: vote-bot - template: - metadata: - creationTimestamp: null - labels: - app: vote-bot - spec: - containers: - - command: - - emojivoto-vote-bot - env: - - name: WEB_HOST - value: web-svc.emojivoto:80 - image: buoyantio/emojivoto-web:v8 - name: vote-bot - resources: - requests: - cpu: 10m ---- diff --git a/emojivoto-job.yml b/emojivoto-job.yml deleted file mode 100644 index 5fcf6f83..00000000 --- a/emojivoto-job.yml +++ /dev/null @@ -1,202 +0,0 @@ ---- -apiVersion: v1 -kind: Namespace -metadata: - name: emojivoto ---- -kind: ServiceAccount -apiVersion: v1 -metadata: - name: emoji - namespace: emojivoto ---- -kind: ServiceAccount -apiVersion: v1 -metadata: - name: voting - namespace: emojivoto ---- -kind: ServiceAccount -apiVersion: v1 -metadata: - name: web - namespace: emojivoto ---- -apiVersion: batch/v1 -kind: Job -metadata: - creationTimestamp: null - name: emoji - namespace: emojivoto -spec: - manualSelector: true - selector: - matchLabels: - app: emoji-svc - template: - metadata: - creationTimestamp: null - labels: - app: emoji-svc - spec: - restartPolicy: OnFailure - serviceAccountName: emoji - containers: - - env: - - name: GRPC_PORT - value: "8080" - image: buoyantio/emojivoto-emoji-svc:v8 - name: emoji-svc - ports: - - containerPort: 8080 - name: grpc - resources: - requests: - cpu: 100m -status: {} ---- -apiVersion: v1 -kind: Service -metadata: - name: emoji-svc - namespace: emojivoto -spec: - selector: - app: emoji-svc - clusterIP: None - ports: - - name: grpc - port: 8080 - targetPort: 8080 ---- -apiVersion: batch/v1 -kind: Job -metadata: - creationTimestamp: null - name: voting - namespace: emojivoto -spec: - manualSelector: true - selector: - matchLabels: - app: voting-svc - template: - metadata: - creationTimestamp: null - labels: - app: voting-svc - spec: - restartPolicy: OnFailure - serviceAccountName: voting - containers: - - env: - - name: GRPC_PORT - value: "8080" - image: buoyantio/emojivoto-voting-svc:v8 - name: voting-svc - ports: - - containerPort: 8080 - name: grpc - resources: - requests: - cpu: 100m -status: {} ---- -apiVersion: v1 -kind: Service -metadata: - name: voting-svc - namespace: emojivoto -spec: - selector: - app: voting-svc - clusterIP: None - ports: - - name: grpc - port: 8080 - targetPort: 8080 ---- -apiVersion: batch/v1 -kind: Job -metadata: - creationTimestamp: null - name: web - namespace: emojivoto -spec: - manualSelector: true - selector: - matchLabels: - app: web-svc - template: - metadata: - creationTimestamp: null - labels: - app: web-svc - spec: - restartPolicy: OnFailure - serviceAccountName: web - containers: - - env: - - name: WEB_PORT - value: "80" - - name: EMOJISVC_HOST - value: emoji-svc.emojivoto:8080 - - name: VOTINGSVC_HOST - value: voting-svc.emojivoto:8080 - - name: INDEX_BUNDLE - value: dist/index_bundle.js - image: buoyantio/emojivoto-web:v8 - name: web-svc - ports: - - containerPort: 80 - name: http - resources: - requests: - cpu: 100m -status: {} ---- -apiVersion: v1 -kind: Service -metadata: - name: web-svc - namespace: emojivoto -spec: - type: LoadBalancer - selector: - app: web-svc - ports: - - name: http - port: 80 - targetPort: 80 ---- -apiVersion: batch/v1 -kind: Job -metadata: - creationTimestamp: null - name: vote-bot - namespace: emojivoto -spec: - manualSelector: true - selector: - matchLabels: - app: vote-bot - template: - metadata: - creationTimestamp: null - labels: - app: vote-bot - spec: - restartPolicy: OnFailure - containers: - - command: - - emojivoto-vote-bot - env: - - name: WEB_HOST - value: web-svc.emojivoto:80 - image: buoyantio/emojivoto-web:v8 - name: vote-bot - resources: - requests: - cpu: 10m -status: {} ---- diff --git a/emojivoto-statefulset.yml b/emojivoto-statefulset.yml deleted file mode 100644 index db600aef..00000000 --- a/emojivoto-statefulset.yml +++ /dev/null @@ -1,194 +0,0 @@ ---- -apiVersion: v1 -kind: Namespace -metadata: - name: emojivoto ---- -kind: ServiceAccount -apiVersion: v1 -metadata: - name: emoji - namespace: emojivoto ---- -kind: ServiceAccount -apiVersion: v1 -metadata: - name: voting - namespace: emojivoto ---- -kind: ServiceAccount -apiVersion: v1 -metadata: - name: web - namespace: emojivoto ---- -apiVersion: apps/v1 -kind: StatefulSet -metadata: - creationTimestamp: null - name: emoji - namespace: emojivoto -spec: - serviceName: emoji-svc - selector: - matchLabels: - app: emoji-svc - template: - metadata: - creationTimestamp: null - labels: - app: emoji-svc - spec: - serviceAccountName: emoji - containers: - - env: - - name: GRPC_PORT - value: "8080" - image: buoyantio/emojivoto-emoji-svc:v8 - name: emoji-svc - ports: - - containerPort: 8080 - name: grpc - resources: - requests: - cpu: 100m ---- -apiVersion: v1 -kind: Service -metadata: - name: emoji-svc - namespace: emojivoto -spec: - selector: - app: emoji-svc - clusterIP: None - ports: - - name: grpc - port: 8080 - targetPort: 8080 ---- -apiVersion: apps/v1 -kind: StatefulSet -metadata: - creationTimestamp: null - name: voting - namespace: emojivoto -spec: - serviceName: voting-svc - selector: - matchLabels: - app: voting-svc - template: - metadata: - creationTimestamp: null - labels: - app: voting-svc - spec: - serviceAccountName: voting - containers: - - env: - - name: GRPC_PORT - value: "8080" - image: buoyantio/emojivoto-voting-svc:v8 - name: voting-svc - ports: - - containerPort: 8080 - name: grpc - resources: - requests: - cpu: 100m ---- -apiVersion: v1 -kind: Service -metadata: - name: voting-svc - namespace: emojivoto -spec: - selector: - app: voting-svc - clusterIP: None - ports: - - name: grpc - port: 8080 - targetPort: 8080 ---- -apiVersion: apps/v1 -kind: StatefulSet -metadata: - creationTimestamp: null - name: web - namespace: emojivoto -spec: - serviceName: web-svc - selector: - matchLabels: - app: web-svc - template: - metadata: - creationTimestamp: null - labels: - app: web-svc - spec: - serviceAccountName: web - containers: - - env: - - name: WEB_PORT - value: "80" - - name: EMOJISVC_HOST - value: emoji-svc.emojivoto:8080 - - name: VOTINGSVC_HOST - value: voting-svc.emojivoto:8080 - - name: INDEX_BUNDLE - value: dist/index_bundle.js - image: buoyantio/emojivoto-web:v8 - name: web-svc - ports: - - containerPort: 80 - name: http - resources: - requests: - cpu: 100m ---- -apiVersion: v1 -kind: Service -metadata: - name: web-svc - namespace: emojivoto -spec: - clusterIP: None - selector: - app: web-svc - ports: - - name: http - port: 80 - targetPort: 80 ---- -apiVersion: apps/v1 -kind: StatefulSet -metadata: - creationTimestamp: null - name: vote-bot - namespace: emojivoto -spec: - serviceName: vote-bot - selector: - matchLabels: - app: vote-bot - template: - metadata: - creationTimestamp: null - labels: - app: vote-bot - spec: - containers: - - command: - - emojivoto-vote-bot - env: - - name: WEB_HOST - value: web-svc.emojivoto:80 - image: buoyantio/emojivoto-web:v8 - name: vote-bot - resources: - requests: - cpu: 10m ---- diff --git a/emojivoto.yml b/emojivoto.yml deleted file mode 100644 index cc8c2869..00000000 --- a/emojivoto.yml +++ /dev/null @@ -1,202 +0,0 @@ ---- -apiVersion: v1 -kind: Namespace -metadata: - name: emojivoto ---- -kind: ServiceAccount -apiVersion: v1 -metadata: - name: emoji - namespace: emojivoto ---- -kind: ServiceAccount -apiVersion: v1 -metadata: - name: voting - namespace: emojivoto ---- -kind: ServiceAccount -apiVersion: v1 -metadata: - name: web - namespace: emojivoto ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - creationTimestamp: null - name: emoji - namespace: emojivoto -spec: - replicas: 1 - selector: - matchLabels: - app: emoji-svc - strategy: {} - template: - metadata: - creationTimestamp: null - labels: - app: emoji-svc - spec: - serviceAccountName: emoji - containers: - - env: - - name: GRPC_PORT - value: "8080" - image: buoyantio/emojivoto-emoji-svc:v8 - name: emoji-svc - ports: - - containerPort: 8080 - name: grpc - resources: - requests: - cpu: 100m -status: {} ---- -apiVersion: v1 -kind: Service -metadata: - name: emoji-svc - namespace: emojivoto -spec: - selector: - app: emoji-svc - clusterIP: None - ports: - - name: grpc - port: 8080 - targetPort: 8080 ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - creationTimestamp: null - name: voting - namespace: emojivoto -spec: - replicas: 1 - selector: - matchLabels: - app: voting-svc - strategy: {} - template: - metadata: - creationTimestamp: null - labels: - app: voting-svc - spec: - serviceAccountName: voting - containers: - - env: - - name: GRPC_PORT - value: "8080" - image: buoyantio/emojivoto-voting-svc:v8 - name: voting-svc - ports: - - containerPort: 8080 - name: grpc - resources: - requests: - cpu: 100m -status: {} ---- -apiVersion: v1 -kind: Service -metadata: - name: voting-svc - namespace: emojivoto -spec: - selector: - app: voting-svc - clusterIP: None - ports: - - name: grpc - port: 8080 - targetPort: 8080 ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - creationTimestamp: null - name: web - namespace: emojivoto -spec: - replicas: 1 - selector: - matchLabels: - app: web-svc - strategy: {} - template: - metadata: - creationTimestamp: null - labels: - app: web-svc - spec: - serviceAccountName: web - containers: - - env: - - name: WEB_PORT - value: "8080" - - name: EMOJISVC_HOST - value: emoji-svc.emojivoto:8080 - - name: VOTINGSVC_HOST - value: voting-svc.emojivoto:8080 - - name: INDEX_BUNDLE - value: dist/index_bundle.js - image: buoyantio/emojivoto-web:v8 - name: web-svc - ports: - - containerPort: 8080 - name: http - resources: - requests: - cpu: 100m -status: {} ---- -apiVersion: v1 -kind: Service -metadata: - name: web-svc - namespace: emojivoto -spec: - type: LoadBalancer - selector: - app: web-svc - ports: - - name: http - port: 80 - targetPort: 8080 ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - creationTimestamp: null - name: vote-bot - namespace: emojivoto -spec: - replicas: 1 - selector: - matchLabels: - app: vote-bot - strategy: {} - template: - metadata: - creationTimestamp: null - labels: - app: vote-bot - spec: - containers: - - command: - - emojivoto-vote-bot - env: - - name: WEB_HOST - value: web-svc.emojivoto:80 - image: buoyantio/emojivoto-web:v8 - name: vote-bot - resources: - requests: - cpu: 10m -status: {} ---- diff --git a/kustomize/daemonset/kustomization.yml b/kustomize/daemonset/kustomization.yml new file mode 100644 index 00000000..0523618c --- /dev/null +++ b/kustomize/daemonset/kustomization.yml @@ -0,0 +1,27 @@ +bases: +- ../deployment +patchesJson6902: +- target: + group: apps + version: v1 + kind: Deployment + name: web + path: patch.yml +- target: + group: apps + version: v1 + kind: Deployment + name: emoji + path: patch.yml +- target: + group: apps + version: v1 + kind: Deployment + name: voting + path: patch.yml +- target: + group: apps + version: v1 + kind: Deployment + name: vote-bot + path: patch.yml diff --git a/kustomize/daemonset/patch.yml b/kustomize/daemonset/patch.yml new file mode 100644 index 00000000..f87adae8 --- /dev/null +++ b/kustomize/daemonset/patch.yml @@ -0,0 +1,6 @@ +- op: replace + path: /kind + value: DaemonSet + +- op: remove + path: /spec/replicas diff --git a/kustomize/deployment/emoji.yml b/kustomize/deployment/emoji.yml new file mode 100644 index 00000000..5b139518 --- /dev/null +++ b/kustomize/deployment/emoji.yml @@ -0,0 +1,47 @@ +kind: ServiceAccount +apiVersion: v1 +metadata: + name: emoji + namespace: emojivoto +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: emoji + namespace: emojivoto +spec: + replicas: 1 + selector: + matchLabels: + app: emoji-svc + template: + metadata: + labels: + app: emoji-svc + spec: + serviceAccountName: emoji + containers: + - env: + - name: GRPC_PORT + value: "8080" + image: buoyantio/emojivoto-emoji-svc:v8 + name: emoji-svc + ports: + - containerPort: 8080 + name: grpc + resources: + requests: + cpu: 100m +--- +apiVersion: v1 +kind: Service +metadata: + name: emoji-svc + namespace: emojivoto +spec: + selector: + app: emoji-svc + ports: + - name: grpc + port: 8080 + targetPort: 8080 diff --git a/kustomize/deployment/kustomization.yml b/kustomize/deployment/kustomization.yml new file mode 100644 index 00000000..b09dc55e --- /dev/null +++ b/kustomize/deployment/kustomization.yml @@ -0,0 +1,6 @@ +resources: +- ns.yml +- web.yml +- emoji.yml +- voting.yml +- vote-bot.yml diff --git a/kustomize/deployment/ns.yml b/kustomize/deployment/ns.yml new file mode 100644 index 00000000..13491ee2 --- /dev/null +++ b/kustomize/deployment/ns.yml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: emojivoto diff --git a/kustomize/deployment/vote-bot.yml b/kustomize/deployment/vote-bot.yml new file mode 100644 index 00000000..830fe964 --- /dev/null +++ b/kustomize/deployment/vote-bot.yml @@ -0,0 +1,26 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: vote-bot + namespace: emojivoto +spec: + replicas: 1 + selector: + matchLabels: + app: vote-bot + template: + metadata: + labels: + app: vote-bot + spec: + containers: + - command: + - emojivoto-vote-bot + env: + - name: WEB_HOST + value: web-svc.emojivoto:80 + image: buoyantio/emojivoto-web:v8 + name: vote-bot + resources: + requests: + cpu: 10m diff --git a/kustomize/deployment/voting.yml b/kustomize/deployment/voting.yml new file mode 100644 index 00000000..d3895f3b --- /dev/null +++ b/kustomize/deployment/voting.yml @@ -0,0 +1,47 @@ +kind: ServiceAccount +apiVersion: v1 +metadata: + name: voting + namespace: emojivoto +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: voting + namespace: emojivoto +spec: + replicas: 1 + selector: + matchLabels: + app: voting-svc + template: + metadata: + labels: + app: voting-svc + spec: + serviceAccountName: voting + containers: + - env: + - name: GRPC_PORT + value: "8080" + image: buoyantio/emojivoto-voting-svc:v8 + name: voting-svc + ports: + - containerPort: 8080 + name: grpc + resources: + requests: + cpu: 100m +--- +apiVersion: v1 +kind: Service +metadata: + name: voting-svc + namespace: emojivoto +spec: + selector: + app: voting-svc + ports: + - name: grpc + port: 8080 + targetPort: 8080 diff --git a/kustomize/deployment/web.yml b/kustomize/deployment/web.yml new file mode 100644 index 00000000..535930e7 --- /dev/null +++ b/kustomize/deployment/web.yml @@ -0,0 +1,54 @@ +kind: ServiceAccount +apiVersion: v1 +metadata: + name: web + namespace: emojivoto +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: web + namespace: emojivoto +spec: + replicas: 1 + selector: + matchLabels: + app: web-svc + template: + metadata: + labels: + app: web-svc + spec: + serviceAccountName: web + containers: + - env: + - name: WEB_PORT + value: "8080" + - name: EMOJISVC_HOST + value: emoji-svc.emojivoto:8080 + - name: VOTINGSVC_HOST + value: voting-svc.emojivoto:8080 + - name: INDEX_BUNDLE + value: dist/index_bundle.js + image: buoyantio/emojivoto-web:v8 + name: web-svc + ports: + - containerPort: 8080 + name: http + resources: + requests: + cpu: 100m +--- +apiVersion: v1 +kind: Service +metadata: + name: web-svc + namespace: emojivoto +spec: + type: LoadBalancer + selector: + app: web-svc + ports: + - name: http + port: 80 + targetPort: 8080 diff --git a/kustomize/job/kustomization.yml b/kustomize/job/kustomization.yml new file mode 100644 index 00000000..0523618c --- /dev/null +++ b/kustomize/job/kustomization.yml @@ -0,0 +1,27 @@ +bases: +- ../deployment +patchesJson6902: +- target: + group: apps + version: v1 + kind: Deployment + name: web + path: patch.yml +- target: + group: apps + version: v1 + kind: Deployment + name: emoji + path: patch.yml +- target: + group: apps + version: v1 + kind: Deployment + name: voting + path: patch.yml +- target: + group: apps + version: v1 + kind: Deployment + name: vote-bot + path: patch.yml diff --git a/kustomize/job/patch.yml b/kustomize/job/patch.yml new file mode 100644 index 00000000..dc3de814 --- /dev/null +++ b/kustomize/job/patch.yml @@ -0,0 +1,17 @@ +- op: replace + path: /kind + value: Job + +- op: replace + path: /apiVersion + value: batch/v1 + +- op: remove + path: /spec/replicas + +- op: remove + path: /spec/selector + +- op: add + path: /spec/template/spec/restartPolicy + value: OnFailure diff --git a/kustomize/statefulset/kustomization.yml b/kustomize/statefulset/kustomization.yml new file mode 100644 index 00000000..e0ca2e99 --- /dev/null +++ b/kustomize/statefulset/kustomization.yml @@ -0,0 +1,29 @@ +bases: +- ../deployment +patches: +- service-name.yml +patchesJson6902: +- target: + group: apps + version: v1 + kind: Deployment + name: web + path: patch.yml +- target: + group: apps + version: v1 + kind: Deployment + name: emoji + path: patch.yml +- target: + group: apps + version: v1 + kind: Deployment + name: voting + path: patch.yml +- target: + group: apps + version: v1 + kind: Deployment + name: vote-bot + path: patch.yml diff --git a/kustomize/statefulset/patch.yml b/kustomize/statefulset/patch.yml new file mode 100644 index 00000000..f30dbc61 --- /dev/null +++ b/kustomize/statefulset/patch.yml @@ -0,0 +1,3 @@ +- op: replace + path: /kind + value: StatefulSet diff --git a/kustomize/statefulset/service-name.yml b/kustomize/statefulset/service-name.yml new file mode 100644 index 00000000..fce0fb87 --- /dev/null +++ b/kustomize/statefulset/service-name.yml @@ -0,0 +1,27 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: emoji +spec: + serviceName: emoji-svc +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: voting +spec: + serviceName: voting-svc +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: web +spec: + serviceName: web-svc +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: vote-bot +spec: + serviceName: vote-bot From 9787ad652b918b504c28523fee3e3f7a39934ae3 Mon Sep 17 00:00:00 2001 From: grampelberg Date: Fri, 8 Nov 2019 09:20:13 -0800 Subject: [PATCH 5/7] Bump image version --- Dockerfile | 2 +- README.md | 8 ++++---- docker-compose.yml | 8 ++++---- kustomize/deployment/emoji.yml | 2 +- kustomize/deployment/vote-bot.yml | 2 +- kustomize/deployment/voting.yml | 2 +- kustomize/deployment/web.yml | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0bacf1fa..e6f90704 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM buoyantio/emojivoto-svc-base:v8 +FROM buoyantio/emojivoto-svc-base:v9 ARG svc_name diff --git a/README.md b/README.md index 1e0b2c8b..925c31fa 100644 --- a/README.md +++ b/README.md @@ -91,10 +91,10 @@ To update the docker images: ```bash docker login - docker push buoyantio/emojivoto-svc-base:v8 - docker push buoyantio/emojivoto-emoji-svc:v8 - docker push buoyantio/emojivoto-voting-svc:v8 - docker push buoyantio/emojivoto-web:v8 + docker push buoyantio/emojivoto-svc-base:v9 + docker push buoyantio/emojivoto-emoji-svc:v9 + docker push buoyantio/emojivoto-voting-svc:v9 + docker push buoyantio/emojivoto-web:v9 ``` 1. Update `emojivoto.yml`, `docker-compose.yml` diff --git a/docker-compose.yml b/docker-compose.yml index 29471a90..d33c84c6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: '3' services: web: - image: buoyantio/emojivoto-web:v8 + image: buoyantio/emojivoto-web:v9 environment: - WEB_PORT=8080 - EMOJISVC_HOST=emoji-svc:8080 @@ -15,7 +15,7 @@ services: - emoji-svc vote-bot: - image: buoyantio/emojivoto-web:v8 + image: buoyantio/emojivoto-web:v9 entrypoint: emojivoto-vote-bot environment: - WEB_HOST=web:8080 @@ -23,14 +23,14 @@ services: - web emoji-svc: - image: buoyantio/emojivoto-emoji-svc:v8 + image: buoyantio/emojivoto-emoji-svc:v9 environment: - GRPC_PORT=8080 ports: - "8081:8080" voting-svc: - image: buoyantio/emojivoto-voting-svc:v8 + image: buoyantio/emojivoto-voting-svc:v9 environment: - GRPC_PORT=8080 ports: diff --git a/kustomize/deployment/emoji.yml b/kustomize/deployment/emoji.yml index 5b139518..55b544eb 100644 --- a/kustomize/deployment/emoji.yml +++ b/kustomize/deployment/emoji.yml @@ -24,7 +24,7 @@ spec: - env: - name: GRPC_PORT value: "8080" - image: buoyantio/emojivoto-emoji-svc:v8 + image: buoyantio/emojivoto-emoji-svc:v9 name: emoji-svc ports: - containerPort: 8080 diff --git a/kustomize/deployment/vote-bot.yml b/kustomize/deployment/vote-bot.yml index 830fe964..d59039d8 100644 --- a/kustomize/deployment/vote-bot.yml +++ b/kustomize/deployment/vote-bot.yml @@ -19,7 +19,7 @@ spec: env: - name: WEB_HOST value: web-svc.emojivoto:80 - image: buoyantio/emojivoto-web:v8 + image: buoyantio/emojivoto-web:v9 name: vote-bot resources: requests: diff --git a/kustomize/deployment/voting.yml b/kustomize/deployment/voting.yml index d3895f3b..068c94ef 100644 --- a/kustomize/deployment/voting.yml +++ b/kustomize/deployment/voting.yml @@ -24,7 +24,7 @@ spec: - env: - name: GRPC_PORT value: "8080" - image: buoyantio/emojivoto-voting-svc:v8 + image: buoyantio/emojivoto-voting-svc:v9 name: voting-svc ports: - containerPort: 8080 diff --git a/kustomize/deployment/web.yml b/kustomize/deployment/web.yml index 535930e7..5e77ac8e 100644 --- a/kustomize/deployment/web.yml +++ b/kustomize/deployment/web.yml @@ -30,7 +30,7 @@ spec: value: voting-svc.emojivoto:8080 - name: INDEX_BUNDLE value: dist/index_bundle.js - image: buoyantio/emojivoto-web:v8 + image: buoyantio/emojivoto-web:v9 name: web-svc ports: - containerPort: 8080 From 54c40292724a434bdfa980d012c5a423ed5a9ef3 Mon Sep 17 00:00:00 2001 From: grampelberg Date: Fri, 8 Nov 2019 15:27:02 -0800 Subject: [PATCH 6/7] Start traces 100% of the time in vote-bot --- emojivoto-web/cmd/vote-bot/main.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/emojivoto-web/cmd/vote-bot/main.go b/emojivoto-web/cmd/vote-bot/main.go index 0b63542e..5a37557c 100644 --- a/emojivoto-web/cmd/vote-bot/main.go +++ b/emojivoto-web/cmd/vote-bot/main.go @@ -10,6 +10,10 @@ import ( "net/url" "os" "time" + + "contrib.go.opencensus.io/exporter/ocagent" + "go.opencensus.io/plugin/ochttp" + "go.opencensus.io/trace" ) // VoteBot votes for emoji! :ballot_box_with_check: @@ -19,6 +23,12 @@ import ( // When not voting for :doughnut:, VoteBot can’t be bothered to // pick a favorite, so it picks one at random. C'mon VoteBot, try harder! +var ( + client = &http.Client{Transport: &ochttp.Transport{}} + + ocagentHost = os.Getenv("OC_AGENT_HOST") +) + type emoji struct { Shortcode string } @@ -31,6 +41,17 @@ func main() { log.Fatalf("WEB_HOST environment variable must me set") } + oce, err := ocagent.NewExporter( + ocagent.WithInsecure(), + ocagent.WithReconnectionPeriod(5*time.Second), + ocagent.WithAddress(ocagentHost), + ocagent.WithServiceName("vote-bot")) + if err != nil { + log.Fatalf("Failed to create ocagent-exporter: %v", err) + } + trace.RegisterExporter(oce) + trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()}) + webUrl := "http://" + webHost if _, err := url.Parse(webUrl); err != nil { log.Fatalf("WEB_HOST %s is invalid", webHost) @@ -64,7 +85,7 @@ func main() { func shortcodes(webUrl string) ([]string, error) { url := fmt.Sprintf("%s/api/list", webUrl) - resp, err := http.Get(url) + resp, err := client.Get(url) if err != nil { return nil, err } @@ -93,7 +114,7 @@ func vote(webUrl string, shortcode string) error { fmt.Printf("✔ Voting for %s\n", shortcode) url := fmt.Sprintf("%s/api/vote?choice=%s", webUrl, shortcode) - resp, err := http.Get(url) + resp, err := client.Get(url) if err != nil { return err } From bbed3a6d5968b228aea560b3d93db7b5a9a84724 Mon Sep 17 00:00:00 2001 From: grampelberg Date: Fri, 8 Nov 2019 15:27:30 -0800 Subject: [PATCH 7/7] Add a tracing configuration --- kustomize/tracing/kustomization.yml | 27 +++++++++++++++++++++++++++ kustomize/tracing/patch.yml | 11 +++++++++++ 2 files changed, 38 insertions(+) create mode 100644 kustomize/tracing/kustomization.yml create mode 100644 kustomize/tracing/patch.yml diff --git a/kustomize/tracing/kustomization.yml b/kustomize/tracing/kustomization.yml new file mode 100644 index 00000000..0523618c --- /dev/null +++ b/kustomize/tracing/kustomization.yml @@ -0,0 +1,27 @@ +bases: +- ../deployment +patchesJson6902: +- target: + group: apps + version: v1 + kind: Deployment + name: web + path: patch.yml +- target: + group: apps + version: v1 + kind: Deployment + name: emoji + path: patch.yml +- target: + group: apps + version: v1 + kind: Deployment + name: voting + path: patch.yml +- target: + group: apps + version: v1 + kind: Deployment + name: vote-bot + path: patch.yml diff --git a/kustomize/tracing/patch.yml b/kustomize/tracing/patch.yml new file mode 100644 index 00000000..46b739b7 --- /dev/null +++ b/kustomize/tracing/patch.yml @@ -0,0 +1,11 @@ +- op: add + path: /spec/template/spec/containers/0/env/- + value: + name: OC_AGENT_HOST + value: oc-collector.tracing:55678 + +- op: add + path: /spec/template/metadata/annotations + value: + linkerd.io/inject: enabled + config.linkerd.io/trace-collector: oc-collector.tracing:55678