diff --git a/kubernetes-manifests/checkoutservice.yaml b/kubernetes-manifests/checkoutservice.yaml index b78048a..23668a6 100644 --- a/kubernetes-manifests/checkoutservice.yaml +++ b/kubernetes-manifests/checkoutservice.yaml @@ -28,13 +28,11 @@ spec: ports: - containerPort: 5050 readinessProbe: - periodSeconds: 5 - tcpSocket: - port: 5050 + exec: + command: ["/bin/grpc_health_probe", "-addr=:5050"] livenessProbe: - periodSeconds: 5 - tcpSocket: - port: 5050 + exec: + command: ["/bin/grpc_health_probe", "-addr=:5050"] env: - name: PRODUCT_CATALOG_SERVICE_ADDR value: "productcatalogservice:3550" diff --git a/kubernetes-manifests/productcatalogservice.yaml b/kubernetes-manifests/productcatalogservice.yaml index 45b5f88..1196356 100644 --- a/kubernetes-manifests/productcatalogservice.yaml +++ b/kubernetes-manifests/productcatalogservice.yaml @@ -29,13 +29,11 @@ spec: ports: - containerPort: 3550 readinessProbe: - periodSeconds: 5 - tcpSocket: - port: 3550 + exec: + command: ["/bin/grpc_health_probe", "-addr=:3550"] livenessProbe: - periodSeconds: 5 - tcpSocket: - port: 3550 + exec: + command: ["/bin/grpc_health_probe", "-addr=:3550"] resources: requests: cpu: 100m diff --git a/kubernetes-manifests/shippingservice.yaml b/kubernetes-manifests/shippingservice.yaml index dd78165..107b574 100644 --- a/kubernetes-manifests/shippingservice.yaml +++ b/kubernetes-manifests/shippingservice.yaml @@ -29,12 +29,11 @@ spec: - containerPort: 50051 readinessProbe: periodSeconds: 5 - tcpSocket: - port: 50051 + exec: + command: ["/bin/grpc_health_probe", "-addr=:50051"] livenessProbe: - periodSeconds: 5 - tcpSocket: - port: 50051 + exec: + command: ["/bin/grpc_health_probe", "-addr=:50051"] resources: requests: cpu: 100m diff --git a/src/checkoutservice/Dockerfile b/src/checkoutservice/Dockerfile index 383cf9a..4f6e616 100644 --- a/src/checkoutservice/Dockerfile +++ b/src/checkoutservice/Dockerfile @@ -15,6 +15,9 @@ RUN go build -gcflags='-N -l' -o /checkoutservice . FROM alpine as release RUN apk add --no-cache ca-certificates +RUN GRPC_HEALTH_PROBE_VERSION=v0.1.0-alpha.1 && \ + wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \ + chmod +x /bin/grpc_health_probe COPY --from=builder /checkoutservice /checkoutservice EXPOSE 5050 ENTRYPOINT ["/checkoutservice"] diff --git a/src/checkoutservice/Gopkg.lock b/src/checkoutservice/Gopkg.lock index bc89e55..036480d 100644 --- a/src/checkoutservice/Gopkg.lock +++ b/src/checkoutservice/Gopkg.lock @@ -2,43 +2,27 @@ [[projects]] - digest = "1:467af0aad47996b25b838d6f14c8371123a8a76ec239020a6c5894e1f8f60272" name = "cloud.google.com/go" packages = [ "compute/metadata", "internal/version", "monitoring/apiv3", "profiler", - "trace/apiv2", + "trace/apiv2" ] - pruneopts = "UT" revision = "c728a003b238b26cef9ab6753a5dc424b331c3ad" version = "v0.27.0" [[projects]] - digest = "1:9fe70def8f0ceb3d455a0acad9dadd6632287cdbf9c8c2ea50e8dabe2ade40c4" name = "contrib.go.opencensus.io/exporter/stackdriver" packages = [ ".", - "propagation", + "propagation" ] - pruneopts = "UT" revision = "37aa2801fbf0205003e15636096ebf0373510288" version = "v0.5.0" [[projects]] - branch = "master" - digest = "1:f5961cd4f136ee9f3a80ca62a05ecc4fb60107d6a323ae258a1c732b76861809" - name = "github.com/GoogleCloudPlatform/microservices-demo" - packages = [ - "src/checkoutservice/genproto", - "src/checkoutservice/money", - ] - pruneopts = "UT" - revision = "6d969441585ade8c91c235115c7cdb12ac61354f" - -[[projects]] - digest = "1:72856926f8208767b837bf51e3373f49139f61889b67dc7fd3c2a0fd711e3f7a" name = "github.com/golang/protobuf" packages = [ "proto", @@ -49,38 +33,30 @@ "ptypes/empty", "ptypes/struct", "ptypes/timestamp", - "ptypes/wrappers", + "ptypes/wrappers" ] - pruneopts = "UT" revision = "aa810b61a9c79d51363740d207bb46cf8e620ed5" version = "v1.2.0" [[projects]] branch = "master" - digest = "1:089d56c0adb79140365b5c86815ce97233986da6f3a525c6b706773e4b83876f" name = "github.com/google/pprof" packages = ["profile"] - pruneopts = "UT" - revision = "84b7d314e22c8d12334e52726f68517973b6027b" + revision = "e027b505a088ac3c68c339a1d7ce7724bf34538b" [[projects]] - digest = "1:3a26588bc48b96825977c1b3df964f8fd842cd6860cc26370588d3563433cf11" name = "github.com/google/uuid" packages = ["."] - pruneopts = "UT" revision = "d460ce9f8df2e77fb1ba55ca87fafed96c607494" version = "v1.0.0" [[projects]] - digest = "1:e145e9710a10bc114a6d3e2738aadf8de146adaa031854ffdf7bbfe15da85e63" name = "github.com/googleapis/gax-go" packages = ["."] - pruneopts = "UT" revision = "317e0006254c44a0ac427cc52a0e083ff0b9622f" version = "v2.0.0" [[projects]] - digest = "1:1bb914cfb78f68f488a91cd7872d3d06a5f83c5bbacf0296dbef44e120b00a91" name = "go.opencensus.io" packages = [ ".", @@ -96,15 +72,13 @@ "trace", "trace/internal", "trace/propagation", - "trace/tracestate", + "trace/tracestate" ] - pruneopts = "UT" revision = "b11f239c032624b045c4c2bfd3d1287b4012ce89" version = "v0.16.0" [[projects]] branch = "master" - digest = "1:1c14517b2f106c61d75006199b46a46576058661d469658cb0f90739919641d2" name = "golang.org/x/net" packages = [ "context", @@ -114,43 +88,35 @@ "http2/hpack", "idna", "internal/timeseries", - "trace", + "trace" ] - pruneopts = "UT" revision = "26e67e76b6c3f6ce91f7c52def5af501b4e0f3a2" [[projects]] branch = "master" - digest = "1:f645667d687fc8bf228865a2c5455824ef05bad08841e673673ef2bb89ac5b90" name = "golang.org/x/oauth2" packages = [ ".", "google", "internal", "jws", - "jwt", + "jwt" ] - pruneopts = "UT" revision = "d2e6202438beef2727060aa7cabdd924d92ebfd9" [[projects]] branch = "master" - digest = "1:e0140c0c868c6e0f01c0380865194592c011fe521d6e12d78bfd33e756fe018a" name = "golang.org/x/sync" packages = ["semaphore"] - pruneopts = "UT" revision = "1d60e4601c6fd243af51cc01ddf169918a5407ca" [[projects]] branch = "master" - digest = "1:6eb2645d74b43d9c87b51947df39f7c668a4f422cd512053f7f6f75bfaad0197" name = "golang.org/x/sys" packages = ["unix"] - pruneopts = "UT" - revision = "d0be0721c37eeb5299f245a996a483160fc36940" + revision = "1561086e645b2809fb9f8a1e2a38160bf8d53bf4" [[projects]] - digest = "1:a2ab62866c75542dd18d2b069fec854577a20211d7c0ea6ae746072a1dccdd18" name = "golang.org/x/text" packages = [ "collate", @@ -166,15 +132,13 @@ "unicode/bidi", "unicode/cldr", "unicode/norm", - "unicode/rangetable", + "unicode/rangetable" ] - pruneopts = "UT" revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" version = "v0.3.0" [[projects]] branch = "master" - digest = "1:e9e388241f9f0f02000dddaeeb91153d53f0cd09dcec33879cc7e043a2e65d75" name = "google.golang.org/api" packages = [ "googleapi/transport", @@ -184,13 +148,11 @@ "support/bundler", "transport", "transport/grpc", - "transport/http", + "transport/http" ] - pruneopts = "UT" - revision = "7ca32eb868bf53ea2fc406698eb98583a8073d19" + revision = "19ff8768a5c0b8e46ea281065664787eefc24121" [[projects]] - digest = "1:26619fcd2452b4044174d26acd8b09c09dffee9a1c3a22d2383b873aa9a0131f" name = "google.golang.org/appengine" packages = [ ".", @@ -204,15 +166,13 @@ "internal/socket", "internal/urlfetch", "socket", - "urlfetch", + "urlfetch" ] - pruneopts = "UT" - revision = "b1f26356af11148e710935ed1ac8a7f5702c7612" - version = "v1.1.0" + revision = "ae0ab99deb4dc413a2b4bd6c8bdd0eb67f1e4d06" + version = "v1.2.0" [[projects]] branch = "master" - digest = "1:7a3da01a8f840fbbef1f027dc091ae52a29c6ab9374e126b6bdc5bf3b0ff2687" name = "google.golang.org/genproto" packages = [ "googleapis/api/annotations", @@ -225,13 +185,11 @@ "googleapis/monitoring/v3", "googleapis/rpc/errdetails", "googleapis/rpc/status", - "protobuf/field_mask", + "protobuf/field_mask" ] - pruneopts = "UT" - revision = "36d5787dc5356b711fe8f3040271aaf51c35955b" + revision = "c3f76f3b92d1ffa4c58a9ff842a58b8877655e0f" [[projects]] - digest = "1:4ad047d772a7d4841687df9534a767a9e243885ed6d7d2ced6af5995a5dc44b3" name = "google.golang.org/grpc" packages = [ ".", @@ -245,6 +203,7 @@ "encoding", "encoding/proto", "grpclog", + "health/grpc_health_v1", "internal", "internal/backoff", "internal/channelz", @@ -260,29 +219,14 @@ "resolver/passthrough", "stats", "status", - "tap", + "tap" ] - pruneopts = "UT" - revision = "8dea3dc473e90c8179e519d91302d0597c0ca1d1" - version = "v1.15.0" + revision = "32fb0ac620c32ba40a4626ddf94d90d12cce3455" + version = "v1.14.0" [solve-meta] analyzer-name = "dep" analyzer-version = 1 - input-imports = [ - "cloud.google.com/go/profiler", - "contrib.go.opencensus.io/exporter/stackdriver", - "github.com/GoogleCloudPlatform/microservices-demo/src/checkoutservice/genproto", - "github.com/GoogleCloudPlatform/microservices-demo/src/checkoutservice/money", - "github.com/golang/protobuf/proto", - "github.com/google/uuid", - "go.opencensus.io/plugin/ocgrpc", - "go.opencensus.io/stats/view", - "go.opencensus.io/trace", - "golang.org/x/net/context", - "google.golang.org/grpc", - "google.golang.org/grpc/codes", - "google.golang.org/grpc/status", - ] + inputs-digest = "0c103e5e32d8ecdd70048b6d91e02b910e30bad54f06b230a9664f585433a669" solver-name = "gps-cdcl" solver-version = 1 diff --git a/src/checkoutservice/Gopkg.toml b/src/checkoutservice/Gopkg.toml index 79834b4..0599867 100644 --- a/src/checkoutservice/Gopkg.toml +++ b/src/checkoutservice/Gopkg.toml @@ -33,10 +33,6 @@ name = "contrib.go.opencensus.io/exporter/stackdriver" version = "0.5.0" -[[constraint]] - branch = "master" - name = "github.com/GoogleCloudPlatform/microservices-demo" - [[constraint]] name = "github.com/golang/protobuf" version = "1.2.0" @@ -55,7 +51,7 @@ [[constraint]] name = "google.golang.org/grpc" - version = "1.15.0" + version = "=1.14.0" [prune] go-tests = true diff --git a/src/checkoutservice/main.go b/src/checkoutservice/main.go index d5a9c07..116e051 100644 --- a/src/checkoutservice/main.go +++ b/src/checkoutservice/main.go @@ -34,6 +34,7 @@ import ( pb "github.com/GoogleCloudPlatform/microservices-demo/src/checkoutservice/genproto" money "github.com/GoogleCloudPlatform/microservices-demo/src/checkoutservice/money" + healthpb "google.golang.org/grpc/health/grpc_health_v1" ) const ( @@ -75,6 +76,7 @@ func main() { } srv := grpc.NewServer(grpc.StatsHandler(&ocgrpc.ServerHandler{})) pb.RegisterCheckoutServiceServer(srv, svc) + healthpb.RegisterHealthServer(srv, svc) log.Printf("starting to listen on tcp: %q", lis.Addr().String()) log.Fatal(srv.Serve(lis)) } @@ -141,6 +143,10 @@ func mustMapEnv(target *string, envKey string) { *target = v } +func (cs *checkoutService) Check(ctx context.Context, req *healthpb.HealthCheckRequest) (*healthpb.HealthCheckResponse, error) { + return &healthpb.HealthCheckResponse{Status: healthpb.HealthCheckResponse_SERVING}, nil +} + func (cs *checkoutService) PlaceOrder(ctx context.Context, req *pb.PlaceOrderRequest) (*pb.PlaceOrderResponse, error) { log.Printf("[PlaceOrder] user_id=%q user_currency=%q", req.UserId, req.UserCurrency) diff --git a/src/productcatalogservice/Dockerfile b/src/productcatalogservice/Dockerfile index b2677d5..f941605 100644 --- a/src/productcatalogservice/Dockerfile +++ b/src/productcatalogservice/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.10-alpine as builder +FROM golang:1.10-alpine AS builder RUN apk add --no-cache ca-certificates git && \ wget -qO/go/bin/dep https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 && \ chmod +x /go/bin/dep @@ -13,8 +13,11 @@ RUN dep ensure --vendor-only -v COPY . . RUN go build -o /productcatalogservice . -FROM alpine as release +FROM alpine AS release RUN apk add --no-cache ca-certificates +RUN GRPC_HEALTH_PROBE_VERSION=v0.1.0-alpha.1 && \ + wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \ + chmod +x /bin/grpc_health_probe WORKDIR /productcatalogservice COPY --from=builder /productcatalogservice ./server COPY products.json . diff --git a/src/productcatalogservice/Gopkg.lock b/src/productcatalogservice/Gopkg.lock index dcf1320..b9a3bbd 100644 --- a/src/productcatalogservice/Gopkg.lock +++ b/src/productcatalogservice/Gopkg.lock @@ -2,40 +2,27 @@ [[projects]] - digest = "1:467af0aad47996b25b838d6f14c8371123a8a76ec239020a6c5894e1f8f60272" name = "cloud.google.com/go" packages = [ "compute/metadata", "internal/version", "monitoring/apiv3", "profiler", - "trace/apiv2", + "trace/apiv2" ] - pruneopts = "UT" revision = "c728a003b238b26cef9ab6753a5dc424b331c3ad" version = "v0.27.0" [[projects]] - digest = "1:9fe70def8f0ceb3d455a0acad9dadd6632287cdbf9c8c2ea50e8dabe2ade40c4" name = "contrib.go.opencensus.io/exporter/stackdriver" packages = [ ".", - "propagation", + "propagation" ] - pruneopts = "UT" revision = "37aa2801fbf0205003e15636096ebf0373510288" version = "v0.5.0" [[projects]] - branch = "master" - digest = "1:c82c943645b21ca2fd3f9d248df1ca5f9055fb5fea5cf4145472163f198ed5df" - name = "github.com/GoogleCloudPlatform/microservices-demo" - packages = ["src/productcatalogservice/genproto"] - pruneopts = "UT" - revision = "6d969441585ade8c91c235115c7cdb12ac61354f" - -[[projects]] - digest = "1:4fbf68bee2a60f6af6414572936edb295f6f26b73c6fb25ab0e7b03b013854f5" name = "github.com/golang/protobuf" packages = [ "jsonpb", @@ -47,43 +34,35 @@ "ptypes/empty", "ptypes/struct", "ptypes/timestamp", - "ptypes/wrappers", + "ptypes/wrappers" ] - pruneopts = "UT" revision = "aa810b61a9c79d51363740d207bb46cf8e620ed5" version = "v1.2.0" [[projects]] - digest = "1:2e3c336fc7fde5c984d2841455a658a6d626450b1754a854b3b32e7a8f49a07a" name = "github.com/google/go-cmp" packages = [ "cmp", "cmp/internal/diff", "cmp/internal/function", - "cmp/internal/value", + "cmp/internal/value" ] - pruneopts = "UT" revision = "3af367b6b30c263d47e8895973edcca9a49cf029" version = "v0.2.0" [[projects]] branch = "master" - digest = "1:089d56c0adb79140365b5c86815ce97233986da6f3a525c6b706773e4b83876f" name = "github.com/google/pprof" packages = ["profile"] - pruneopts = "UT" - revision = "84b7d314e22c8d12334e52726f68517973b6027b" + revision = "e027b505a088ac3c68c339a1d7ce7724bf34538b" [[projects]] - digest = "1:e145e9710a10bc114a6d3e2738aadf8de146adaa031854ffdf7bbfe15da85e63" name = "github.com/googleapis/gax-go" packages = ["."] - pruneopts = "UT" revision = "317e0006254c44a0ac427cc52a0e083ff0b9622f" version = "v2.0.0" [[projects]] - digest = "1:1bb914cfb78f68f488a91cd7872d3d06a5f83c5bbacf0296dbef44e120b00a91" name = "go.opencensus.io" packages = [ ".", @@ -99,15 +78,13 @@ "trace", "trace/internal", "trace/propagation", - "trace/tracestate", + "trace/tracestate" ] - pruneopts = "UT" revision = "b11f239c032624b045c4c2bfd3d1287b4012ce89" version = "v0.16.0" [[projects]] branch = "master" - digest = "1:1c14517b2f106c61d75006199b46a46576058661d469658cb0f90739919641d2" name = "golang.org/x/net" packages = [ "context", @@ -117,43 +94,35 @@ "http2/hpack", "idna", "internal/timeseries", - "trace", + "trace" ] - pruneopts = "UT" revision = "26e67e76b6c3f6ce91f7c52def5af501b4e0f3a2" [[projects]] branch = "master" - digest = "1:f645667d687fc8bf228865a2c5455824ef05bad08841e673673ef2bb89ac5b90" name = "golang.org/x/oauth2" packages = [ ".", "google", "internal", "jws", - "jwt", + "jwt" ] - pruneopts = "UT" revision = "d2e6202438beef2727060aa7cabdd924d92ebfd9" [[projects]] branch = "master" - digest = "1:e0140c0c868c6e0f01c0380865194592c011fe521d6e12d78bfd33e756fe018a" name = "golang.org/x/sync" packages = ["semaphore"] - pruneopts = "UT" revision = "1d60e4601c6fd243af51cc01ddf169918a5407ca" [[projects]] branch = "master" - digest = "1:6eb2645d74b43d9c87b51947df39f7c668a4f422cd512053f7f6f75bfaad0197" name = "golang.org/x/sys" packages = ["unix"] - pruneopts = "UT" - revision = "d0be0721c37eeb5299f245a996a483160fc36940" + revision = "1561086e645b2809fb9f8a1e2a38160bf8d53bf4" [[projects]] - digest = "1:a2ab62866c75542dd18d2b069fec854577a20211d7c0ea6ae746072a1dccdd18" name = "golang.org/x/text" packages = [ "collate", @@ -169,15 +138,13 @@ "unicode/bidi", "unicode/cldr", "unicode/norm", - "unicode/rangetable", + "unicode/rangetable" ] - pruneopts = "UT" revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" version = "v0.3.0" [[projects]] branch = "master" - digest = "1:e9e388241f9f0f02000dddaeeb91153d53f0cd09dcec33879cc7e043a2e65d75" name = "google.golang.org/api" packages = [ "googleapi/transport", @@ -187,13 +154,11 @@ "support/bundler", "transport", "transport/grpc", - "transport/http", + "transport/http" ] - pruneopts = "UT" - revision = "7ca32eb868bf53ea2fc406698eb98583a8073d19" + revision = "19ff8768a5c0b8e46ea281065664787eefc24121" [[projects]] - digest = "1:26619fcd2452b4044174d26acd8b09c09dffee9a1c3a22d2383b873aa9a0131f" name = "google.golang.org/appengine" packages = [ ".", @@ -207,15 +172,13 @@ "internal/socket", "internal/urlfetch", "socket", - "urlfetch", + "urlfetch" ] - pruneopts = "UT" - revision = "b1f26356af11148e710935ed1ac8a7f5702c7612" - version = "v1.1.0" + revision = "ae0ab99deb4dc413a2b4bd6c8bdd0eb67f1e4d06" + version = "v1.2.0" [[projects]] branch = "master" - digest = "1:7a3da01a8f840fbbef1f027dc091ae52a29c6ab9374e126b6bdc5bf3b0ff2687" name = "google.golang.org/genproto" packages = [ "googleapis/api/annotations", @@ -228,13 +191,11 @@ "googleapis/monitoring/v3", "googleapis/rpc/errdetails", "googleapis/rpc/status", - "protobuf/field_mask", + "protobuf/field_mask" ] - pruneopts = "UT" - revision = "36d5787dc5356b711fe8f3040271aaf51c35955b" + revision = "c3f76f3b92d1ffa4c58a9ff842a58b8877655e0f" [[projects]] - digest = "1:4ad047d772a7d4841687df9534a767a9e243885ed6d7d2ced6af5995a5dc44b3" name = "google.golang.org/grpc" packages = [ ".", @@ -248,6 +209,7 @@ "encoding", "encoding/proto", "grpclog", + "health/grpc_health_v1", "internal", "internal/backoff", "internal/channelz", @@ -263,29 +225,14 @@ "resolver/passthrough", "stats", "status", - "tap", + "tap" ] - pruneopts = "UT" - revision = "8dea3dc473e90c8179e519d91302d0597c0ca1d1" - version = "v1.15.0" + revision = "32fb0ac620c32ba40a4626ddf94d90d12cce3455" + version = "v1.14.0" [solve-meta] analyzer-name = "dep" analyzer-version = 1 - input-imports = [ - "cloud.google.com/go/profiler", - "contrib.go.opencensus.io/exporter/stackdriver", - "github.com/GoogleCloudPlatform/microservices-demo/src/productcatalogservice/genproto", - "github.com/golang/protobuf/jsonpb", - "github.com/golang/protobuf/proto", - "github.com/google/go-cmp/cmp", - "go.opencensus.io/plugin/ocgrpc", - "go.opencensus.io/stats/view", - "go.opencensus.io/trace", - "golang.org/x/net/context", - "google.golang.org/grpc", - "google.golang.org/grpc/codes", - "google.golang.org/grpc/status", - ] + inputs-digest = "b68fd9438c2eb711d9fc51c1f23c5ca0d5169bf4022351dfc400cd35ba39dfaa" solver-name = "gps-cdcl" solver-version = 1 diff --git a/src/productcatalogservice/Gopkg.toml b/src/productcatalogservice/Gopkg.toml index 585d63c..a9b34ec 100644 --- a/src/productcatalogservice/Gopkg.toml +++ b/src/productcatalogservice/Gopkg.toml @@ -33,10 +33,6 @@ name = "contrib.go.opencensus.io/exporter/stackdriver" version = "0.5.0" -[[constraint]] - branch = "master" - name = "github.com/GoogleCloudPlatform/microservices-demo" - [[constraint]] name = "github.com/golang/protobuf" version = "1.2.0" @@ -55,7 +51,7 @@ [[constraint]] name = "google.golang.org/grpc" - version = "1.15.0" + version = "=1.14.0" [prune] go-tests = true diff --git a/src/productcatalogservice/server.go b/src/productcatalogservice/server.go index d0ee660..6599877 100644 --- a/src/productcatalogservice/server.go +++ b/src/productcatalogservice/server.go @@ -26,6 +26,7 @@ import ( "time" pb "github.com/GoogleCloudPlatform/microservices-demo/src/productcatalogservice/genproto" + healthpb "google.golang.org/grpc/health/grpc_health_v1" "cloud.google.com/go/profiler" "contrib.go.opencensus.io/exporter/stackdriver" @@ -69,7 +70,9 @@ func run(port int) string { log.Fatal(err) } srv := grpc.NewServer(grpc.StatsHandler(&ocgrpc.ServerHandler{})) - pb.RegisterProductCatalogServiceServer(srv, &productCatalog{}) + svc := &productCatalog{} + pb.RegisterProductCatalogServiceServer(srv, svc) + healthpb.RegisterHealthServer(srv, svc) go srv.Serve(l) return l.Addr().String() } @@ -140,6 +143,10 @@ func parseCatalog() []*pb.Product { return cat.Products } +func (p *productCatalog) Check(ctx context.Context, req *healthpb.HealthCheckRequest) (*healthpb.HealthCheckResponse, error) { + return &healthpb.HealthCheckResponse{Status: healthpb.HealthCheckResponse_SERVING}, nil +} + func (p *productCatalog) ListProducts(context.Context, *pb.Empty) (*pb.ListProductsResponse, error) { return &pb.ListProductsResponse{Products: parseCatalog()}, nil } diff --git a/src/shippingservice/Dockerfile b/src/shippingservice/Dockerfile index a9b3e17..ef44642 100644 --- a/src/shippingservice/Dockerfile +++ b/src/shippingservice/Dockerfile @@ -14,6 +14,9 @@ RUN go install . FROM alpine as release RUN apk add --no-cache ca-certificates +RUN GRPC_HEALTH_PROBE_VERSION=v0.1.0-alpha.1 && \ + wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \ + chmod +x /bin/grpc_health_probe COPY --from=builder /go/bin/shippingservice /shippingservice ENV APP_PORT=50051 EXPOSE 50051 diff --git a/src/shippingservice/Gopkg.lock b/src/shippingservice/Gopkg.lock index 667ef6d..998e4eb 100644 --- a/src/shippingservice/Gopkg.lock +++ b/src/shippingservice/Gopkg.lock @@ -2,40 +2,27 @@ [[projects]] - digest = "1:467af0aad47996b25b838d6f14c8371123a8a76ec239020a6c5894e1f8f60272" name = "cloud.google.com/go" packages = [ "compute/metadata", "internal/version", "monitoring/apiv3", "profiler", - "trace/apiv2", + "trace/apiv2" ] - pruneopts = "UT" revision = "c728a003b238b26cef9ab6753a5dc424b331c3ad" version = "v0.27.0" [[projects]] - digest = "1:9fe70def8f0ceb3d455a0acad9dadd6632287cdbf9c8c2ea50e8dabe2ade40c4" name = "contrib.go.opencensus.io/exporter/stackdriver" packages = [ ".", - "propagation", + "propagation" ] - pruneopts = "UT" revision = "37aa2801fbf0205003e15636096ebf0373510288" version = "v0.5.0" [[projects]] - branch = "master" - digest = "1:57b417980654aa49be2ff6a1ee6498a412ab253930dd95f1e1f27a9bbf2e1081" - name = "github.com/GoogleCloudPlatform/microservices-demo" - packages = ["src/shippingservice/genproto"] - pruneopts = "UT" - revision = "6d969441585ade8c91c235115c7cdb12ac61354f" - -[[projects]] - digest = "1:72856926f8208767b837bf51e3373f49139f61889b67dc7fd3c2a0fd711e3f7a" name = "github.com/golang/protobuf" packages = [ "proto", @@ -46,30 +33,24 @@ "ptypes/empty", "ptypes/struct", "ptypes/timestamp", - "ptypes/wrappers", + "ptypes/wrappers" ] - pruneopts = "UT" revision = "aa810b61a9c79d51363740d207bb46cf8e620ed5" version = "v1.2.0" [[projects]] branch = "master" - digest = "1:089d56c0adb79140365b5c86815ce97233986da6f3a525c6b706773e4b83876f" name = "github.com/google/pprof" packages = ["profile"] - pruneopts = "UT" - revision = "84b7d314e22c8d12334e52726f68517973b6027b" + revision = "e027b505a088ac3c68c339a1d7ce7724bf34538b" [[projects]] - digest = "1:e145e9710a10bc114a6d3e2738aadf8de146adaa031854ffdf7bbfe15da85e63" name = "github.com/googleapis/gax-go" packages = ["."] - pruneopts = "UT" revision = "317e0006254c44a0ac427cc52a0e083ff0b9622f" version = "v2.0.0" [[projects]] - digest = "1:1bb914cfb78f68f488a91cd7872d3d06a5f83c5bbacf0296dbef44e120b00a91" name = "go.opencensus.io" packages = [ ".", @@ -85,15 +66,13 @@ "trace", "trace/internal", "trace/propagation", - "trace/tracestate", + "trace/tracestate" ] - pruneopts = "UT" revision = "b11f239c032624b045c4c2bfd3d1287b4012ce89" version = "v0.16.0" [[projects]] branch = "master" - digest = "1:1c14517b2f106c61d75006199b46a46576058661d469658cb0f90739919641d2" name = "golang.org/x/net" packages = [ "context", @@ -103,43 +82,35 @@ "http2/hpack", "idna", "internal/timeseries", - "trace", + "trace" ] - pruneopts = "UT" revision = "26e67e76b6c3f6ce91f7c52def5af501b4e0f3a2" [[projects]] branch = "master" - digest = "1:f645667d687fc8bf228865a2c5455824ef05bad08841e673673ef2bb89ac5b90" name = "golang.org/x/oauth2" packages = [ ".", "google", "internal", "jws", - "jwt", + "jwt" ] - pruneopts = "UT" revision = "d2e6202438beef2727060aa7cabdd924d92ebfd9" [[projects]] branch = "master" - digest = "1:e0140c0c868c6e0f01c0380865194592c011fe521d6e12d78bfd33e756fe018a" name = "golang.org/x/sync" packages = ["semaphore"] - pruneopts = "UT" revision = "1d60e4601c6fd243af51cc01ddf169918a5407ca" [[projects]] branch = "master" - digest = "1:6eb2645d74b43d9c87b51947df39f7c668a4f422cd512053f7f6f75bfaad0197" name = "golang.org/x/sys" packages = ["unix"] - pruneopts = "UT" - revision = "d0be0721c37eeb5299f245a996a483160fc36940" + revision = "1561086e645b2809fb9f8a1e2a38160bf8d53bf4" [[projects]] - digest = "1:a2ab62866c75542dd18d2b069fec854577a20211d7c0ea6ae746072a1dccdd18" name = "golang.org/x/text" packages = [ "collate", @@ -155,15 +126,13 @@ "unicode/bidi", "unicode/cldr", "unicode/norm", - "unicode/rangetable", + "unicode/rangetable" ] - pruneopts = "UT" revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" version = "v0.3.0" [[projects]] branch = "master" - digest = "1:e9e388241f9f0f02000dddaeeb91153d53f0cd09dcec33879cc7e043a2e65d75" name = "google.golang.org/api" packages = [ "googleapi/transport", @@ -173,13 +142,11 @@ "support/bundler", "transport", "transport/grpc", - "transport/http", + "transport/http" ] - pruneopts = "UT" - revision = "7ca32eb868bf53ea2fc406698eb98583a8073d19" + revision = "19ff8768a5c0b8e46ea281065664787eefc24121" [[projects]] - digest = "1:26619fcd2452b4044174d26acd8b09c09dffee9a1c3a22d2383b873aa9a0131f" name = "google.golang.org/appengine" packages = [ ".", @@ -193,15 +160,13 @@ "internal/socket", "internal/urlfetch", "socket", - "urlfetch", + "urlfetch" ] - pruneopts = "UT" - revision = "b1f26356af11148e710935ed1ac8a7f5702c7612" - version = "v1.1.0" + revision = "ae0ab99deb4dc413a2b4bd6c8bdd0eb67f1e4d06" + version = "v1.2.0" [[projects]] branch = "master" - digest = "1:7a3da01a8f840fbbef1f027dc091ae52a29c6ab9374e126b6bdc5bf3b0ff2687" name = "google.golang.org/genproto" packages = [ "googleapis/api/annotations", @@ -214,13 +179,11 @@ "googleapis/monitoring/v3", "googleapis/rpc/errdetails", "googleapis/rpc/status", - "protobuf/field_mask", + "protobuf/field_mask" ] - pruneopts = "UT" - revision = "36d5787dc5356b711fe8f3040271aaf51c35955b" + revision = "c3f76f3b92d1ffa4c58a9ff842a58b8877655e0f" [[projects]] - digest = "1:97c4b6de720998595a38558d26277cffc14290a7f60ae2cf6f077a300c50ed17" name = "google.golang.org/grpc" packages = [ ".", @@ -234,6 +197,7 @@ "encoding", "encoding/proto", "grpclog", + "health/grpc_health_v1", "internal", "internal/backoff", "internal/channelz", @@ -251,26 +215,14 @@ "resolver/passthrough", "stats", "status", - "tap", + "tap" ] - pruneopts = "UT" - revision = "8dea3dc473e90c8179e519d91302d0597c0ca1d1" - version = "v1.15.0" + revision = "32fb0ac620c32ba40a4626ddf94d90d12cce3455" + version = "v1.14.0" [solve-meta] analyzer-name = "dep" analyzer-version = 1 - input-imports = [ - "cloud.google.com/go/profiler", - "contrib.go.opencensus.io/exporter/stackdriver", - "github.com/GoogleCloudPlatform/microservices-demo/src/shippingservice/genproto", - "github.com/golang/protobuf/proto", - "go.opencensus.io/plugin/ocgrpc", - "go.opencensus.io/stats/view", - "go.opencensus.io/trace", - "golang.org/x/net/context", - "google.golang.org/grpc", - "google.golang.org/grpc/reflection", - ] + inputs-digest = "5dac84cd5efcc89491aa3cda06a774c1b370c8e0cbdb99668cbfd8ba27b3e32c" solver-name = "gps-cdcl" solver-version = 1 diff --git a/src/shippingservice/Gopkg.toml b/src/shippingservice/Gopkg.toml index d82eeb4..eafb618 100644 --- a/src/shippingservice/Gopkg.toml +++ b/src/shippingservice/Gopkg.toml @@ -33,10 +33,6 @@ name = "contrib.go.opencensus.io/exporter/stackdriver" version = "0.5.0" -[[constraint]] - branch = "master" - name = "github.com/GoogleCloudPlatform/microservices-demo" - [[constraint]] name = "github.com/golang/protobuf" version = "1.2.0" @@ -51,7 +47,7 @@ [[constraint]] name = "google.golang.org/grpc" - version = "1.15.0" + version = "=1.14.0" [prune] go-tests = true diff --git a/src/shippingservice/main.go b/src/shippingservice/main.go index bcef405..f82787a 100644 --- a/src/shippingservice/main.go +++ b/src/shippingservice/main.go @@ -31,6 +31,7 @@ import ( "google.golang.org/grpc/reflection" pb "github.com/GoogleCloudPlatform/microservices-demo/src/shippingservice/genproto" + healthpb "google.golang.org/grpc/health/grpc_health_v1" ) const ( @@ -51,13 +52,15 @@ func main() { if err != nil { log.Fatalf("failed to listen: %v", err) } - s := grpc.NewServer(grpc.StatsHandler(&ocgrpc.ServerHandler{})) - pb.RegisterShippingServiceServer(s, &server{}) + srv := grpc.NewServer(grpc.StatsHandler(&ocgrpc.ServerHandler{})) + svc := &server{} + pb.RegisterShippingServiceServer(srv, svc) + healthpb.RegisterHealthServer(srv, svc) log.Printf("Shipping Service listening on port %s", port) // Register reflection service on gRPC server. - reflection.Register(s) - if err := s.Serve(lis); err != nil { + reflection.Register(srv) + if err := srv.Serve(lis); err != nil { log.Fatalf("failed to serve: %v", err) } } @@ -65,6 +68,11 @@ func main() { // server controls RPC service responses. type server struct{} +// Check is for health checking. +func (s *server) Check(ctx context.Context, req *healthpb.HealthCheckRequest) (*healthpb.HealthCheckResponse, error) { + return &healthpb.HealthCheckResponse{Status: healthpb.HealthCheckResponse_SERVING}, nil +} + // GetQuote produces a shipping quote (cost) in USD. func (s *server) GetQuote(ctx context.Context, in *pb.GetQuoteRequest) (*pb.GetQuoteResponse, error) { log.Printf("[GetQuote] received request")