Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/webserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ func main() {
recvSignal := <-sig
l.Logger.Info().Str("received_signal", recvSignal.String()).Msg("Performing a graceful shutdown")

pprofServer.Shutdown(ctx)
httpServer.Shutdown(ctx)
pprofServer.Stop(ctx)

l.Logger.Info().Msgf("Service %s exiting", serviceName)
}
3 changes: 2 additions & 1 deletion pkg/profiling/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func NewPprofServer() *PprofServer {
listenAddress := net.JoinHostPort(hostname, port)
return &PprofServer{
listenAddr: listenAddress,
once: &sync.Once{},
server: &http.Server{
Addr: listenAddress,
Handler: http.DefaultServeMux,
Expand All @@ -45,7 +46,7 @@ func (p *PprofServer) Start() {
}()
}

func (p *PprofServer) Stop(ctx context.Context) {
func (p *PprofServer) Shutdown(ctx context.Context) {
p.once.Do(func() {
cCtx, cancel := context.WithTimeoutCause(
ctx,
Expand Down
17 changes: 12 additions & 5 deletions pkg/tracer/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"net"
"sync"
"time"

l "weezel/example-gin/pkg/logger"

Expand Down Expand Up @@ -59,6 +60,7 @@ func NewOtelTracerMetrics(
serviceName: serviceName,
res: res,
modes: modes,
closeOnce: &sync.Once{},
}

otelTracerMetrics.connection, err = grpc.NewClient(
Expand Down Expand Up @@ -98,14 +100,19 @@ func (o *OtelTracerMetrics) Close(ctx context.Context) {
var connErr error
var tracerErr error
var metricsErr error
if o.connection != nil {
connErr = o.connection.Close()
}

timeout := 4 * time.Second
cCtx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()

if o.tracer != nil {
tracerErr = o.tracer.Shutdown(ctx)
tracerErr = o.tracer.Shutdown(cCtx)
}
if o.metrics != nil {
metricsErr = o.metrics.Shutdown(ctx)
metricsErr = o.metrics.Shutdown(cCtx)
}
if o.connection != nil {
connErr = o.connection.Close()
}
errs := errors.Join(connErr, tracerErr, metricsErr)
if errs != nil {
Expand Down