Skip to content

Commit

Permalink
feat(observability): add start parameter to provide basic auth to pyr…
Browse files Browse the repository at this point in the history
…oscope

Signed-off-by: Smuu <[email protected]>
  • Loading branch information
smuu committed Dec 11, 2024
1 parent ac5d7a7 commit 6d9722f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
42 changes: 29 additions & 13 deletions cmd/flags_misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@ import (
)

var (
LogLevelFlag = "log.level"
LogLevelModuleFlag = "log.level.module"
pprofFlag = "pprof"
tracingFlag = "tracing"
tracingEndpointFlag = "tracing.endpoint"
tracingTlS = "tracing.tls"
metricsFlag = "metrics"
metricsEndpointFlag = "metrics.endpoint"
metricsTlS = "metrics.tls"
p2pMetrics = "p2p.metrics"
pyroscopeFlag = "pyroscope"
pyroscopeTracing = "pyroscope.tracing"
pyroscopeEndpoint = "pyroscope.endpoint"
LogLevelFlag = "log.level"
LogLevelModuleFlag = "log.level.module"
pprofFlag = "pprof"
tracingFlag = "tracing"
tracingEndpointFlag = "tracing.endpoint"
tracingTlS = "tracing.tls"
metricsFlag = "metrics"
metricsEndpointFlag = "metrics.endpoint"
metricsTlS = "metrics.tls"
p2pMetrics = "p2p.metrics"
pyroscopeFlag = "pyroscope"
pyroscopeTracing = "pyroscope.tracing"
pyroscopeEndpoint = "pyroscope.endpoint"
pyroscopeBasicAuthUser = "pyroscope.basic-auth.user"
pyroscopeBasicAuthPassword = "pyroscope.basic-auth.password"

Check failure on line 37 in cmd/flags_misc.go

View workflow job for this annotation

GitHub Actions / go-ci / Lint

G101: Potential hardcoded credentials (gosec)
)

// MiscFlags gives a set of hardcoded miscellaneous flags.
Expand Down Expand Up @@ -118,6 +120,18 @@ and their lower-case forms`,
"Sets HTTP endpoint for Pyroscope profiles to be exported to. Depends on '--pyroscope'",
)

flags.String(
pyroscopeBasicAuthUser,
"",
"Sets basic auth user for Pyroscope. Depends on '--pyroscope'",
)

flags.String(
pyroscopeBasicAuthPassword,
"",
"Sets basic auth password for Pyroscope. Depends on '--pyroscope'",
)

return flags
}

Expand Down Expand Up @@ -183,6 +197,8 @@ func ParseMiscFlags(ctx context.Context, cmd *cobra.Command) (context.Context, e
ctx = WithNodeOptions(ctx,
nodebuilder.WithPyroscope(
cmd.Flag(pyroscopeEndpoint).Value.String(),
cmd.Flag(pyroscopeBasicAuthUser).Value.String(),
cmd.Flag(pyroscopeBasicAuthPassword).Value.String(),
NodeType(ctx),
),
)
Expand Down
13 changes: 10 additions & 3 deletions nodebuilder/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ func WithBootstrappers(peers p2p.Bootstrappers) fx.Option {
}

// WithPyroscope enables pyroscope profiling for the node.
func WithPyroscope(endpoint string, nodeType node.Type) fx.Option {
func WithPyroscope(endpoint string, basicAuthUser string, basicAuthPassword string, nodeType node.Type) fx.Option {
return fx.Options(
fx.Invoke(func(peerID peer.ID) error {
_, err := pyroscope.Start(pyroscope.Config{
config := pyroscope.Config{
UploadRate: 15 * time.Second,
ApplicationName: "celestia.da-node",
ServerAddress: endpoint,
Expand All @@ -69,7 +69,14 @@ func WithPyroscope(endpoint string, nodeType node.Type) fx.Option {
pyroscope.ProfileInuseSpace,
pyroscope.ProfileGoroutines,
},
})
}

if basicAuthUser != "" && basicAuthPassword != "" {
config.BasicAuthUser = basicAuthUser
config.BasicAuthPassword = basicAuthPassword
}

_, err := pyroscope.Start(config)
return err
}),
)
Expand Down

0 comments on commit 6d9722f

Please sign in to comment.