Skip to content

Commit

Permalink
Merge branch 'main' into alex/systemtests_pkg
Browse files Browse the repository at this point in the history
* main:
  fix(server/v2/api/telemetry): enable global metrics  (#22571)
  • Loading branch information
alpe committed Nov 21, 2024
2 parents 1576df5 + b45cf75 commit 9fe3682
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
10 changes: 9 additions & 1 deletion server/v2/api/telemetry/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Server[T transaction.Tx] struct {
}

// New creates a new telemetry server.
func New[T transaction.Tx](cfg server.ConfigMap, logger log.Logger) (*Server[T], error) {
func New[T transaction.Tx](cfg server.ConfigMap, logger log.Logger, enableTelemetry func()) (*Server[T], error) {
srv := &Server[T]{}
serverCfg := srv.Config().(*Config)
if len(cfg) > 0 {
Expand All @@ -39,6 +39,14 @@ func New[T transaction.Tx](cfg server.ConfigMap, logger log.Logger) (*Server[T],
srv.config = serverCfg
srv.logger = logger.With(log.ModuleKey, srv.Name())

if enableTelemetry == nil {
panic("enableTelemetry must be provided")
}

if srv.config.Enable {
enableTelemetry()
}

metrics, err := NewMetrics(srv.config)
if err != nil {
return nil, fmt.Errorf("failed to initialize metrics: %w", err)
Expand Down
3 changes: 2 additions & 1 deletion simapp/v2/simdv2/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/debug"
"github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/client/rpc"
sdktelemetry "github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
"github.com/cosmos/cosmos-sdk/x/genutil"
Expand Down Expand Up @@ -118,7 +119,7 @@ func InitRootCmd[T transaction.Tx](
}
}

telemetryServer, err := telemetry.New[T](deps.GlobalConfig, logger)
telemetryServer, err := telemetry.New[T](deps.GlobalConfig, logger, sdktelemetry.EnableTelemetry)
if err != nil {
return nil, err
}
Expand Down
5 changes: 5 additions & 0 deletions telemetry/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ func IsTelemetryEnabled() bool {
return globalTelemetryEnabled
}

// EnableTelemetry allows for the global telemetry enabled state to be set.
func EnableTelemetry() {
globalTelemetryEnabled = true
}

// globalLabels defines the set of global labels that will be applied to all
// metrics emitted using the telemetry package function wrappers.
var globalLabels = []metrics.Label{}
Expand Down

0 comments on commit 9fe3682

Please sign in to comment.