Skip to content

Commit

Permalink
Enable profiling (http/pprof)
Browse files Browse the repository at this point in the history
- create debug routes behind *admin* authentication
  • Loading branch information
fridim committed Oct 21, 2024
1 parent 7279616 commit f6e420d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
28 changes: 23 additions & 5 deletions cmd/sandbox-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@ import (
_ "embed"
"log/slog"
"net/http"
"net/http/pprof"
"os"
"strings"
"time"

"github.com/rhpds/sandbox/internal/config"
sandboxdb "github.com/rhpds/sandbox/internal/dynamodb"
"github.com/rhpds/sandbox/internal/log"
"github.com/rhpds/sandbox/internal/models"

"github.com/getkin/kin-openapi/openapi3"
gorillamux "github.com/getkin/kin-openapi/routers/gorillamux"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/go-chi/httplog/v2"
"github.com/go-chi/jwtauth/v5"
"github.com/jackc/pgx/v4/pgxpool"

"github.com/rhpds/sandbox/internal/config"
sandboxdb "github.com/rhpds/sandbox/internal/dynamodb"
"github.com/rhpds/sandbox/internal/log"
"github.com/rhpds/sandbox/internal/models"
)

//go:embed assets/swagger.yaml
Expand Down Expand Up @@ -279,6 +280,23 @@ func main() {
r.Delete("/api/v1/reservations/{name}", baseHandler.DeleteReservationHandler)
})

// ---------------------------------------------------------------------
// Profiling
// ---------------------------------------------------------------------
router.Group(func(r chi.Router) {
// ---------------------------------
// Admin auth but no OpenAPI validation
// ---------------------------------
r.Use(jwtauth.Verifier(tokenAuth))
r.Use(AuthenticatorAdmin)
// Profiling
r.Get("/debug/pprof/", pprof.Index)
r.Get("/debug/pprof/profile", pprof.Profile)
r.Get("/debug/pprof/trace", pprof.Trace)
r.Get("/debug/pprof/cmdline", pprof.Cmdline)
r.Get("/debug/pprof/symbol", pprof.Symbol)
})

// ---------------------------------------------------------------------
// Login Routes
// ---------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion tests/001.hurl
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ jsonpath "$.reservation.status" == "updating"
GET {{host}}/api/v1/reservations/summit
Authorization: Bearer {{access_token}}
[Options]
retry: 15
retry: 25
HTTP 200
[Asserts]
jsonpath "$.reservation.status" == "success"
Expand Down

0 comments on commit f6e420d

Please sign in to comment.