Skip to content

Commit

Permalink
feat(node): add telemetry via the cosmos SDK for basic activity on th…
Browse files Browse the repository at this point in the history
…e blockchain
  • Loading branch information
hydrogen18 authored Nov 26, 2020
1 parent 9ce6b96 commit 85f7ab5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions x/deployment/handler/endblock.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package handler

import (
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ovrclk/akash/x/deployment/keeper"
"github.com/ovrclk/akash/x/deployment/types"
Expand All @@ -18,6 +19,7 @@ func OnEndBlock(ctx sdk.Context, keeper keeper.Keeper, mkeeper MarketKeeper) {

// set state to ordered
keeper.OnOrderCreated(ctx, group)
telemetry.IncrCounter(1.0, "akash.order_created")
return false
})
}
2 changes: 2 additions & 0 deletions x/deployment/handler/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handler
import (
"bytes"
"context"
"github.com/cosmos/cosmos-sdk/telemetry"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/pkg/errors"
Expand Down Expand Up @@ -54,6 +55,7 @@ func (ms msgServer) CreateDeployment(goCtx context.Context, msg *types.MsgCreate
if err := ms.deployment.Create(ctx, deployment, groups); err != nil {
return nil, errors.Wrap(types.ErrInternal, err.Error())
}
telemetry.IncrCounter(1.0, "akash.deployment_created")

return &types.MsgCreateDeploymentResponse{}, nil
}
Expand Down
16 changes: 13 additions & 3 deletions x/market/handler/endblock.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package handler

import (
"github.com/cosmos/cosmos-sdk/telemetry"
validationConstants "github.com/ovrclk/akash/validation/constants"
"hash/fnv"
"sort"

Expand All @@ -23,7 +25,7 @@ func OnEndBlock(ctx sdk.Context, keepers Keepers) error {

func transferFundsForActiveLeases(ctx sdk.Context, keepers Keepers) error {
// for all active leases, transfer funds
count := 0
activeLeaseCount := 0
keepers.Market.WithActiveLeases(ctx, func(lease types.Lease) bool {

owner, err := sdk.AccAddressFromBech32(lease.ID().Owner)
Expand Down Expand Up @@ -56,11 +58,14 @@ func transferFundsForActiveLeases(ctx sdk.Context, keepers Keepers) error {
return false
}

count++
telemetry.IncrCounter(float32(amt.AmountOf(validationConstants.AkashDenom).Int64()), "akash.coins_xfer")

activeLeaseCount++
return false
})

ctx.Logger().Info("processed active leases", "count", count)
ctx.Logger().Info("processed active leases", "count", activeLeaseCount)
telemetry.SetGauge(float32(activeLeaseCount), "akash.active_leases")

return nil
}
Expand All @@ -74,6 +79,7 @@ func PickBidWinner(bids []types.Bid) (winner *types.Bid, err error) {
// So it can't be used to determine who bid first like a timestamp.
return bids[i].Price.IsLT(bids[j].Price)
})

switch len(bids) {
case 0:
// This is a fatal case
Expand Down Expand Up @@ -114,6 +120,7 @@ func PickBidWinner(bids []types.Bid) (winner *types.Bid, err error) {
// matchOrders that are open, picks a winning Bid, creates a Lease, and closes
// originating Order.
func matchOrders(ctx sdk.Context, keepers Keepers) error {
openOrdersCount := 0
keepers.Market.WithOpenOrders(ctx, func(order types.Order) bool {
if err := order.ValidateCanMatch(ctx.BlockHeight()); err != nil {
if errors.Is(err, types.ErrOrderDurationExceeded) {
Expand All @@ -122,6 +129,7 @@ func matchOrders(ctx sdk.Context, keepers Keepers) error {
}
return false
}
openOrdersCount++

var bids []types.Bid
keepers.Market.WithBidsForOrder(ctx, order.ID(), func(bid types.Bid) bool {
Expand Down Expand Up @@ -163,8 +171,10 @@ func matchOrders(ctx sdk.Context, keepers Keepers) error {

// notify group of match
keepers.Deployment.OnLeaseCreated(ctx, order.ID().GroupID())
telemetry.IncrCounter(1.0, "akash.lease_created")

return false
})
telemetry.SetGauge(float32(openOrdersCount), "akash.open_orders")
return nil
}
3 changes: 3 additions & 0 deletions x/market/handler/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package handler

import (
"context"
"github.com/cosmos/cosmos-sdk/telemetry"

sdk "github.com/cosmos/cosmos-sdk/types"

Expand Down Expand Up @@ -67,6 +68,7 @@ func (ms msgServer) CreateBid(goCtx context.Context, msg *types.MsgCreateBid) (*
return nil, err
}

telemetry.IncrCounter(1.0, "akash.bids")
return &types.MsgCreateBidResponse{}, nil
}

Expand Down Expand Up @@ -105,6 +107,7 @@ func (ms msgServer) CloseBid(goCtx context.Context, msg *types.MsgCloseBid) (*ty
ms.keepers.Market.OnLeaseClosed(ctx, lease)
ms.keepers.Market.OnOrderClosed(ctx, order)
ms.keepers.Deployment.OnLeaseClosed(ctx, order.ID().GroupID())
telemetry.IncrCounter(1.0, "akash.order_closed")

return &types.MsgCloseBidResponse{}, nil
}
Expand Down

0 comments on commit 85f7ab5

Please sign in to comment.