Skip to content

Commit

Permalink
feat: emit more data in prom metrics (#15657)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhanusaputra authored Apr 6, 2023
1 parent b2c8418 commit 17debf2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/bank) [#14894](https://github.com/cosmos/cosmos-sdk/pull/14894) Return a human readable denomination for IBC vouchers when querying bank balances. Added a `ResolveDenom` parameter to `types.QueryAllBalancesRequest` and `--resolve-denom` flag to `GetBalancesCmd()`.
* (x/gov) [#15151](https://github.com/cosmos/cosmos-sdk/pull/15151) Add `burn_vote_quorum`, `burn_proposal_deposit_prevote` and `burn_vote_veto` params to allow applications to decide if they would like to burn deposits
* (runtime) [#15547](https://github.com/cosmos/cosmos-sdk/pull/15547) Allow runtime to pass event core api service to modules
* (telemetry) [#15657](https://github.com/cosmos/cosmos-sdk/pull/15657) Emit more data (go version, sdk version, upgrade height) in prom metrics

### Improvements

Expand Down
25 changes: 25 additions & 0 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"runtime/pprof"

pruningtypes "cosmossdk.io/store/pruning/types"
"github.com/armon/go-metrics"
"github.com/cometbft/cometbft/abci/server"
cmtcmd "github.com/cometbft/cometbft/cmd/cometbft/commands"
"github.com/cometbft/cometbft/node"
Expand All @@ -32,6 +33,7 @@ import (
"github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/telemetry"
"github.com/cosmos/cosmos-sdk/types/mempool"
"github.com/cosmos/cosmos-sdk/version"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
)

Expand Down Expand Up @@ -225,6 +227,8 @@ func startStandAlone(svrCtx *Context, appCreator types.AppCreator) error {
return err
}

emitServerInfoMetrics()

svr, err := server.NewServer(addr, transport, app)
if err != nil {
return fmt.Errorf("error creating listener: %v", err)
Expand Down Expand Up @@ -354,6 +358,8 @@ func startInProcess(svrCtx *Context, clientCtx client.Context, appCreator types.
return err
}

emitServerInfoMetrics()

var (
apiSrv *api.Server
grpcSrv *grpc.Server
Expand Down Expand Up @@ -505,3 +511,22 @@ func wrapCPUProfile(svrCtx *Context, callbackFn func() error) error {

return <-errCh
}

// emitServerInfoMetrics emits server info related metrics using application telemetry.
func emitServerInfoMetrics() {
var ls []metrics.Label

versionInfo := version.NewInfo()
if len(versionInfo.GoVersion) > 0 {
ls = append(ls, telemetry.NewLabel("go", versionInfo.GoVersion))
}
if len(versionInfo.CosmosSdkVersion) > 0 {
ls = append(ls, telemetry.NewLabel("version", versionInfo.CosmosSdkVersion))
}

if len(ls) == 0 {
return
}

telemetry.SetGaugeWithLabels([]string{"server", "info"}, 1, ls)
}
13 changes: 12 additions & 1 deletion x/upgrade/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"path"
"path/filepath"
"sort"
"strconv"

errorsmod "cosmossdk.io/errors"
"cosmossdk.io/log"
Expand All @@ -16,7 +17,9 @@ import (
xp "cosmossdk.io/x/upgrade/exported"
"cosmossdk.io/x/upgrade/types"

"github.com/armon/go-metrics"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/kv"
Expand Down Expand Up @@ -46,7 +49,7 @@ type Keeper struct {
// homePath - root directory of the application's config
// vs - the interface implemented by baseapp which allows setting baseapp's protocol version field
func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey storetypes.StoreKey, cdc codec.BinaryCodec, homePath string, vs xp.ProtocolVersionSetter, authority string) *Keeper {
return &Keeper{
k := &Keeper{
homePath: homePath,
skipUpgradeHeights: skipUpgradeHeights,
storeKey: storeKey,
Expand All @@ -55,6 +58,12 @@ func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey storetypes.StoreKey,
versionSetter: vs,
authority: authority,
}

if upgradePlan, err := k.ReadUpgradeInfoFromDisk(); err == nil && upgradePlan.Height > 0 {
telemetry.SetGaugeWithLabels([]string{"server", "info"}, 1, []metrics.Label{telemetry.NewLabel("upgrade_height", strconv.FormatInt(upgradePlan.Height, 10))})
}

return k
}

// SetVersionSetter sets the interface implemented by baseapp which allows setting baseapp's protocol version field
Expand Down Expand Up @@ -217,6 +226,8 @@ func (k Keeper) ScheduleUpgrade(ctx sdk.Context, plan types.Plan) error {
bz := k.cdc.MustMarshal(&plan)
store.Set(types.PlanKey(), bz)

telemetry.SetGaugeWithLabels([]string{"server", "info"}, 1, []metrics.Label{telemetry.NewLabel("upgrade_height", strconv.FormatInt(plan.Height, 10))})

return nil
}

Expand Down

0 comments on commit 17debf2

Please sign in to comment.