forked from TrueCloudLab/frostfs-node
[#39] ir: Do not store config keys in httpComponent
Pprof will have specific options, it seems wrong to have them in a generic struct. Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
61776033c2
commit
f989bc52be
3 changed files with 22 additions and 37 deletions
|
@ -13,20 +13,23 @@ import (
|
||||||
type httpComponent struct {
|
type httpComponent struct {
|
||||||
srv *httputil.Server
|
srv *httputil.Server
|
||||||
address string
|
address string
|
||||||
addressKey string
|
|
||||||
name string
|
name string
|
||||||
handler http.Handler
|
handler http.Handler
|
||||||
shutdownDur time.Duration
|
shutdownDur time.Duration
|
||||||
shutdownTimeoutKey string
|
|
||||||
enabled bool
|
enabled bool
|
||||||
enabledKey string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
enabledKeyPostfix = ".enabled"
|
||||||
|
addressKeyPostfix = ".address"
|
||||||
|
shutdownTimeoutKeyPostfix = ".shutdown_timeout"
|
||||||
|
)
|
||||||
|
|
||||||
func (c *httpComponent) init() {
|
func (c *httpComponent) init() {
|
||||||
log.Info(fmt.Sprintf("init %s", c.name))
|
log.Info(fmt.Sprintf("init %s", c.name))
|
||||||
c.enabled = cfg.GetBool(c.enabledKey)
|
c.enabled = cfg.GetBool(c.name + enabledKeyPostfix)
|
||||||
c.address = cfg.GetString(c.addressKey)
|
c.address = cfg.GetString(c.name + addressKeyPostfix)
|
||||||
c.shutdownDur = cfg.GetDuration(c.shutdownTimeoutKey)
|
c.shutdownDur = cfg.GetDuration(c.name + shutdownTimeoutKeyPostfix)
|
||||||
|
|
||||||
if c.enabled {
|
if c.enabled {
|
||||||
c.srv = httputil.New(
|
c.srv = httputil.New(
|
||||||
|
@ -63,9 +66,9 @@ func (c *httpComponent) shutdown() error {
|
||||||
|
|
||||||
func (c *httpComponent) reload() {
|
func (c *httpComponent) reload() {
|
||||||
log.Info(fmt.Sprintf("reload %s", c.name))
|
log.Info(fmt.Sprintf("reload %s", c.name))
|
||||||
enabled := cfg.GetBool(c.enabledKey)
|
enabled := cfg.GetBool(c.name + enabledKeyPostfix)
|
||||||
address := cfg.GetString(c.addressKey)
|
address := cfg.GetString(c.name + addressKeyPostfix)
|
||||||
dur := cfg.GetDuration(c.shutdownTimeoutKey)
|
dur := cfg.GetDuration(c.name + shutdownTimeoutKeyPostfix)
|
||||||
if enabled != c.enabled || enabled && (address != c.address || dur != c.shutdownDur) {
|
if enabled != c.enabled || enabled && (address != c.address || dur != c.shutdownDur) {
|
||||||
log.Info(fmt.Sprintf("%s config updated", c.name))
|
log.Info(fmt.Sprintf("%s config updated", c.name))
|
||||||
if err := c.shutdown(); err != nil {
|
if err := c.shutdown(); err != nil {
|
||||||
|
|
|
@ -4,18 +4,9 @@ import (
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/metrics"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/metrics"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
prometheusEnabledKey = "prometheus.enabled"
|
|
||||||
prometheusAddressKey = "prometheus.address"
|
|
||||||
prometheusShutdownTimeoutKey = "prometheus.shutdown_timeout"
|
|
||||||
)
|
|
||||||
|
|
||||||
func newMetricsComponent() *httpComponent {
|
func newMetricsComponent() *httpComponent {
|
||||||
return &httpComponent{
|
return &httpComponent{
|
||||||
name: "prometheus",
|
name: "prometheus",
|
||||||
enabledKey: prometheusEnabledKey,
|
|
||||||
addressKey: prometheusAddressKey,
|
|
||||||
shutdownTimeoutKey: prometheusShutdownTimeoutKey,
|
|
||||||
handler: metrics.Handler(),
|
handler: metrics.Handler(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,18 +4,9 @@ import (
|
||||||
httputil "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/http"
|
httputil "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
pprofEnabledKey = "pprof.enabled"
|
|
||||||
pprofAddressKey = "pprof.address"
|
|
||||||
pprofShutdownTimeoutKey = "pprof.shutdown_timeout"
|
|
||||||
)
|
|
||||||
|
|
||||||
func newPprofComponent() *httpComponent {
|
func newPprofComponent() *httpComponent {
|
||||||
return &httpComponent{
|
return &httpComponent{
|
||||||
name: "pprof",
|
name: "pprof",
|
||||||
enabledKey: pprofEnabledKey,
|
|
||||||
addressKey: pprofAddressKey,
|
|
||||||
shutdownTimeoutKey: pprofShutdownTimeoutKey,
|
|
||||||
handler: httputil.Handler(),
|
handler: httputil.Handler(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue