From f989bc52be968a4ce7f96adb4da0bd550dae33f1 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 12 May 2023 11:04:52 +0300 Subject: [PATCH] [#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 --- cmd/frostfs-ir/httpcomponent.go | 33 ++++++++++++++++++--------------- cmd/frostfs-ir/metrics.go | 13 ++----------- cmd/frostfs-ir/pprof.go | 13 ++----------- 3 files changed, 22 insertions(+), 37 deletions(-) diff --git a/cmd/frostfs-ir/httpcomponent.go b/cmd/frostfs-ir/httpcomponent.go index d73160a1d..38e936471 100644 --- a/cmd/frostfs-ir/httpcomponent.go +++ b/cmd/frostfs-ir/httpcomponent.go @@ -11,22 +11,25 @@ import ( ) type httpComponent struct { - srv *httputil.Server - address string - addressKey string - name string - handler http.Handler - shutdownDur time.Duration - shutdownTimeoutKey string - enabled bool - enabledKey string + srv *httputil.Server + address string + name string + handler http.Handler + shutdownDur time.Duration + enabled bool } +const ( + enabledKeyPostfix = ".enabled" + addressKeyPostfix = ".address" + shutdownTimeoutKeyPostfix = ".shutdown_timeout" +) + func (c *httpComponent) init() { log.Info(fmt.Sprintf("init %s", c.name)) - c.enabled = cfg.GetBool(c.enabledKey) - c.address = cfg.GetString(c.addressKey) - c.shutdownDur = cfg.GetDuration(c.shutdownTimeoutKey) + c.enabled = cfg.GetBool(c.name + enabledKeyPostfix) + c.address = cfg.GetString(c.name + addressKeyPostfix) + c.shutdownDur = cfg.GetDuration(c.name + shutdownTimeoutKeyPostfix) if c.enabled { c.srv = httputil.New( @@ -63,9 +66,9 @@ func (c *httpComponent) shutdown() error { func (c *httpComponent) reload() { log.Info(fmt.Sprintf("reload %s", c.name)) - enabled := cfg.GetBool(c.enabledKey) - address := cfg.GetString(c.addressKey) - dur := cfg.GetDuration(c.shutdownTimeoutKey) + enabled := cfg.GetBool(c.name + enabledKeyPostfix) + address := cfg.GetString(c.name + addressKeyPostfix) + dur := cfg.GetDuration(c.name + shutdownTimeoutKeyPostfix) if enabled != c.enabled || enabled && (address != c.address || dur != c.shutdownDur) { log.Info(fmt.Sprintf("%s config updated", c.name)) if err := c.shutdown(); err != nil { diff --git a/cmd/frostfs-ir/metrics.go b/cmd/frostfs-ir/metrics.go index debeb7d60..39b432c74 100644 --- a/cmd/frostfs-ir/metrics.go +++ b/cmd/frostfs-ir/metrics.go @@ -4,18 +4,9 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/metrics" ) -const ( - prometheusEnabledKey = "prometheus.enabled" - prometheusAddressKey = "prometheus.address" - prometheusShutdownTimeoutKey = "prometheus.shutdown_timeout" -) - func newMetricsComponent() *httpComponent { return &httpComponent{ - name: "prometheus", - enabledKey: prometheusEnabledKey, - addressKey: prometheusAddressKey, - shutdownTimeoutKey: prometheusShutdownTimeoutKey, - handler: metrics.Handler(), + name: "prometheus", + handler: metrics.Handler(), } } diff --git a/cmd/frostfs-ir/pprof.go b/cmd/frostfs-ir/pprof.go index 0d48c11de..8228a0f53 100644 --- a/cmd/frostfs-ir/pprof.go +++ b/cmd/frostfs-ir/pprof.go @@ -4,18 +4,9 @@ import ( httputil "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/http" ) -const ( - pprofEnabledKey = "pprof.enabled" - pprofAddressKey = "pprof.address" - pprofShutdownTimeoutKey = "pprof.shutdown_timeout" -) - func newPprofComponent() *httpComponent { return &httpComponent{ - name: "pprof", - enabledKey: pprofEnabledKey, - addressKey: pprofAddressKey, - shutdownTimeoutKey: pprofShutdownTimeoutKey, - handler: httputil.Handler(), + name: "pprof", + handler: httputil.Handler(), } }