grpc: implement health check in go services (#27)

Also locked grpc-go to =1.14 exact version.
See grpc/grpc-go#2314 and grpc/grpc-go#2313 for reference
This commit is contained in:
Ahmet Alp Balkan 2018-09-20 10:31:31 -07:00 committed by GitHub
parent 6c37a96f3a
commit 1bab006af1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 116 additions and 260 deletions

View file

@ -28,13 +28,11 @@ spec:
ports: ports:
- containerPort: 5050 - containerPort: 5050
readinessProbe: readinessProbe:
periodSeconds: 5 exec:
tcpSocket: command: ["/bin/grpc_health_probe", "-addr=:5050"]
port: 5050
livenessProbe: livenessProbe:
periodSeconds: 5 exec:
tcpSocket: command: ["/bin/grpc_health_probe", "-addr=:5050"]
port: 5050
env: env:
- name: PRODUCT_CATALOG_SERVICE_ADDR - name: PRODUCT_CATALOG_SERVICE_ADDR
value: "productcatalogservice:3550" value: "productcatalogservice:3550"

View file

@ -29,13 +29,11 @@ spec:
ports: ports:
- containerPort: 3550 - containerPort: 3550
readinessProbe: readinessProbe:
periodSeconds: 5 exec:
tcpSocket: command: ["/bin/grpc_health_probe", "-addr=:3550"]
port: 3550
livenessProbe: livenessProbe:
periodSeconds: 5 exec:
tcpSocket: command: ["/bin/grpc_health_probe", "-addr=:3550"]
port: 3550
resources: resources:
requests: requests:
cpu: 100m cpu: 100m

View file

@ -29,12 +29,11 @@ spec:
- containerPort: 50051 - containerPort: 50051
readinessProbe: readinessProbe:
periodSeconds: 5 periodSeconds: 5
tcpSocket: exec:
port: 50051 command: ["/bin/grpc_health_probe", "-addr=:50051"]
livenessProbe: livenessProbe:
periodSeconds: 5 exec:
tcpSocket: command: ["/bin/grpc_health_probe", "-addr=:50051"]
port: 50051
resources: resources:
requests: requests:
cpu: 100m cpu: 100m

View file

@ -15,6 +15,9 @@ RUN go build -gcflags='-N -l' -o /checkoutservice .
FROM alpine as release FROM alpine as release
RUN apk add --no-cache ca-certificates 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 COPY --from=builder /checkoutservice /checkoutservice
EXPOSE 5050 EXPOSE 5050
ENTRYPOINT ["/checkoutservice"] ENTRYPOINT ["/checkoutservice"]

View file

@ -2,43 +2,27 @@
[[projects]] [[projects]]
digest = "1:467af0aad47996b25b838d6f14c8371123a8a76ec239020a6c5894e1f8f60272"
name = "cloud.google.com/go" name = "cloud.google.com/go"
packages = [ packages = [
"compute/metadata", "compute/metadata",
"internal/version", "internal/version",
"monitoring/apiv3", "monitoring/apiv3",
"profiler", "profiler",
"trace/apiv2", "trace/apiv2"
] ]
pruneopts = "UT"
revision = "c728a003b238b26cef9ab6753a5dc424b331c3ad" revision = "c728a003b238b26cef9ab6753a5dc424b331c3ad"
version = "v0.27.0" version = "v0.27.0"
[[projects]] [[projects]]
digest = "1:9fe70def8f0ceb3d455a0acad9dadd6632287cdbf9c8c2ea50e8dabe2ade40c4"
name = "contrib.go.opencensus.io/exporter/stackdriver" name = "contrib.go.opencensus.io/exporter/stackdriver"
packages = [ packages = [
".", ".",
"propagation", "propagation"
] ]
pruneopts = "UT"
revision = "37aa2801fbf0205003e15636096ebf0373510288" revision = "37aa2801fbf0205003e15636096ebf0373510288"
version = "v0.5.0" version = "v0.5.0"
[[projects]] [[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" name = "github.com/golang/protobuf"
packages = [ packages = [
"proto", "proto",
@ -49,38 +33,30 @@
"ptypes/empty", "ptypes/empty",
"ptypes/struct", "ptypes/struct",
"ptypes/timestamp", "ptypes/timestamp",
"ptypes/wrappers", "ptypes/wrappers"
] ]
pruneopts = "UT"
revision = "aa810b61a9c79d51363740d207bb46cf8e620ed5" revision = "aa810b61a9c79d51363740d207bb46cf8e620ed5"
version = "v1.2.0" version = "v1.2.0"
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:089d56c0adb79140365b5c86815ce97233986da6f3a525c6b706773e4b83876f"
name = "github.com/google/pprof" name = "github.com/google/pprof"
packages = ["profile"] packages = ["profile"]
pruneopts = "UT" revision = "e027b505a088ac3c68c339a1d7ce7724bf34538b"
revision = "84b7d314e22c8d12334e52726f68517973b6027b"
[[projects]] [[projects]]
digest = "1:3a26588bc48b96825977c1b3df964f8fd842cd6860cc26370588d3563433cf11"
name = "github.com/google/uuid" name = "github.com/google/uuid"
packages = ["."] packages = ["."]
pruneopts = "UT"
revision = "d460ce9f8df2e77fb1ba55ca87fafed96c607494" revision = "d460ce9f8df2e77fb1ba55ca87fafed96c607494"
version = "v1.0.0" version = "v1.0.0"
[[projects]] [[projects]]
digest = "1:e145e9710a10bc114a6d3e2738aadf8de146adaa031854ffdf7bbfe15da85e63"
name = "github.com/googleapis/gax-go" name = "github.com/googleapis/gax-go"
packages = ["."] packages = ["."]
pruneopts = "UT"
revision = "317e0006254c44a0ac427cc52a0e083ff0b9622f" revision = "317e0006254c44a0ac427cc52a0e083ff0b9622f"
version = "v2.0.0" version = "v2.0.0"
[[projects]] [[projects]]
digest = "1:1bb914cfb78f68f488a91cd7872d3d06a5f83c5bbacf0296dbef44e120b00a91"
name = "go.opencensus.io" name = "go.opencensus.io"
packages = [ packages = [
".", ".",
@ -96,15 +72,13 @@
"trace", "trace",
"trace/internal", "trace/internal",
"trace/propagation", "trace/propagation",
"trace/tracestate", "trace/tracestate"
] ]
pruneopts = "UT"
revision = "b11f239c032624b045c4c2bfd3d1287b4012ce89" revision = "b11f239c032624b045c4c2bfd3d1287b4012ce89"
version = "v0.16.0" version = "v0.16.0"
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:1c14517b2f106c61d75006199b46a46576058661d469658cb0f90739919641d2"
name = "golang.org/x/net" name = "golang.org/x/net"
packages = [ packages = [
"context", "context",
@ -114,43 +88,35 @@
"http2/hpack", "http2/hpack",
"idna", "idna",
"internal/timeseries", "internal/timeseries",
"trace", "trace"
] ]
pruneopts = "UT"
revision = "26e67e76b6c3f6ce91f7c52def5af501b4e0f3a2" revision = "26e67e76b6c3f6ce91f7c52def5af501b4e0f3a2"
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:f645667d687fc8bf228865a2c5455824ef05bad08841e673673ef2bb89ac5b90"
name = "golang.org/x/oauth2" name = "golang.org/x/oauth2"
packages = [ packages = [
".", ".",
"google", "google",
"internal", "internal",
"jws", "jws",
"jwt", "jwt"
] ]
pruneopts = "UT"
revision = "d2e6202438beef2727060aa7cabdd924d92ebfd9" revision = "d2e6202438beef2727060aa7cabdd924d92ebfd9"
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:e0140c0c868c6e0f01c0380865194592c011fe521d6e12d78bfd33e756fe018a"
name = "golang.org/x/sync" name = "golang.org/x/sync"
packages = ["semaphore"] packages = ["semaphore"]
pruneopts = "UT"
revision = "1d60e4601c6fd243af51cc01ddf169918a5407ca" revision = "1d60e4601c6fd243af51cc01ddf169918a5407ca"
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:6eb2645d74b43d9c87b51947df39f7c668a4f422cd512053f7f6f75bfaad0197"
name = "golang.org/x/sys" name = "golang.org/x/sys"
packages = ["unix"] packages = ["unix"]
pruneopts = "UT" revision = "1561086e645b2809fb9f8a1e2a38160bf8d53bf4"
revision = "d0be0721c37eeb5299f245a996a483160fc36940"
[[projects]] [[projects]]
digest = "1:a2ab62866c75542dd18d2b069fec854577a20211d7c0ea6ae746072a1dccdd18"
name = "golang.org/x/text" name = "golang.org/x/text"
packages = [ packages = [
"collate", "collate",
@ -166,15 +132,13 @@
"unicode/bidi", "unicode/bidi",
"unicode/cldr", "unicode/cldr",
"unicode/norm", "unicode/norm",
"unicode/rangetable", "unicode/rangetable"
] ]
pruneopts = "UT"
revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0"
version = "v0.3.0" version = "v0.3.0"
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:e9e388241f9f0f02000dddaeeb91153d53f0cd09dcec33879cc7e043a2e65d75"
name = "google.golang.org/api" name = "google.golang.org/api"
packages = [ packages = [
"googleapi/transport", "googleapi/transport",
@ -184,13 +148,11 @@
"support/bundler", "support/bundler",
"transport", "transport",
"transport/grpc", "transport/grpc",
"transport/http", "transport/http"
] ]
pruneopts = "UT" revision = "19ff8768a5c0b8e46ea281065664787eefc24121"
revision = "7ca32eb868bf53ea2fc406698eb98583a8073d19"
[[projects]] [[projects]]
digest = "1:26619fcd2452b4044174d26acd8b09c09dffee9a1c3a22d2383b873aa9a0131f"
name = "google.golang.org/appengine" name = "google.golang.org/appengine"
packages = [ packages = [
".", ".",
@ -204,15 +166,13 @@
"internal/socket", "internal/socket",
"internal/urlfetch", "internal/urlfetch",
"socket", "socket",
"urlfetch", "urlfetch"
] ]
pruneopts = "UT" revision = "ae0ab99deb4dc413a2b4bd6c8bdd0eb67f1e4d06"
revision = "b1f26356af11148e710935ed1ac8a7f5702c7612" version = "v1.2.0"
version = "v1.1.0"
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:7a3da01a8f840fbbef1f027dc091ae52a29c6ab9374e126b6bdc5bf3b0ff2687"
name = "google.golang.org/genproto" name = "google.golang.org/genproto"
packages = [ packages = [
"googleapis/api/annotations", "googleapis/api/annotations",
@ -225,13 +185,11 @@
"googleapis/monitoring/v3", "googleapis/monitoring/v3",
"googleapis/rpc/errdetails", "googleapis/rpc/errdetails",
"googleapis/rpc/status", "googleapis/rpc/status",
"protobuf/field_mask", "protobuf/field_mask"
] ]
pruneopts = "UT" revision = "c3f76f3b92d1ffa4c58a9ff842a58b8877655e0f"
revision = "36d5787dc5356b711fe8f3040271aaf51c35955b"
[[projects]] [[projects]]
digest = "1:4ad047d772a7d4841687df9534a767a9e243885ed6d7d2ced6af5995a5dc44b3"
name = "google.golang.org/grpc" name = "google.golang.org/grpc"
packages = [ packages = [
".", ".",
@ -245,6 +203,7 @@
"encoding", "encoding",
"encoding/proto", "encoding/proto",
"grpclog", "grpclog",
"health/grpc_health_v1",
"internal", "internal",
"internal/backoff", "internal/backoff",
"internal/channelz", "internal/channelz",
@ -260,29 +219,14 @@
"resolver/passthrough", "resolver/passthrough",
"stats", "stats",
"status", "status",
"tap", "tap"
] ]
pruneopts = "UT" revision = "32fb0ac620c32ba40a4626ddf94d90d12cce3455"
revision = "8dea3dc473e90c8179e519d91302d0597c0ca1d1" version = "v1.14.0"
version = "v1.15.0"
[solve-meta] [solve-meta]
analyzer-name = "dep" analyzer-name = "dep"
analyzer-version = 1 analyzer-version = 1
input-imports = [ inputs-digest = "0c103e5e32d8ecdd70048b6d91e02b910e30bad54f06b230a9664f585433a669"
"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",
]
solver-name = "gps-cdcl" solver-name = "gps-cdcl"
solver-version = 1 solver-version = 1

View file

@ -33,10 +33,6 @@
name = "contrib.go.opencensus.io/exporter/stackdriver" name = "contrib.go.opencensus.io/exporter/stackdriver"
version = "0.5.0" version = "0.5.0"
[[constraint]]
branch = "master"
name = "github.com/GoogleCloudPlatform/microservices-demo"
[[constraint]] [[constraint]]
name = "github.com/golang/protobuf" name = "github.com/golang/protobuf"
version = "1.2.0" version = "1.2.0"
@ -55,7 +51,7 @@
[[constraint]] [[constraint]]
name = "google.golang.org/grpc" name = "google.golang.org/grpc"
version = "1.15.0" version = "=1.14.0"
[prune] [prune]
go-tests = true go-tests = true

View file

@ -34,6 +34,7 @@ import (
pb "github.com/GoogleCloudPlatform/microservices-demo/src/checkoutservice/genproto" pb "github.com/GoogleCloudPlatform/microservices-demo/src/checkoutservice/genproto"
money "github.com/GoogleCloudPlatform/microservices-demo/src/checkoutservice/money" money "github.com/GoogleCloudPlatform/microservices-demo/src/checkoutservice/money"
healthpb "google.golang.org/grpc/health/grpc_health_v1"
) )
const ( const (
@ -75,6 +76,7 @@ func main() {
} }
srv := grpc.NewServer(grpc.StatsHandler(&ocgrpc.ServerHandler{})) srv := grpc.NewServer(grpc.StatsHandler(&ocgrpc.ServerHandler{}))
pb.RegisterCheckoutServiceServer(srv, svc) pb.RegisterCheckoutServiceServer(srv, svc)
healthpb.RegisterHealthServer(srv, svc)
log.Printf("starting to listen on tcp: %q", lis.Addr().String()) log.Printf("starting to listen on tcp: %q", lis.Addr().String())
log.Fatal(srv.Serve(lis)) log.Fatal(srv.Serve(lis))
} }
@ -141,6 +143,10 @@ func mustMapEnv(target *string, envKey string) {
*target = v *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) { 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) log.Printf("[PlaceOrder] user_id=%q user_currency=%q", req.UserId, req.UserCurrency)

View file

@ -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 && \ 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 && \ wget -qO/go/bin/dep https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 && \
chmod +x /go/bin/dep chmod +x /go/bin/dep
@ -13,8 +13,11 @@ RUN dep ensure --vendor-only -v
COPY . . COPY . .
RUN go build -o /productcatalogservice . RUN go build -o /productcatalogservice .
FROM alpine as release FROM alpine AS release
RUN apk add --no-cache ca-certificates 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 WORKDIR /productcatalogservice
COPY --from=builder /productcatalogservice ./server COPY --from=builder /productcatalogservice ./server
COPY products.json . COPY products.json .

View file

@ -2,40 +2,27 @@
[[projects]] [[projects]]
digest = "1:467af0aad47996b25b838d6f14c8371123a8a76ec239020a6c5894e1f8f60272"
name = "cloud.google.com/go" name = "cloud.google.com/go"
packages = [ packages = [
"compute/metadata", "compute/metadata",
"internal/version", "internal/version",
"monitoring/apiv3", "monitoring/apiv3",
"profiler", "profiler",
"trace/apiv2", "trace/apiv2"
] ]
pruneopts = "UT"
revision = "c728a003b238b26cef9ab6753a5dc424b331c3ad" revision = "c728a003b238b26cef9ab6753a5dc424b331c3ad"
version = "v0.27.0" version = "v0.27.0"
[[projects]] [[projects]]
digest = "1:9fe70def8f0ceb3d455a0acad9dadd6632287cdbf9c8c2ea50e8dabe2ade40c4"
name = "contrib.go.opencensus.io/exporter/stackdriver" name = "contrib.go.opencensus.io/exporter/stackdriver"
packages = [ packages = [
".", ".",
"propagation", "propagation"
] ]
pruneopts = "UT"
revision = "37aa2801fbf0205003e15636096ebf0373510288" revision = "37aa2801fbf0205003e15636096ebf0373510288"
version = "v0.5.0" version = "v0.5.0"
[[projects]] [[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" name = "github.com/golang/protobuf"
packages = [ packages = [
"jsonpb", "jsonpb",
@ -47,43 +34,35 @@
"ptypes/empty", "ptypes/empty",
"ptypes/struct", "ptypes/struct",
"ptypes/timestamp", "ptypes/timestamp",
"ptypes/wrappers", "ptypes/wrappers"
] ]
pruneopts = "UT"
revision = "aa810b61a9c79d51363740d207bb46cf8e620ed5" revision = "aa810b61a9c79d51363740d207bb46cf8e620ed5"
version = "v1.2.0" version = "v1.2.0"
[[projects]] [[projects]]
digest = "1:2e3c336fc7fde5c984d2841455a658a6d626450b1754a854b3b32e7a8f49a07a"
name = "github.com/google/go-cmp" name = "github.com/google/go-cmp"
packages = [ packages = [
"cmp", "cmp",
"cmp/internal/diff", "cmp/internal/diff",
"cmp/internal/function", "cmp/internal/function",
"cmp/internal/value", "cmp/internal/value"
] ]
pruneopts = "UT"
revision = "3af367b6b30c263d47e8895973edcca9a49cf029" revision = "3af367b6b30c263d47e8895973edcca9a49cf029"
version = "v0.2.0" version = "v0.2.0"
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:089d56c0adb79140365b5c86815ce97233986da6f3a525c6b706773e4b83876f"
name = "github.com/google/pprof" name = "github.com/google/pprof"
packages = ["profile"] packages = ["profile"]
pruneopts = "UT" revision = "e027b505a088ac3c68c339a1d7ce7724bf34538b"
revision = "84b7d314e22c8d12334e52726f68517973b6027b"
[[projects]] [[projects]]
digest = "1:e145e9710a10bc114a6d3e2738aadf8de146adaa031854ffdf7bbfe15da85e63"
name = "github.com/googleapis/gax-go" name = "github.com/googleapis/gax-go"
packages = ["."] packages = ["."]
pruneopts = "UT"
revision = "317e0006254c44a0ac427cc52a0e083ff0b9622f" revision = "317e0006254c44a0ac427cc52a0e083ff0b9622f"
version = "v2.0.0" version = "v2.0.0"
[[projects]] [[projects]]
digest = "1:1bb914cfb78f68f488a91cd7872d3d06a5f83c5bbacf0296dbef44e120b00a91"
name = "go.opencensus.io" name = "go.opencensus.io"
packages = [ packages = [
".", ".",
@ -99,15 +78,13 @@
"trace", "trace",
"trace/internal", "trace/internal",
"trace/propagation", "trace/propagation",
"trace/tracestate", "trace/tracestate"
] ]
pruneopts = "UT"
revision = "b11f239c032624b045c4c2bfd3d1287b4012ce89" revision = "b11f239c032624b045c4c2bfd3d1287b4012ce89"
version = "v0.16.0" version = "v0.16.0"
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:1c14517b2f106c61d75006199b46a46576058661d469658cb0f90739919641d2"
name = "golang.org/x/net" name = "golang.org/x/net"
packages = [ packages = [
"context", "context",
@ -117,43 +94,35 @@
"http2/hpack", "http2/hpack",
"idna", "idna",
"internal/timeseries", "internal/timeseries",
"trace", "trace"
] ]
pruneopts = "UT"
revision = "26e67e76b6c3f6ce91f7c52def5af501b4e0f3a2" revision = "26e67e76b6c3f6ce91f7c52def5af501b4e0f3a2"
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:f645667d687fc8bf228865a2c5455824ef05bad08841e673673ef2bb89ac5b90"
name = "golang.org/x/oauth2" name = "golang.org/x/oauth2"
packages = [ packages = [
".", ".",
"google", "google",
"internal", "internal",
"jws", "jws",
"jwt", "jwt"
] ]
pruneopts = "UT"
revision = "d2e6202438beef2727060aa7cabdd924d92ebfd9" revision = "d2e6202438beef2727060aa7cabdd924d92ebfd9"
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:e0140c0c868c6e0f01c0380865194592c011fe521d6e12d78bfd33e756fe018a"
name = "golang.org/x/sync" name = "golang.org/x/sync"
packages = ["semaphore"] packages = ["semaphore"]
pruneopts = "UT"
revision = "1d60e4601c6fd243af51cc01ddf169918a5407ca" revision = "1d60e4601c6fd243af51cc01ddf169918a5407ca"
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:6eb2645d74b43d9c87b51947df39f7c668a4f422cd512053f7f6f75bfaad0197"
name = "golang.org/x/sys" name = "golang.org/x/sys"
packages = ["unix"] packages = ["unix"]
pruneopts = "UT" revision = "1561086e645b2809fb9f8a1e2a38160bf8d53bf4"
revision = "d0be0721c37eeb5299f245a996a483160fc36940"
[[projects]] [[projects]]
digest = "1:a2ab62866c75542dd18d2b069fec854577a20211d7c0ea6ae746072a1dccdd18"
name = "golang.org/x/text" name = "golang.org/x/text"
packages = [ packages = [
"collate", "collate",
@ -169,15 +138,13 @@
"unicode/bidi", "unicode/bidi",
"unicode/cldr", "unicode/cldr",
"unicode/norm", "unicode/norm",
"unicode/rangetable", "unicode/rangetable"
] ]
pruneopts = "UT"
revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0"
version = "v0.3.0" version = "v0.3.0"
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:e9e388241f9f0f02000dddaeeb91153d53f0cd09dcec33879cc7e043a2e65d75"
name = "google.golang.org/api" name = "google.golang.org/api"
packages = [ packages = [
"googleapi/transport", "googleapi/transport",
@ -187,13 +154,11 @@
"support/bundler", "support/bundler",
"transport", "transport",
"transport/grpc", "transport/grpc",
"transport/http", "transport/http"
] ]
pruneopts = "UT" revision = "19ff8768a5c0b8e46ea281065664787eefc24121"
revision = "7ca32eb868bf53ea2fc406698eb98583a8073d19"
[[projects]] [[projects]]
digest = "1:26619fcd2452b4044174d26acd8b09c09dffee9a1c3a22d2383b873aa9a0131f"
name = "google.golang.org/appengine" name = "google.golang.org/appengine"
packages = [ packages = [
".", ".",
@ -207,15 +172,13 @@
"internal/socket", "internal/socket",
"internal/urlfetch", "internal/urlfetch",
"socket", "socket",
"urlfetch", "urlfetch"
] ]
pruneopts = "UT" revision = "ae0ab99deb4dc413a2b4bd6c8bdd0eb67f1e4d06"
revision = "b1f26356af11148e710935ed1ac8a7f5702c7612" version = "v1.2.0"
version = "v1.1.0"
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:7a3da01a8f840fbbef1f027dc091ae52a29c6ab9374e126b6bdc5bf3b0ff2687"
name = "google.golang.org/genproto" name = "google.golang.org/genproto"
packages = [ packages = [
"googleapis/api/annotations", "googleapis/api/annotations",
@ -228,13 +191,11 @@
"googleapis/monitoring/v3", "googleapis/monitoring/v3",
"googleapis/rpc/errdetails", "googleapis/rpc/errdetails",
"googleapis/rpc/status", "googleapis/rpc/status",
"protobuf/field_mask", "protobuf/field_mask"
] ]
pruneopts = "UT" revision = "c3f76f3b92d1ffa4c58a9ff842a58b8877655e0f"
revision = "36d5787dc5356b711fe8f3040271aaf51c35955b"
[[projects]] [[projects]]
digest = "1:4ad047d772a7d4841687df9534a767a9e243885ed6d7d2ced6af5995a5dc44b3"
name = "google.golang.org/grpc" name = "google.golang.org/grpc"
packages = [ packages = [
".", ".",
@ -248,6 +209,7 @@
"encoding", "encoding",
"encoding/proto", "encoding/proto",
"grpclog", "grpclog",
"health/grpc_health_v1",
"internal", "internal",
"internal/backoff", "internal/backoff",
"internal/channelz", "internal/channelz",
@ -263,29 +225,14 @@
"resolver/passthrough", "resolver/passthrough",
"stats", "stats",
"status", "status",
"tap", "tap"
] ]
pruneopts = "UT" revision = "32fb0ac620c32ba40a4626ddf94d90d12cce3455"
revision = "8dea3dc473e90c8179e519d91302d0597c0ca1d1" version = "v1.14.0"
version = "v1.15.0"
[solve-meta] [solve-meta]
analyzer-name = "dep" analyzer-name = "dep"
analyzer-version = 1 analyzer-version = 1
input-imports = [ inputs-digest = "b68fd9438c2eb711d9fc51c1f23c5ca0d5169bf4022351dfc400cd35ba39dfaa"
"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",
]
solver-name = "gps-cdcl" solver-name = "gps-cdcl"
solver-version = 1 solver-version = 1

View file

@ -33,10 +33,6 @@
name = "contrib.go.opencensus.io/exporter/stackdriver" name = "contrib.go.opencensus.io/exporter/stackdriver"
version = "0.5.0" version = "0.5.0"
[[constraint]]
branch = "master"
name = "github.com/GoogleCloudPlatform/microservices-demo"
[[constraint]] [[constraint]]
name = "github.com/golang/protobuf" name = "github.com/golang/protobuf"
version = "1.2.0" version = "1.2.0"
@ -55,7 +51,7 @@
[[constraint]] [[constraint]]
name = "google.golang.org/grpc" name = "google.golang.org/grpc"
version = "1.15.0" version = "=1.14.0"
[prune] [prune]
go-tests = true go-tests = true

View file

@ -26,6 +26,7 @@ import (
"time" "time"
pb "github.com/GoogleCloudPlatform/microservices-demo/src/productcatalogservice/genproto" pb "github.com/GoogleCloudPlatform/microservices-demo/src/productcatalogservice/genproto"
healthpb "google.golang.org/grpc/health/grpc_health_v1"
"cloud.google.com/go/profiler" "cloud.google.com/go/profiler"
"contrib.go.opencensus.io/exporter/stackdriver" "contrib.go.opencensus.io/exporter/stackdriver"
@ -69,7 +70,9 @@ func run(port int) string {
log.Fatal(err) log.Fatal(err)
} }
srv := grpc.NewServer(grpc.StatsHandler(&ocgrpc.ServerHandler{})) 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) go srv.Serve(l)
return l.Addr().String() return l.Addr().String()
} }
@ -140,6 +143,10 @@ func parseCatalog() []*pb.Product {
return cat.Products 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) { func (p *productCatalog) ListProducts(context.Context, *pb.Empty) (*pb.ListProductsResponse, error) {
return &pb.ListProductsResponse{Products: parseCatalog()}, nil return &pb.ListProductsResponse{Products: parseCatalog()}, nil
} }

View file

@ -14,6 +14,9 @@ RUN go install .
FROM alpine as release FROM alpine as release
RUN apk add --no-cache ca-certificates 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 COPY --from=builder /go/bin/shippingservice /shippingservice
ENV APP_PORT=50051 ENV APP_PORT=50051
EXPOSE 50051 EXPOSE 50051

View file

@ -2,40 +2,27 @@
[[projects]] [[projects]]
digest = "1:467af0aad47996b25b838d6f14c8371123a8a76ec239020a6c5894e1f8f60272"
name = "cloud.google.com/go" name = "cloud.google.com/go"
packages = [ packages = [
"compute/metadata", "compute/metadata",
"internal/version", "internal/version",
"monitoring/apiv3", "monitoring/apiv3",
"profiler", "profiler",
"trace/apiv2", "trace/apiv2"
] ]
pruneopts = "UT"
revision = "c728a003b238b26cef9ab6753a5dc424b331c3ad" revision = "c728a003b238b26cef9ab6753a5dc424b331c3ad"
version = "v0.27.0" version = "v0.27.0"
[[projects]] [[projects]]
digest = "1:9fe70def8f0ceb3d455a0acad9dadd6632287cdbf9c8c2ea50e8dabe2ade40c4"
name = "contrib.go.opencensus.io/exporter/stackdriver" name = "contrib.go.opencensus.io/exporter/stackdriver"
packages = [ packages = [
".", ".",
"propagation", "propagation"
] ]
pruneopts = "UT"
revision = "37aa2801fbf0205003e15636096ebf0373510288" revision = "37aa2801fbf0205003e15636096ebf0373510288"
version = "v0.5.0" version = "v0.5.0"
[[projects]] [[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" name = "github.com/golang/protobuf"
packages = [ packages = [
"proto", "proto",
@ -46,30 +33,24 @@
"ptypes/empty", "ptypes/empty",
"ptypes/struct", "ptypes/struct",
"ptypes/timestamp", "ptypes/timestamp",
"ptypes/wrappers", "ptypes/wrappers"
] ]
pruneopts = "UT"
revision = "aa810b61a9c79d51363740d207bb46cf8e620ed5" revision = "aa810b61a9c79d51363740d207bb46cf8e620ed5"
version = "v1.2.0" version = "v1.2.0"
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:089d56c0adb79140365b5c86815ce97233986da6f3a525c6b706773e4b83876f"
name = "github.com/google/pprof" name = "github.com/google/pprof"
packages = ["profile"] packages = ["profile"]
pruneopts = "UT" revision = "e027b505a088ac3c68c339a1d7ce7724bf34538b"
revision = "84b7d314e22c8d12334e52726f68517973b6027b"
[[projects]] [[projects]]
digest = "1:e145e9710a10bc114a6d3e2738aadf8de146adaa031854ffdf7bbfe15da85e63"
name = "github.com/googleapis/gax-go" name = "github.com/googleapis/gax-go"
packages = ["."] packages = ["."]
pruneopts = "UT"
revision = "317e0006254c44a0ac427cc52a0e083ff0b9622f" revision = "317e0006254c44a0ac427cc52a0e083ff0b9622f"
version = "v2.0.0" version = "v2.0.0"
[[projects]] [[projects]]
digest = "1:1bb914cfb78f68f488a91cd7872d3d06a5f83c5bbacf0296dbef44e120b00a91"
name = "go.opencensus.io" name = "go.opencensus.io"
packages = [ packages = [
".", ".",
@ -85,15 +66,13 @@
"trace", "trace",
"trace/internal", "trace/internal",
"trace/propagation", "trace/propagation",
"trace/tracestate", "trace/tracestate"
] ]
pruneopts = "UT"
revision = "b11f239c032624b045c4c2bfd3d1287b4012ce89" revision = "b11f239c032624b045c4c2bfd3d1287b4012ce89"
version = "v0.16.0" version = "v0.16.0"
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:1c14517b2f106c61d75006199b46a46576058661d469658cb0f90739919641d2"
name = "golang.org/x/net" name = "golang.org/x/net"
packages = [ packages = [
"context", "context",
@ -103,43 +82,35 @@
"http2/hpack", "http2/hpack",
"idna", "idna",
"internal/timeseries", "internal/timeseries",
"trace", "trace"
] ]
pruneopts = "UT"
revision = "26e67e76b6c3f6ce91f7c52def5af501b4e0f3a2" revision = "26e67e76b6c3f6ce91f7c52def5af501b4e0f3a2"
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:f645667d687fc8bf228865a2c5455824ef05bad08841e673673ef2bb89ac5b90"
name = "golang.org/x/oauth2" name = "golang.org/x/oauth2"
packages = [ packages = [
".", ".",
"google", "google",
"internal", "internal",
"jws", "jws",
"jwt", "jwt"
] ]
pruneopts = "UT"
revision = "d2e6202438beef2727060aa7cabdd924d92ebfd9" revision = "d2e6202438beef2727060aa7cabdd924d92ebfd9"
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:e0140c0c868c6e0f01c0380865194592c011fe521d6e12d78bfd33e756fe018a"
name = "golang.org/x/sync" name = "golang.org/x/sync"
packages = ["semaphore"] packages = ["semaphore"]
pruneopts = "UT"
revision = "1d60e4601c6fd243af51cc01ddf169918a5407ca" revision = "1d60e4601c6fd243af51cc01ddf169918a5407ca"
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:6eb2645d74b43d9c87b51947df39f7c668a4f422cd512053f7f6f75bfaad0197"
name = "golang.org/x/sys" name = "golang.org/x/sys"
packages = ["unix"] packages = ["unix"]
pruneopts = "UT" revision = "1561086e645b2809fb9f8a1e2a38160bf8d53bf4"
revision = "d0be0721c37eeb5299f245a996a483160fc36940"
[[projects]] [[projects]]
digest = "1:a2ab62866c75542dd18d2b069fec854577a20211d7c0ea6ae746072a1dccdd18"
name = "golang.org/x/text" name = "golang.org/x/text"
packages = [ packages = [
"collate", "collate",
@ -155,15 +126,13 @@
"unicode/bidi", "unicode/bidi",
"unicode/cldr", "unicode/cldr",
"unicode/norm", "unicode/norm",
"unicode/rangetable", "unicode/rangetable"
] ]
pruneopts = "UT"
revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0"
version = "v0.3.0" version = "v0.3.0"
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:e9e388241f9f0f02000dddaeeb91153d53f0cd09dcec33879cc7e043a2e65d75"
name = "google.golang.org/api" name = "google.golang.org/api"
packages = [ packages = [
"googleapi/transport", "googleapi/transport",
@ -173,13 +142,11 @@
"support/bundler", "support/bundler",
"transport", "transport",
"transport/grpc", "transport/grpc",
"transport/http", "transport/http"
] ]
pruneopts = "UT" revision = "19ff8768a5c0b8e46ea281065664787eefc24121"
revision = "7ca32eb868bf53ea2fc406698eb98583a8073d19"
[[projects]] [[projects]]
digest = "1:26619fcd2452b4044174d26acd8b09c09dffee9a1c3a22d2383b873aa9a0131f"
name = "google.golang.org/appengine" name = "google.golang.org/appengine"
packages = [ packages = [
".", ".",
@ -193,15 +160,13 @@
"internal/socket", "internal/socket",
"internal/urlfetch", "internal/urlfetch",
"socket", "socket",
"urlfetch", "urlfetch"
] ]
pruneopts = "UT" revision = "ae0ab99deb4dc413a2b4bd6c8bdd0eb67f1e4d06"
revision = "b1f26356af11148e710935ed1ac8a7f5702c7612" version = "v1.2.0"
version = "v1.1.0"
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:7a3da01a8f840fbbef1f027dc091ae52a29c6ab9374e126b6bdc5bf3b0ff2687"
name = "google.golang.org/genproto" name = "google.golang.org/genproto"
packages = [ packages = [
"googleapis/api/annotations", "googleapis/api/annotations",
@ -214,13 +179,11 @@
"googleapis/monitoring/v3", "googleapis/monitoring/v3",
"googleapis/rpc/errdetails", "googleapis/rpc/errdetails",
"googleapis/rpc/status", "googleapis/rpc/status",
"protobuf/field_mask", "protobuf/field_mask"
] ]
pruneopts = "UT" revision = "c3f76f3b92d1ffa4c58a9ff842a58b8877655e0f"
revision = "36d5787dc5356b711fe8f3040271aaf51c35955b"
[[projects]] [[projects]]
digest = "1:97c4b6de720998595a38558d26277cffc14290a7f60ae2cf6f077a300c50ed17"
name = "google.golang.org/grpc" name = "google.golang.org/grpc"
packages = [ packages = [
".", ".",
@ -234,6 +197,7 @@
"encoding", "encoding",
"encoding/proto", "encoding/proto",
"grpclog", "grpclog",
"health/grpc_health_v1",
"internal", "internal",
"internal/backoff", "internal/backoff",
"internal/channelz", "internal/channelz",
@ -251,26 +215,14 @@
"resolver/passthrough", "resolver/passthrough",
"stats", "stats",
"status", "status",
"tap", "tap"
] ]
pruneopts = "UT" revision = "32fb0ac620c32ba40a4626ddf94d90d12cce3455"
revision = "8dea3dc473e90c8179e519d91302d0597c0ca1d1" version = "v1.14.0"
version = "v1.15.0"
[solve-meta] [solve-meta]
analyzer-name = "dep" analyzer-name = "dep"
analyzer-version = 1 analyzer-version = 1
input-imports = [ inputs-digest = "5dac84cd5efcc89491aa3cda06a774c1b370c8e0cbdb99668cbfd8ba27b3e32c"
"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",
]
solver-name = "gps-cdcl" solver-name = "gps-cdcl"
solver-version = 1 solver-version = 1

View file

@ -33,10 +33,6 @@
name = "contrib.go.opencensus.io/exporter/stackdriver" name = "contrib.go.opencensus.io/exporter/stackdriver"
version = "0.5.0" version = "0.5.0"
[[constraint]]
branch = "master"
name = "github.com/GoogleCloudPlatform/microservices-demo"
[[constraint]] [[constraint]]
name = "github.com/golang/protobuf" name = "github.com/golang/protobuf"
version = "1.2.0" version = "1.2.0"
@ -51,7 +47,7 @@
[[constraint]] [[constraint]]
name = "google.golang.org/grpc" name = "google.golang.org/grpc"
version = "1.15.0" version = "=1.14.0"
[prune] [prune]
go-tests = true go-tests = true

View file

@ -31,6 +31,7 @@ import (
"google.golang.org/grpc/reflection" "google.golang.org/grpc/reflection"
pb "github.com/GoogleCloudPlatform/microservices-demo/src/shippingservice/genproto" pb "github.com/GoogleCloudPlatform/microservices-demo/src/shippingservice/genproto"
healthpb "google.golang.org/grpc/health/grpc_health_v1"
) )
const ( const (
@ -51,13 +52,15 @@ func main() {
if err != nil { if err != nil {
log.Fatalf("failed to listen: %v", err) log.Fatalf("failed to listen: %v", err)
} }
s := grpc.NewServer(grpc.StatsHandler(&ocgrpc.ServerHandler{})) srv := grpc.NewServer(grpc.StatsHandler(&ocgrpc.ServerHandler{}))
pb.RegisterShippingServiceServer(s, &server{}) svc := &server{}
pb.RegisterShippingServiceServer(srv, svc)
healthpb.RegisterHealthServer(srv, svc)
log.Printf("Shipping Service listening on port %s", port) log.Printf("Shipping Service listening on port %s", port)
// Register reflection service on gRPC server. // Register reflection service on gRPC server.
reflection.Register(s) reflection.Register(srv)
if err := s.Serve(lis); err != nil { if err := srv.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err) log.Fatalf("failed to serve: %v", err)
} }
} }
@ -65,6 +68,11 @@ func main() {
// server controls RPC service responses. // server controls RPC service responses.
type server struct{} 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. // GetQuote produces a shipping quote (cost) in USD.
func (s *server) GetQuote(ctx context.Context, in *pb.GetQuoteRequest) (*pb.GetQuoteResponse, error) { func (s *server) GetQuote(ctx context.Context, in *pb.GetQuoteRequest) (*pb.GetQuoteResponse, error) {
log.Printf("[GetQuote] received request") log.Printf("[GetQuote] received request")