From a9a434dcec1d6debcf06830a2cc3685a51362921 Mon Sep 17 00:00:00 2001 From: Freddy Caceres Date: Wed, 23 Nov 2022 20:21:09 -0500 Subject: [PATCH 1/3] fix: register sdk metrics on startInProcess --- server/api/server.go | 18 ++++++++++++++---- server/start.go | 8 -------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/server/api/server.go b/server/api/server.go index 5b2c6fb37293..375739c60848 100644 --- a/server/api/server.go +++ b/server/api/server.go @@ -88,6 +88,13 @@ func New(clientCtx client.Context, logger log.Logger) *Server { func (s *Server) Start(cfg config.Config) error { s.mtx.Lock() + if cfg.Telemetry.Enabled { + if err := s.SetTelemetry(cfg); err != nil { + s.mtx.Unlock() + return err + } + } + tmCfg := tmrpcserver.DefaultConfig() tmCfg.MaxOpenConnections = int(cfg.API.MaxOpenConnections) tmCfg.ReadTimeout = time.Duration(cfg.API.RPCReadTimeout) * time.Second @@ -126,11 +133,14 @@ func (s *Server) registerGRPCGatewayRoutes() { s.Router.PathPrefix("/").Handler(s.GRPCGatewayRouter) } -func (s *Server) SetTelemetry(m *telemetry.Metrics) { - s.mtx.Lock() - s.metrics = m +func (s *Server) SetTelemetry(cfg config.Config) error { + metrics, err := telemetry.New(cfg.Telemetry) + if err != nil { + return err + } + s.metrics = metrics s.registerMetrics() - s.mtx.Unlock() + return nil } func (s *Server) registerMetrics() { diff --git a/server/start.go b/server/start.go index 41fdaaaec1fd..0448b17e5abc 100644 --- a/server/start.go +++ b/server/start.go @@ -355,11 +355,6 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App app.RegisterNodeService(clientCtx) } - metrics, err := startTelemetry(config) - if err != nil { - return err - } - var apiSrv *api.Server if config.API.Enable { genDoc, err := genDocProvider() @@ -407,9 +402,6 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App apiSrv = api.New(clientCtx, ctx.Logger.With("module", "api-server")) app.RegisterAPIRoutes(apiSrv, config.API) - if config.Telemetry.Enabled { - apiSrv.SetTelemetry(metrics) - } errCh := make(chan error) go func() { From 66c4970fdcee6fe0af9227eadb4a4c2273412df6 Mon Sep 17 00:00:00 2001 From: Freddy Caceres Date: Thu, 24 Nov 2022 17:15:28 -0500 Subject: [PATCH 2/3] make setTelemetry private --- server/api/server.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/api/server.go b/server/api/server.go index 375739c60848..245cc55c836d 100644 --- a/server/api/server.go +++ b/server/api/server.go @@ -89,7 +89,7 @@ func (s *Server) Start(cfg config.Config) error { s.mtx.Lock() if cfg.Telemetry.Enabled { - if err := s.SetTelemetry(cfg); err != nil { + if err := s.setTelemetry(cfg); err != nil { s.mtx.Unlock() return err } @@ -133,7 +133,7 @@ func (s *Server) registerGRPCGatewayRoutes() { s.Router.PathPrefix("/").Handler(s.GRPCGatewayRouter) } -func (s *Server) SetTelemetry(cfg config.Config) error { +func (s *Server) setTelemetry(cfg config.Config) error { metrics, err := telemetry.New(cfg.Telemetry) if err != nil { return err From 0fe8543e307e03c26abe67f128cf575b267ab9af Mon Sep 17 00:00:00 2001 From: Freddy Caceres Date: Thu, 24 Nov 2022 17:19:11 -0500 Subject: [PATCH 3/3] update changelog --- CHANGELOG.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 703911130021..330d9fcd556e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -168,8 +168,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (types) [#13430](https://github.com/cosmos/cosmos-sdk/pull/13430) Remove unused code `ResponseCheckTx` and `ResponseDeliverTx` * (store) [#13529](https://github.com/cosmos/cosmos-sdk/pull/13529) Add method `LatestVersion` to `MultiStore` interface, add method `SetQueryMultiStore` to baesapp to support alternative `MultiStore` implementation for query service. * (pruning) [#13609](https://github.com/cosmos/cosmos-sdk/pull/13609) Move pruning package to be under store package -* [#13794](https://github.com/cosmos/cosmos-sdk/pull/13794) Most methods on `types/module.AppModule` have been moved to -extension interfaces. `module.Manager.Modules` is now of type `map[string]interface{}` to support in parallel the new +* [#13794](https://github.com/cosmos/cosmos-sdk/pull/13794) Most methods on `types/module.AppModule` have been moved to +extension interfaces. `module.Manager.Modules` is now of type `map[string]interface{}` to support in parallel the new `cosmossdk.io/core/appmodule.AppModule` API. * (x/group) [#13876](https://github.com/cosmos/cosmos-sdk/pull/13876) Add `GetMinExecutionPeriod` method on DecisionPolicy interface. * (x/auth)[#13780](https://github.com/cosmos/cosmos-sdk/pull/13780) Querying with `id` (type of int64) in `AccountAddressByID` grpc query now throws error, use account-id(type of uint64) instead. @@ -183,7 +183,7 @@ extension interfaces. `module.Manager.Modules` is now of type `map[string]interf * (x/upgrade) [#13936](https://github.com/cosmos/cosmos-sdk/pull/13936) Make downgrade verification work again * (x/group) [#13742](https://github.com/cosmos/cosmos-sdk/pull/13742) Fix `validate-genesis` when group policy accounts exist. -* (x/auth) [#13838](https://github.com/cosmos/cosmos-sdk/pull/13838) Fix calling `String()` and `MarshalYAML` panics when pubkey is set on a `BaseAccount`. +* (x/auth) [#13838](https://github.com/cosmos/cosmos-sdk/pull/13838) Fix calling `String()` and `MarshalYAML` panics when pubkey is set on a `BaseAccount`. * (rosetta) [#13583](https://github.com/cosmos/cosmos-sdk/pull/13583) Misc fixes for cosmos-rosetta. * (x/evidence) [#13740](https://github.com/cosmos/cosmos-sdk/pull/13740) Fix evidence query API to decode the hash properly. * (bank) [#13691](https://github.com/cosmos/cosmos-sdk/issues/13691) Fix unhandled error for vesting account transfers, when total vesting amount exceeds total balance. @@ -203,6 +203,7 @@ extension interfaces. `module.Manager.Modules` is now of type `map[string]interf * (server) [#13778](https://github.com/cosmos/cosmos-sdk/pull/13778) Set Cosmos SDK default endpoints to localhost to avoid unknown exposure of endpoints. * (x/auth) [#13877](https://github.com/cosmos/cosmos-sdk/pull/13877) Handle missing account numbers during `InitGenesis`. * (x/gov) [#13918](https://github.com/cosmos/cosmos-sdk/pull/13918) Fix propagation of message errors when executing a proposal. +* (server) [13997](https://github.com/cosmos/cosmos-sdk/pull/13997) Fix SDK metrics on startInProcess ### Deprecated