Skip to content

Commit b53ad0c

Browse files
committed
internal/debug: add basic authentication support for pyroscope profiler
1 parent 7442b66 commit b53ad0c

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

internal/debug/api.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ func (l *pyroscopeLogger) Errorf(format string, v ...interface{}) {
150150
// StartPyroscopeProfiler starts the Pyroscope profiler for later use
151151
func (h *HandlerT) StartPyroscopeProfiler(
152152
server string,
153+
authUsername string,
154+
authPassword string,
153155
tags map[string]string,
154156
) error {
155157
h.mu.Lock()
@@ -160,10 +162,12 @@ func (h *HandlerT) StartPyroscopeProfiler(
160162
}
161163
profiler, err := pyroscope.Start(
162164
pyroscope.Config{
163-
ApplicationName: "geth",
164-
ServerAddress: server,
165-
Logger: &pyroscopeLogger{Logger: log.Root().With("module", "pyroscope")},
166-
Tags: tags,
165+
ApplicationName: "geth",
166+
ServerAddress: server,
167+
BasicAuthUser: authUsername,
168+
BasicAuthPassword: authPassword,
169+
Logger: &pyroscopeLogger{Logger: log.Root().With("module", "pyroscope")},
170+
Tags: tags,
167171
ProfileTypes: []pyroscope.ProfileType{
168172
// Enabling all profile types
169173
pyroscope.ProfileCPU,

internal/debug/flags.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,18 @@ var (
153153
Value: "http://localhost:4040",
154154
Category: flags.LoggingCategory,
155155
}
156+
pyroscopeAuthUsernameFlag = &cli.StringFlag{
157+
Name: "pyroscope.username",
158+
Usage: "Pyroscope basic authentication username",
159+
Value: "",
160+
Category: flags.LoggingCategory,
161+
}
162+
pyroscopeAuthPasswordFlag = &cli.StringFlag{
163+
Name: "pyroscope.password",
164+
Usage: "Pyroscope basic authentication password",
165+
Value: "",
166+
Category: flags.LoggingCategory,
167+
}
156168
pyroscopeTagsFlag = &cli.StringFlag{
157169
Name: "pyroscope.tags",
158170
Usage: "Comma separated list of key=value tags to add to profiling data",
@@ -183,6 +195,8 @@ var Flags = []cli.Flag{
183195
traceFlag,
184196
pyroscopeFlag,
185197
pyroscopeServerFlag,
198+
pyroscopeAuthUsernameFlag,
199+
pyroscopeAuthPasswordFlag,
186200
pyroscopeTagsFlag,
187201
}
188202

@@ -324,6 +338,8 @@ func Setup(ctx *cli.Context) error {
324338
// Pyroscope profiling
325339
if ctx.Bool(pyroscopeFlag.Name) {
326340
pyroscopeServer := ctx.String(pyroscopeServerFlag.Name)
341+
pyroscopeAuthUsername := ctx.String(pyroscopeAuthUsernameFlag.Name)
342+
pyroscopeAuthPassword := ctx.String(pyroscopeAuthPasswordFlag.Name)
327343

328344
rawTags := ctx.String(pyroscopeTagsFlag.Name)
329345
tags := make(map[string]string)
@@ -335,7 +351,12 @@ func Setup(ctx *cli.Context) error {
335351
}
336352
}
337353

338-
Handler.StartPyroscopeProfiler(pyroscopeServer, tags)
354+
Handler.StartPyroscopeProfiler(
355+
pyroscopeServer,
356+
pyroscopeAuthUsername,
357+
pyroscopeAuthPassword,
358+
tags,
359+
)
339360
}
340361

341362
if len(logFile) > 0 || rotation {

0 commit comments

Comments
 (0)