Dmitrii Stepanov
d433b49265
All checks were successful
DCO action / DCO (pull_request) Successful in 2m40s
Vulncheck / Vulncheck (pull_request) Successful in 3m41s
Build / Build Components (1.20) (pull_request) Successful in 4m27s
Build / Build Components (1.21) (pull_request) Successful in 5m6s
Tests and linters / Staticcheck (pull_request) Successful in 6m16s
Tests and linters / gopls check (pull_request) Successful in 6m23s
Tests and linters / Lint (pull_request) Successful in 6m48s
Tests and linters / Tests (1.20) (pull_request) Successful in 9m4s
Tests and linters / Tests with -race (pull_request) Successful in 9m9s
Tests and linters / Tests (1.21) (pull_request) Successful in 9m23s
`fmt.Errorf can be replaced with errors.New` and `fmt.Sprintf can be replaced with string addition` Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
67 lines
1.4 KiB
Go
67 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"runtime"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
|
httputil "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/http"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type pprofComponent struct {
|
|
httpComponent
|
|
blockRate int
|
|
mutexRate int
|
|
}
|
|
|
|
const (
|
|
pprofBlockRateKey = "pprof.block_rate"
|
|
pprofMutexRateKey = "pprof.mutex_rate"
|
|
)
|
|
|
|
func newPprofComponent() *pprofComponent {
|
|
return &pprofComponent{
|
|
httpComponent: httpComponent{
|
|
name: "pprof",
|
|
handler: httputil.Handler(),
|
|
},
|
|
}
|
|
}
|
|
|
|
func (c *pprofComponent) init() {
|
|
c.httpComponent.init()
|
|
|
|
if c.enabled {
|
|
c.blockRate = cfg.GetInt(pprofBlockRateKey)
|
|
c.mutexRate = cfg.GetInt(pprofMutexRateKey)
|
|
runtime.SetBlockProfileRate(c.blockRate)
|
|
runtime.SetMutexProfileFraction(c.mutexRate)
|
|
} else {
|
|
c.blockRate = 0
|
|
c.mutexRate = 0
|
|
runtime.SetBlockProfileRate(0)
|
|
runtime.SetMutexProfileFraction(0)
|
|
}
|
|
}
|
|
|
|
func (c *pprofComponent) needReload() bool {
|
|
blockRate := cfg.GetInt(pprofBlockRateKey)
|
|
mutexRate := cfg.GetInt(pprofMutexRateKey)
|
|
return c.httpComponent.needReload() ||
|
|
c.enabled && (c.blockRate != blockRate || c.mutexRate != mutexRate)
|
|
}
|
|
|
|
func (c *pprofComponent) reload() {
|
|
log.Info("reload " + c.name)
|
|
if c.needReload() {
|
|
log.Info(c.name + " config updated")
|
|
if err := c.shutdown(); err != nil {
|
|
log.Debug(logs.FrostFSIRCouldNotShutdownHTTPServer,
|
|
zap.String("error", err.Error()))
|
|
return
|
|
}
|
|
|
|
c.init()
|
|
c.start()
|
|
}
|
|
}
|