Skip to content

Commit

Permalink
chore: Switch to new pprof configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <bob@vibioh.fr>
  • Loading branch information
ViBiOh committed May 4, 2024
1 parent 86026d8 commit f695b71
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 19 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Usage of api:
--okStatus int [http] Healthy HTTP Status code ${API_OK_STATUS} (default 204)
--port uint [server] Listen port (0 to disable) ${API_PORT} (default 1080)
--pprofAgent string [pprof] URL of the Datadog Trace Agent (e.g. http://datadog.observability:8126) ${API_PPROF_AGENT}
--pprofPort int [pprof] Port of the HTTP server (0 to disable) ${API_PPROF_PORT} (default 0)
--readTimeout duration [server] Read Timeout ${API_READ_TIMEOUT} (default 5s)
--shutdownTimeout duration [server] Shutdown Timeout ${API_SHUTDOWN_TIMEOUT} (default 10s)
--telemetryRate string [telemetry] OpenTelemetry sample rate, 'always', 'never' or a float value ${API_TELEMETRY_RATE} (default "always")
Expand Down
19 changes: 5 additions & 14 deletions cmd/goweb/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ package main

import (
"context"
"fmt"
"net/http"

_ "net/http/pprof"

"github.com/ViBiOh/httputils/v4/pkg/alcotest"
"github.com/ViBiOh/httputils/v4/pkg/cors"
Expand All @@ -20,24 +16,19 @@ func main() {
config := newConfig()
alcotest.DoAndExit(config.alcotest)

go func() {
fmt.Println(http.ListenAndServe("localhost:9999", http.DefaultServeMux))
}()

ctx := context.Background()

client, err := newClient(ctx, config)
clients, err := newClient(ctx, config)
logger.FatalfOnErr(ctx, err, "client")

defer client.Close(ctx)
defer clients.Close(ctx)
go clients.Start()

appServer := server.New(config.appServer)

go client.pprof.Start(client.health.DoneCtx())

go appServer.Start(client.health.EndCtx(), httputils.Handler(newPort(config, client), client.health, recoverer.Middleware, client.telemetry.Middleware("http"), owasp.New(config.owasp).Middleware, cors.New(config.cors).Middleware))
go appServer.Start(clients.health.EndCtx(), httputils.Handler(newPort(config, clients), clients.health, recoverer.Middleware, clients.telemetry.Middleware("http"), owasp.New(config.owasp).Middleware, cors.New(config.cors).Middleware))

client.health.WaitForTermination(appServer.Done())
clients.health.WaitForTermination(appServer.Done())

server.GracefulWait(appServer.Done())
}
4 changes: 4 additions & 0 deletions cmd/goweb/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func newClient(ctx context.Context, config configuration) (client, error) {
return output, nil
}

func (c client) Start() {
go c.pprof.Start(c.health.DoneCtx())
}

func (c client) Close(ctx context.Context) {
c.telemetry.Close(ctx)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.22.0

require (
github.com/ViBiOh/flags v1.5.0
github.com/ViBiOh/httputils/v4 v4.75.1
github.com/ViBiOh/httputils/v4 v4.75.3
go.opentelemetry.io/otel/metric v1.26.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/ViBiOh/flags v1.5.0 h1:nwuFS8tAwtV6rTPpv2pCB+r12WjZYLjluW7yT+SeVpQ=
github.com/ViBiOh/flags v1.5.0/go.mod h1:39UMuTnKsIp6walgD8dK99KRCb4DJt9vPtbWehHh1T0=
github.com/ViBiOh/httputils/v4 v4.75.1 h1:HPQ9zzs9qaNaXz7sbmqFFp+PQthnwHXElfI3Ii1JCB0=
github.com/ViBiOh/httputils/v4 v4.75.1/go.mod h1:hjrxCv58B8RFGgGNjIOBXqnzoYL7De2IjC2AIMsRKWU=
github.com/ViBiOh/httputils/v4 v4.75.3 h1:+weNBuOx5ApBZXZ/Ku5cVwfedThrvBh7ZpzV5lTDeHQ=
github.com/ViBiOh/httputils/v4 v4.75.3/go.mod h1:hjrxCv58B8RFGgGNjIOBXqnzoYL7De2IjC2AIMsRKWU=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
Expand Down
2 changes: 0 additions & 2 deletions infra/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,5 @@ spec:
API_PPROF_AGENT: http://datadog.observability:8126
API_TELEMETRY_URL: datadog.observability:4317
OTEL_RESOURCE_ATTRIBUTES: env=production,git.repository_url=github.com/ViBiOh/goweb
pprof:
enabled: true
autoscaling:
enabled: false

0 comments on commit f695b71

Please sign in to comment.