internal/debug: add basic authentication support for pyroscope profiler

This commit is contained in:
Carlos Bermudez Porto 2025-11-27 13:40:37 -03:00
parent 7442b66c4f
commit b53ad0c0a6
No known key found for this signature in database
GPG key ID: BB3E788AC4086AD8
2 changed files with 30 additions and 5 deletions

View file

@ -150,6 +150,8 @@ func (l *pyroscopeLogger) Errorf(format string, v ...interface{}) {
// StartPyroscopeProfiler starts the Pyroscope profiler for later use // StartPyroscopeProfiler starts the Pyroscope profiler for later use
func (h *HandlerT) StartPyroscopeProfiler( func (h *HandlerT) StartPyroscopeProfiler(
server string, server string,
authUsername string,
authPassword string,
tags map[string]string, tags map[string]string,
) error { ) error {
h.mu.Lock() h.mu.Lock()
@ -162,6 +164,8 @@ func (h *HandlerT) StartPyroscopeProfiler(
pyroscope.Config{ pyroscope.Config{
ApplicationName: "geth", ApplicationName: "geth",
ServerAddress: server, ServerAddress: server,
BasicAuthUser: authUsername,
BasicAuthPassword: authPassword,
Logger: &pyroscopeLogger{Logger: log.Root().With("module", "pyroscope")}, Logger: &pyroscopeLogger{Logger: log.Root().With("module", "pyroscope")},
Tags: tags, Tags: tags,
ProfileTypes: []pyroscope.ProfileType{ ProfileTypes: []pyroscope.ProfileType{

View file

@ -153,6 +153,18 @@ var (
Value: "http://localhost:4040", Value: "http://localhost:4040",
Category: flags.LoggingCategory, Category: flags.LoggingCategory,
} }
pyroscopeAuthUsernameFlag = &cli.StringFlag{
Name: "pyroscope.username",
Usage: "Pyroscope basic authentication username",
Value: "",
Category: flags.LoggingCategory,
}
pyroscopeAuthPasswordFlag = &cli.StringFlag{
Name: "pyroscope.password",
Usage: "Pyroscope basic authentication password",
Value: "",
Category: flags.LoggingCategory,
}
pyroscopeTagsFlag = &cli.StringFlag{ pyroscopeTagsFlag = &cli.StringFlag{
Name: "pyroscope.tags", Name: "pyroscope.tags",
Usage: "Comma separated list of key=value tags to add to profiling data", Usage: "Comma separated list of key=value tags to add to profiling data",
@ -183,6 +195,8 @@ var Flags = []cli.Flag{
traceFlag, traceFlag,
pyroscopeFlag, pyroscopeFlag,
pyroscopeServerFlag, pyroscopeServerFlag,
pyroscopeAuthUsernameFlag,
pyroscopeAuthPasswordFlag,
pyroscopeTagsFlag, pyroscopeTagsFlag,
} }
@ -324,6 +338,8 @@ func Setup(ctx *cli.Context) error {
// Pyroscope profiling // Pyroscope profiling
if ctx.Bool(pyroscopeFlag.Name) { if ctx.Bool(pyroscopeFlag.Name) {
pyroscopeServer := ctx.String(pyroscopeServerFlag.Name) pyroscopeServer := ctx.String(pyroscopeServerFlag.Name)
pyroscopeAuthUsername := ctx.String(pyroscopeAuthUsernameFlag.Name)
pyroscopeAuthPassword := ctx.String(pyroscopeAuthPasswordFlag.Name)
rawTags := ctx.String(pyroscopeTagsFlag.Name) rawTags := ctx.String(pyroscopeTagsFlag.Name)
tags := make(map[string]string) tags := make(map[string]string)
@ -335,7 +351,12 @@ func Setup(ctx *cli.Context) error {
} }
} }
Handler.StartPyroscopeProfiler(pyroscopeServer, tags) Handler.StartPyroscopeProfiler(
pyroscopeServer,
pyroscopeAuthUsername,
pyroscopeAuthPassword,
tags,
)
} }
if len(logFile) > 0 || rotation { if len(logFile) > 0 || rotation {