config: move metrics.Config into config.BasicService

Config package should be as lightweight as possible and now it depends on the
whole metrics package just to get one structure from it.
This commit is contained in:
Roman Khimov 2022-07-08 19:10:46 +03:00
parent fab8dfb9f8
commit dc59dc991b
6 changed files with 18 additions and 16 deletions

View file

@ -10,7 +10,6 @@ import (
"github.com/nspcc-dev/neo-go/pkg/config"
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
"github.com/nspcc-dev/neo-go/pkg/core/storage"
"github.com/nspcc-dev/neo-go/pkg/network/metrics"
"github.com/nspcc-dev/neo-go/pkg/rpc"
"github.com/stretchr/testify/require"
"github.com/urfave/cli"
@ -317,7 +316,7 @@ func TestConfigureAddresses(t *testing.T) {
t.Run("custom Pprof address", func(t *testing.T) {
cfg := &config.ApplicationConfiguration{
Address: defaultAddress,
Pprof: metrics.Config{
Pprof: config.BasicService{
Address: customAddress,
},
}
@ -330,7 +329,7 @@ func TestConfigureAddresses(t *testing.T) {
t.Run("custom Prometheus address", func(t *testing.T) {
cfg := &config.ApplicationConfiguration{
Address: defaultAddress,
Prometheus: metrics.Config{
Prometheus: config.BasicService{
Address: customAddress,
},
}

View file

@ -2,7 +2,6 @@ package config
import (
"github.com/nspcc-dev/neo-go/pkg/core/storage"
"github.com/nspcc-dev/neo-go/pkg/network/metrics"
"github.com/nspcc-dev/neo-go/pkg/rpc"
)
@ -19,8 +18,8 @@ type ApplicationConfiguration struct {
NodePort uint16 `yaml:"NodePort"`
PingInterval int64 `yaml:"PingInterval"`
PingTimeout int64 `yaml:"PingTimeout"`
Pprof metrics.Config `yaml:"Pprof"`
Prometheus metrics.Config `yaml:"Prometheus"`
Pprof BasicService `yaml:"Pprof"`
Prometheus BasicService `yaml:"Prometheus"`
ProtoTickInterval int64 `yaml:"ProtoTickInterval"`
Relay bool `yaml:"Relay"`
RPC rpc.Config `yaml:"RPC"`

View file

@ -0,0 +1,8 @@
package config
// BasicService is used for simple services like Pprof or Prometheus monitoring.
type BasicService struct {
Enabled bool `yaml:"Enabled"`
Address string `yaml:"Address"`
Port string `yaml:"Port"`
}

View file

@ -4,24 +4,18 @@ import (
"context"
"net/http"
"github.com/nspcc-dev/neo-go/pkg/config"
"go.uber.org/zap"
)
// Service serves metrics.
type Service struct {
*http.Server
config Config
config config.BasicService
log *zap.Logger
serviceType string
}
// Config config used for monitoring.
type Config struct {
Enabled bool `yaml:"Enabled"`
Address string `yaml:"Address"`
Port string `yaml:"Port"`
}
// Start runs http service with the exposed endpoint on the configured port.
func (ms *Service) Start() {
if ms.config.Enabled {

View file

@ -4,6 +4,7 @@ import (
"net/http"
"net/http/pprof"
"github.com/nspcc-dev/neo-go/pkg/config"
"go.uber.org/zap"
)
@ -11,7 +12,7 @@ import (
type PprofService Service
// NewPprofService creates a new service for gathering pprof metrics.
func NewPprofService(cfg Config, log *zap.Logger) *Service {
func NewPprofService(cfg config.BasicService, log *zap.Logger) *Service {
if log == nil {
return nil
}

View file

@ -3,6 +3,7 @@ package metrics
import (
"net/http"
"github.com/nspcc-dev/neo-go/pkg/config"
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.uber.org/zap"
)
@ -11,7 +12,7 @@ import (
type PrometheusService Service
// NewPrometheusService creates a new service for gathering prometheus metrics.
func NewPrometheusService(cfg Config, log *zap.Logger) *Service {
func NewPrometheusService(cfg config.BasicService, log *zap.Logger) *Service {
if log == nil {
return nil
}