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 committed by Felix Lange
parent 2c3aa48b5b
commit aa6a37d591
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
func (h *HandlerT) StartPyroscopeProfiler(
server string,
authUsername string,
authPassword string,
tags map[string]string,
) error {
h.mu.Lock()
@ -162,6 +164,8 @@ func (h *HandlerT) StartPyroscopeProfiler(
pyroscope.Config{
ApplicationName: "geth",
ServerAddress: server,
BasicAuthUser: authUsername,
BasicAuthPassword: authPassword,
Logger: &pyroscopeLogger{Logger: log.Root().With("module", "pyroscope")},
Tags: tags,
ProfileTypes: []pyroscope.ProfileType{

View file

@ -153,6 +153,18 @@ var (
Value: "http://localhost:4040",
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{
Name: "pyroscope.tags",
Usage: "Comma separated list of key=value tags to add to profiling data",
@ -183,6 +195,8 @@ var Flags = []cli.Flag{
traceFlag,
pyroscopeFlag,
pyroscopeServerFlag,
pyroscopeAuthUsernameFlag,
pyroscopeAuthPasswordFlag,
pyroscopeTagsFlag,
}
@ -324,6 +338,8 @@ func Setup(ctx *cli.Context) error {
// Pyroscope profiling
if ctx.Bool(pyroscopeFlag.Name) {
pyroscopeServer := ctx.String(pyroscopeServerFlag.Name)
pyroscopeAuthUsername := ctx.String(pyroscopeAuthUsernameFlag.Name)
pyroscopeAuthPassword := ctx.String(pyroscopeAuthPasswordFlag.Name)
rawTags := ctx.String(pyroscopeTagsFlag.Name)
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 {