Skip to content
Draft
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
1 change: 1 addition & 0 deletions deployment/clouddeploy/gke-workers/base/gitter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ spec:
imagePullPolicy: Always
args:
- "--port=8888"
- "--enable_profiling=true"
- "--work_dir=/work/gitter"
- "--fetch_timeout=1h"
volumeMounts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ spec:
- name: gitter
args:
- "--port=8888"
- "--enable_profiling=true"
- "--work_dir=/work/gitter"
- "--fetch_timeout=1h"
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ spec:
- name: gitter
args:
- "--port=8888"
- "--enable_profiling=true"
- "--work_dir=/work/gitter"
- "--fetch_timeout=1h"
env:
Expand Down
16 changes: 15 additions & 1 deletion go/cmd/gitter/gitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"syscall"
"time"

"net/http/pprof"

"github.com/google/osv.dev/go/logger"
"golang.org/x/sync/singleflight"
)
Expand Down Expand Up @@ -197,6 +199,7 @@ func fetchBlob(ctx context.Context, url string, forceUpdate bool) ([]byte, error

func main() {
port := flag.Int("port", 8888, "Listen port")
enableProfiling := flag.Bool("enable_profiling", false, "Enable pprof profiling endpoints")
workDir := flag.String("work_dir", defaultGitterWorkDir, "Work directory")
flag.DurationVar(&fetchTimeout, "fetch_timeout", time.Hour, "Fetch timeout duration")
flag.Parse()
Expand All @@ -215,7 +218,16 @@ func main() {
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()

http.HandleFunc(getGitEndpoint, gitHandler)
mux := http.NewServeMux()
mux.HandleFunc(getGitEndpoint, gitHandler)

if *enableProfiling {
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
}

logger.Info("Gitter starting and listening", slog.Int("port", *port))

Expand All @@ -232,6 +244,7 @@ func main() {

server := &http.Server{
Addr: fmt.Sprintf(":%d", *port),
Handler: mux,
ReadHeaderTimeout: 3 * time.Second,
BaseContext: func(_ net.Listener) context.Context {
// Return the context tied to the termination signal.
Expand Down Expand Up @@ -260,6 +273,7 @@ func main() {
logger.Error("Server forced to shutdown", slog.Any("error", err))
}


saveMap()
logger.Info("Server exiting")
}
Expand Down
Binary file added go/cmd/gitter/gitter_test_bin
Binary file not shown.