cartservice: add an exec probe written in Go
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
parent
420a074091
commit
0c1068aec6
5 changed files with 2276 additions and 0 deletions
|
@ -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 . .
|
||||
|
|
4
src/cartservice/probe/README.md
Normal file
4
src/cartservice/probe/README.md
Normal 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.
|
6
src/cartservice/probe/genproto.sh
Executable file
6
src/cartservice/probe/genproto.sh
Executable 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
|
2221
src/cartservice/probe/genproto/demo.pb.go
Normal file
2221
src/cartservice/probe/genproto/demo.pb.go
Normal file
File diff suppressed because it is too large
Load diff
36
src/cartservice/probe/main.go
Normal file
36
src/cartservice/probe/main.go
Normal 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")
|
||||
}
|
Loading…
Reference in a new issue