cartservice: add an exec probe written in Go

Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
Ahmet Alp Balkan 2018-07-07 16:56:52 -07:00
parent 420a074091
commit 0c1068aec6
5 changed files with 2276 additions and 0 deletions

View File

@ -1,4 +1,13 @@
# cartservice_probe
FROM golang:1.10 as builder
WORKDIR /src/microservices-demo/cartservice/probe
COPY probe/ .
RUN go get -d ./...
RUN go build -o /cartservice_probe .
# cartservice
FROM gcr.io/google-appengine/aspnetcore:2.1.0
COPY --from=builder /cartservice_probe /cartservice_probe
RUN apt update && apt install net-tools telnet
WORKDIR /app
COPY . .

View File

@ -0,0 +1,4 @@
# cartservice Probe
This probe makes a call to the cartservice over localhost and exits to verify
liveness of the cartservice.

View File

@ -0,0 +1,6 @@
#!/bin/bash -e
PATH=$PATH:$GOPATH/bin
protodir=../../../pb
protoc --go_out=plugins=grpc:genproto -I $protodir $protodir/demo.proto

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,36 @@
package main
import (
"context"
"log"
"os"
"time"
pb "./genproto"
"google.golang.org/grpc"
)
func main() {
port := os.Getenv("PORT")
if port == "" {
log.Fatal("probe is executed without PORT env var")
}
log.Printf("probe executing on port %q", port)
conn, err := grpc.DialContext(context.TODO(),
"localhost:"+port,
grpc.WithInsecure(),
grpc.WithBlock(),
grpc.WithTimeout(time.Second*1))
if err != nil {
log.Fatalf("probe failed: failed to connect: %+v", err)
}
defer conn.Close()
if _, err := pb.NewCartServiceClient(conn).GetCart(context.TODO(),
&pb.GetCartRequest{UserId: "exec-probe-nonexistinguser"}); err != nil {
log.Fatalf("probe failed: failed to query: %+v", err)
}
log.Println("probe successful")
}