add pprof handler
This commit is contained in:
parent
629c095bbe
commit
f9ff71f62a
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,4 +1,7 @@
|
||||
.vscode
|
||||
|
||||
data
|
||||
__debug*
|
||||
__debug*
|
||||
|
||||
.env
|
||||
.envrc
|
@ -1,11 +1,12 @@
|
||||
FROM docker.io/library/golang:1.24-alpine
|
||||
ARG GOPROXY=direct
|
||||
ARG TAGS=""
|
||||
ARG ALPINE_MIRROR=https://mirrors.ustc.edu.cn
|
||||
WORKDIR /src
|
||||
COPY go.mod go.sum ./
|
||||
RUN sed -i "s,https://dl-cdn.alpinelinux.org,${ALPINE_MIRROR}," /etc/apk/repositories; apk add git && env GOPROXY=${GOPROXY:-direct} go mod download
|
||||
ADD . /src
|
||||
RUN go build -o /cache-proxy ./cmd/proxy
|
||||
RUN go build -o /cache-proxy -tags "${TAGS}" ./cmd/proxy
|
||||
|
||||
FROM docker.io/library/alpine:3.21 AS runtime
|
||||
COPY --from=0 /cache-proxy /bin/cache-proxy
|
||||
|
17
cmd/proxy/debug.go
Normal file
17
cmd/proxy/debug.go
Normal file
@ -0,0 +1,17 @@
|
||||
//go:build pprof
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.BoolVar(&pprofEnabled, "pprof", true, "")
|
||||
|
||||
if v, ok := os.LookupEnv("SENTRY_DSN"); ok {
|
||||
sentrydsn = v
|
||||
}
|
||||
flag.StringVar(&sentrydsn, "sentry", sentrydsn, "sentry dsn to report errors")
|
||||
}
|
@ -4,6 +4,7 @@ import (
|
||||
"flag"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/http/pprof"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
@ -22,6 +23,7 @@ var (
|
||||
configFilePath = "config.yaml"
|
||||
logLevel = "info"
|
||||
sentrydsn = ""
|
||||
pprofEnabled = false
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -31,12 +33,8 @@ func init() {
|
||||
if v, ok := os.LookupEnv("LOG_LEVEL"); ok {
|
||||
logLevel = v
|
||||
}
|
||||
if v, ok := os.LookupEnv("SENTRY_DSN"); ok {
|
||||
sentrydsn = v
|
||||
}
|
||||
flag.StringVar(&configFilePath, "config", configFilePath, "path to config file")
|
||||
flag.StringVar(&logLevel, "log-level", logLevel, "log level. (trace, debug, info, warn, error)")
|
||||
flag.StringVar(&sentrydsn, "sentry", sentrydsn, "sentry dsn to report errors")
|
||||
}
|
||||
|
||||
func configFromFile(path string) (*cacheproxy.Config, error) {
|
||||
@ -124,6 +122,14 @@ func main() {
|
||||
|
||||
mux.HandleFunc("GET /", server.HandleRequestWithCache)
|
||||
|
||||
if pprofEnabled {
|
||||
mux.HandleFunc("GET /debug/pprof/", pprof.Index)
|
||||
mux.HandleFunc("GET /debug/pprof/cmdline", pprof.Cmdline)
|
||||
mux.HandleFunc("GET /debug/pprof/profile", pprof.Profile)
|
||||
mux.HandleFunc("GET /debug/pprof/symbol", pprof.Symbol)
|
||||
mux.HandleFunc("GET /debug/pprof/trace", pprof.Trace)
|
||||
}
|
||||
|
||||
slog.With("addr", ":8881").Info("serving app")
|
||||
if err := http.ListenAndServe(":8881", middleware.Use(mux,
|
||||
recover.Recover(),
|
||||
|
20
compose.release.yaml
Normal file
20
compose.release.yaml
Normal file
@ -0,0 +1,20 @@
|
||||
services:
|
||||
cache-proxy:
|
||||
image: ${REPOSITORY:-git.jeffthecoder.xyz}/${OWNER:-public}/cache-proxy:${VERSION:-latest}
|
||||
build:
|
||||
args:
|
||||
GOPROXY: ${GOPROXY:-direct}
|
||||
ALPINE_MIRROR: ${ALPINE_MIRROR:-https://mirrors.ustc.edu.cn}
|
||||
|
||||
restart: always
|
||||
|
||||
volumes:
|
||||
- ./config.yaml:/config.yaml:ro
|
||||
- ./data:/data
|
||||
ports:
|
||||
- 8881:8881
|
||||
environment:
|
||||
- LOG_LEVEL=info
|
||||
env_file:
|
||||
- path: .env
|
||||
required: false
|
13
compose.yaml
13
compose.yaml
@ -1,12 +1,12 @@
|
||||
services:
|
||||
cache-proxy:
|
||||
image: 100.64.0.2:3000/guochao/cache-proxy:${VERSION:-latest}
|
||||
image: ${REPOSITORY:-git.jeffthecoder.xyz}/${OWNER:-public}/cache-proxy:${VERSION:-latest}
|
||||
build:
|
||||
args:
|
||||
GOPROXY: ${GOPROXY:-direct}
|
||||
ALPINE_MIRROR: ${ALPINE_MIRROR:-https://mirrors.ustc.edu.cn}
|
||||
TAGS: pprof
|
||||
|
||||
pull_policy: always
|
||||
restart: always
|
||||
|
||||
volumes:
|
||||
@ -15,9 +15,8 @@ services:
|
||||
ports:
|
||||
- 8881:8881
|
||||
environment:
|
||||
- HTTPS_PROXY=http://100.64.0.23:7890
|
||||
- HTTP_PROXY=http://100.64.0.23:7890
|
||||
- ALL_PROXY=http://100.64.0.23:7890
|
||||
- NO_PROXY=localhost,local,cn,*.local,*.cn,127.0.0.1,127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,100.64.0.0/16
|
||||
- SENTRY_DSN=http://3b7336602c77427d96318074cd86ee04@100.64.0.2:8000/2
|
||||
- SENTRY_DSN=${SENTRY_DSN}
|
||||
- LOG_LEVEL=debug
|
||||
env_file:
|
||||
- path: .env
|
||||
required: false
|
Loading…
x
Reference in New Issue
Block a user