Skip to content

Commit

Permalink
Merge pull request #9 from msfidelis/grpc_healthcheck
Browse files Browse the repository at this point in the history
feature(grpc): healthcheck path for gRPC Services
  • Loading branch information
msfidelis authored Jul 9, 2024
2 parents f205945 + 5e41c4b commit 7e92406
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 0 deletions.
17 changes: 17 additions & 0 deletions bmr-grpc-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"bmr-grpc-service/proto/bmr/service/bmr"
"context"
"net"
"net/http"
"os"

"github.com/rs/zerolog"
Expand Down Expand Up @@ -39,6 +40,9 @@ func main() {
Msg("Failed to listen")
}

// Healthcheck Probe :8080
go startHTTPHealthCheckServer()

logInternal.Info().
Msg("Listener for bmr-grpc-service is created")

Expand All @@ -60,3 +64,16 @@ func main() {
Msg("Server bmr-grpc-service is enabled")

}

func startHTTPHealthCheckServer() {
logInternal := logger.Instance()
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok"))
})

logInternal.Info().Msg("Starting HTTP healthcheck server on :8080")
if err := http.ListenAndServe(":8080", nil); err != nil {
logInternal.Fatal().Err(err).Msg("Failed to start HTTP healthcheck server")
}
}
17 changes: 17 additions & 0 deletions calories-grpc-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"calories-grpc-service/proto/calories/service/calories"
"context"
"net"
"net/http"
"os"

"github.com/rs/zerolog"
Expand Down Expand Up @@ -40,6 +41,9 @@ func main() {
Msg("Failed to listen")
}

// Healthcheck Probe :8080
go startHTTPHealthCheckServer()

logInternal.Info().
Msg("Listener for calories-grpc-service is created")

Expand All @@ -61,3 +65,16 @@ func main() {
Msg("Server calories-grpc-service is enabled")

}

func startHTTPHealthCheckServer() {
logInternal := logger.Instance()
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok"))
})

logInternal.Info().Msg("Starting HTTP healthcheck server on :8080")
if err := http.ListenAndServe(":8080", nil); err != nil {
logInternal.Fatal().Err(err).Msg("Failed to start HTTP healthcheck server")
}
}
17 changes: 17 additions & 0 deletions database-store-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"database-store-service/pkg/logger"
"fmt"
"net/http"
"os"
"sync"

Expand All @@ -16,6 +17,9 @@ func main() {
wg := sync.WaitGroup{}
wg.Add(10)

// Healthcheck Probe :8080
go startHTTPHealthCheckServer()

// Nats Client
nc, err := nats.Connect(os.Getenv("NATS_URI"))
defer nc.Close()
Expand Down Expand Up @@ -62,3 +66,16 @@ func main() {
wg.Wait()

}

func startHTTPHealthCheckServer() {
logInternal := logger.Instance()
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok"))
})

logInternal.Info().Msg("Starting HTTP healthcheck server on :8080")
if err := http.ListenAndServe(":8080", nil); err != nil {
logInternal.Fatal().Err(err).Msg("Failed to start HTTP healthcheck server")
}
}
16 changes: 16 additions & 0 deletions imc-grpc-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"imc-grpc-service/pkg/tracer"
"imc-grpc-service/proto/imc/service/imc"
"net"
"net/http"
"os"

"github.com/rs/zerolog"
Expand Down Expand Up @@ -40,6 +41,9 @@ func main() {
Msg("Failed to listen")
}

// Healthcheck Probe :8080
go startHTTPHealthCheckServer()

logInternal.Info().
Msg("Listener for imc-grpc-service is created")

Expand All @@ -59,5 +63,17 @@ func main() {

logInternal.Info().
Msg("Server imc-grpc-service is enabled")
}

func startHTTPHealthCheckServer() {
logInternal := logger.Instance()
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok"))
})

logInternal.Info().Msg("Starting HTTP healthcheck server on :8080")
if err := http.ListenAndServe(":8080", nil); err != nil {
logInternal.Fatal().Err(err).Msg("Failed to start HTTP healthcheck server")
}
}
17 changes: 17 additions & 0 deletions proteins-grpc-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"net"
"net/http"
"os"
"proteins-grpc-service/pkg/logger"
"proteins-grpc-service/pkg/tracer"
Expand Down Expand Up @@ -40,6 +41,9 @@ func main() {
Msg("Failed to listen")
}

// Healthcheck Probe :8080
go startHTTPHealthCheckServer()

logInternal.Info().
Msg("Listener for proteins-grpc-service is created")

Expand All @@ -61,3 +65,16 @@ func main() {
Msg("Server proteins-grpc-service is enabled")

}

func startHTTPHealthCheckServer() {
logInternal := logger.Instance()
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok"))
})

logInternal.Info().Msg("Starting HTTP healthcheck server on :8080")
if err := http.ListenAndServe(":8080", nil); err != nil {
logInternal.Fatal().Err(err).Msg("Failed to start HTTP healthcheck server")
}
}
17 changes: 17 additions & 0 deletions recommendations-grpc-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"net"
"net/http"
"os"
"recommendations-grpc-service/pkg/logger"
"recommendations-grpc-service/pkg/tracer"
Expand Down Expand Up @@ -40,6 +41,9 @@ func main() {
Msg("Failed to listen")
}

// Healthcheck Probe :8080
go startHTTPHealthCheckServer()

logInternal.Info().
Msg("Listener for recommendations-grpc-service is created")

Expand All @@ -61,3 +65,16 @@ func main() {
Msg("Server recommendations-grpc-service is enabled")

}

func startHTTPHealthCheckServer() {
logInternal := logger.Instance()
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok"))
})

logInternal.Info().Msg("Starting HTTP healthcheck server on :8080")
if err := http.ListenAndServe(":8080", nil); err != nil {
logInternal.Fatal().Err(err).Msg("Failed to start HTTP healthcheck server")
}
}
17 changes: 17 additions & 0 deletions water-grpc-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"net"
"net/http"
"os"
"water-grpc-service/pkg/logger"
"water-grpc-service/pkg/tracer"
Expand Down Expand Up @@ -40,6 +41,9 @@ func main() {
Msg("Failed to listen")
}

// Healthcheck Probe :8080
go startHTTPHealthCheckServer()

logInternal.Info().
Msg("Listener for water-grpc-service is created")

Expand All @@ -61,3 +65,16 @@ func main() {
Msg("Server water-grpc-service is enabled")

}

func startHTTPHealthCheckServer() {
logInternal := logger.Instance()
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok"))
})

logInternal.Info().Msg("Starting HTTP healthcheck server on :8080")
if err := http.ListenAndServe(":8080", nil); err != nil {
logInternal.Fatal().Err(err).Msg("Failed to start HTTP healthcheck server")
}
}

0 comments on commit 7e92406

Please sign in to comment.