Skip to content

Commit

Permalink
feat: add healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
stillmatic committed Jun 30, 2023
1 parent e143917 commit 33d4984
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
client_secret.json
.env

# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
Expand Down
12 changes: 10 additions & 2 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"golang.org/x/oauth2/google"
"gopkg.in/Iwark/spreadsheet.v2"

grpchealth "github.com/bufbuild/connect-grpchealth-go"
"github.com/stillmatic/featuresheet"
fsv1 "github.com/stillmatic/featuresheet/gen/featuresheet/v1"
"github.com/stillmatic/featuresheet/gen/featuresheet/v1/featuresheetv1connect"
Expand Down Expand Up @@ -47,6 +48,9 @@ func (s *FeatureSheetServer) Evaluate(

func main() {
// copy these from client_secret.json
if os.Getenv("GCP_PROJECT_ID") == "" {
panic("GCP_PROJECT_ID env var must be set")
}
serviceAccountJSON := map[string]interface{}{
"type": "service_account",
"project_id": os.Getenv("GCP_PROJECT_ID"),
Expand All @@ -59,12 +63,10 @@ func main() {
"auth_provider_x509_cert_url": os.Getenv("GCP_AUTH_PROVIDER_CERT_URL"),
"client_x509_cert_url": os.Getenv("GCP_CLIENT_CERT_URL"),
}

serviceAccountJSONBytes, err := json.Marshal(serviceAccountJSON)
if err != nil {
panic(err)
}

conf, err := google.JWTConfigFromJSON(serviceAccountJSONBytes, spreadsheet.Scope)
if err != nil {
panic(err)
Expand All @@ -80,12 +82,18 @@ func main() {
if err != nil {
panic(err)
}

// serving
s := &FeatureSheetServer{
fs: fs,
}
mux := http.NewServeMux()
path, handler := featuresheetv1connect.NewFeatureSheetServiceHandler(s)
mux.Handle(path, handler)
checker := grpchealth.NewStaticChecker(
"featuresheet.v1.FeatureSheetService",
)
mux.Handle(grpchealth.NewHandler(checker))
portNum := os.Getenv("PORT")
if portNum == "" {
portNum = "8080"
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
require (
cloud.google.com/go/compute/metadata v0.2.0 // indirect
github.com/bufbuild/connect-go v1.9.0 // indirect
github.com/bufbuild/connect-grpchealth-go v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ cloud.google.com/go/compute/metadata v0.2.0 h1:nBbNSZyDpkNlo3DepaaLKVuO7ClyifSAm
cloud.google.com/go/compute/metadata v0.2.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k=
github.com/bufbuild/connect-go v1.9.0 h1:JIgAeNuFpo+SUPfU19Yt5TcWlznsN5Bv10/gI/6Pjoc=
github.com/bufbuild/connect-go v1.9.0/go.mod h1:CAIePUgkDR5pAFaylSMtNK45ANQjp9JvpluG20rhpV8=
github.com/bufbuild/connect-grpchealth-go v1.1.1 h1:ldceS3m7+Qvl3GI4yzB4oCg3uOdD+Y1bytc/5xuMpqo=
github.com/bufbuild/connect-grpchealth-go v1.1.1/go.mod h1:9KbkogLoUIxOTPKyWDv5evkawr1IYXaHax4XoUHCgoQ=
github.com/datadog/mmh3 v0.0.0-20210722141835-012dc69a9e49 h1:9ppqviquwkVpmVM19utHENs1+Ugp4odEBUbFsqP2f/M=
github.com/datadog/mmh3 v0.0.0-20210722141835-012dc69a9e49/go.mod h1:NoK5OFSzgNJ9DLcHQ3hhbZKeJZioh9B8G59FOAlytYU=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down

0 comments on commit 33d4984

Please sign in to comment.