Skip to content

Commit

Permalink
[STAB-29] Pass in version/commit in dev/staging, shift app_info metri…
Browse files Browse the repository at this point in the history
…cs to begin blocker (#232)

* shift metrics to begin blocker

* change build to properly pass in version and commit flags

* VERSION instead of TAG_VERSION

* update other locations in code

* fix imports

* import
  • Loading branch information
jonfung-dydx authored Sep 18, 2023
1 parent 50dd06a commit d66436a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 78 deletions.
30 changes: 6 additions & 24 deletions .github/workflows/protocol-build-and-push-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ jobs:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: dev-validator-snapshot
run: |
DOCKER_BUILDKIT=1 docker build \
--platform amd64 \
-t dydxprotocol-base \
-f Dockerfile .
make localnet-build-amd64
commit_hash=$(git rev-parse --short=7 HEAD)
docker build \
--platform amd64 \
Expand Down Expand Up @@ -75,10 +72,7 @@ jobs:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: dev2-validator-snapshot
run: |
DOCKER_BUILDKIT=1 docker build \
--platform amd64 \
-t dydxprotocol-base \
-f Dockerfile .
make localnet-build-amd64
commit_hash=$(git rev-parse --short=7 HEAD)
docker build \
--platform amd64 \
Expand Down Expand Up @@ -114,10 +108,7 @@ jobs:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: dev3-validator-snapshot
run: |
DOCKER_BUILDKIT=1 docker build \
--platform amd64 \
-t dydxprotocol-base \
-f Dockerfile .
make localnet-build-amd64
commit_hash=$(git rev-parse --short=7 HEAD)
docker build \
--platform amd64 \
Expand Down Expand Up @@ -153,10 +144,7 @@ jobs:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: dev4-validator-snapshot
run: |
DOCKER_BUILDKIT=1 docker build \
--platform amd64 \
-t dydxprotocol-base \
-f Dockerfile .
make localnet-build-amd64
commit_hash=$(git rev-parse --short=7 HEAD)
docker build \
--platform amd64 \
Expand Down Expand Up @@ -192,10 +180,7 @@ jobs:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: dev5-validator-snapshot
run: |
DOCKER_BUILDKIT=1 docker build \
--platform amd64 \
-t dydxprotocol-base \
-f Dockerfile .
make localnet-build-amd64
commit_hash=$(git rev-parse --short=7 HEAD)
docker build \
--platform amd64 \
Expand Down Expand Up @@ -231,10 +216,7 @@ jobs:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: staging-validator-snapshot
run: |
DOCKER_BUILDKIT=1 docker build \
--platform amd64 \
-t dydxprotocol-base \
-f Dockerfile .
make localnet-build-amd64
commit_hash=$(git rev-parse --short=7 HEAD)
docker build \
--platform amd64 \
Expand Down
30 changes: 6 additions & 24 deletions .github/workflows/protocol-build-and-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ jobs:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: dev-validator
run: |
DOCKER_BUILDKIT=1 docker build \
--platform amd64 \
-t dydxprotocol-base \
-f Dockerfile .
make localnet-build-amd64
commit_hash=$(git rev-parse --short=7 HEAD)
docker build \
--platform amd64 \
Expand Down Expand Up @@ -76,10 +73,7 @@ jobs:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: dev2-validator
run: |
DOCKER_BUILDKIT=1 docker build \
--platform amd64 \
-t dydxprotocol-base \
-f Dockerfile .
make localnet-build-amd64
commit_hash=$(git rev-parse --short=7 HEAD)
docker build \
--platform amd64 \
Expand Down Expand Up @@ -115,10 +109,7 @@ jobs:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: dev3-validator
run: |
DOCKER_BUILDKIT=1 docker build \
--platform amd64 \
-t dydxprotocol-base \
-f Dockerfile .
make localnet-build-amd64
commit_hash=$(git rev-parse --short=7 HEAD)
docker build \
--platform amd64 \
Expand Down Expand Up @@ -154,10 +145,7 @@ jobs:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: dev4-validator
run: |
DOCKER_BUILDKIT=1 docker build \
--platform amd64 \
-t dydxprotocol-base \
-f Dockerfile .
make localnet-build-amd64
commit_hash=$(git rev-parse --short=7 HEAD)
docker build \
--platform amd64 \
Expand Down Expand Up @@ -193,10 +181,7 @@ jobs:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: dev5-validator
run: |
DOCKER_BUILDKIT=1 docker build \
--platform amd64 \
-t dydxprotocol-base \
-f Dockerfile .
make localnet-build-amd64
commit_hash=$(git rev-parse --short=7 HEAD)
docker build \
--platform amd64 \
Expand Down Expand Up @@ -232,10 +217,7 @@ jobs:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: staging-validator
run: |
DOCKER_BUILDKIT=1 docker build \
--platform amd64 \
-t dydxprotocol-base \
-f Dockerfile .
make localnet-build-amd64
commit_hash=$(git rev-parse --short=7 HEAD)
docker build \
--platform amd64 \
Expand Down
8 changes: 5 additions & 3 deletions protocol/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ PROJECT_NAME := $(shell git remote get-url origin | xargs basename -s .git)
CGO_ENABLED=1
export GIT_COMMIT_HASH=$(shell git rev-parse --short HEAD)
export COMMIT=$(shell git rev-parse HEAD)
export TAG_VERSION=$(shell git describe --tags | sed 's/^protocol\/v//')

export GO111MODULE = on

Expand Down Expand Up @@ -341,10 +340,13 @@ proto-download-deps:
###############################################################################

localnet-new-validator:
@docker run --rm -it $(shell docker build --build-arg VERSION=$(TAG_VERSION) --build-arg COMMIT=$(COMMIT) . -t dydxprotocol-base && docker build . -q -f ./testing/util/Dockerfile)
@docker run --rm -it $(shell docker build --build-arg VERSION=$(VERSION) --build-arg COMMIT=$(COMMIT) . -t dydxprotocol-base && docker build . -q -f ./testing/util/Dockerfile)

localnet-build:
docker build --build-arg VERSION=$(TAG_VERSION) --build-arg COMMIT=$(COMMIT) . -t dydxprotocol-base --no-cache
docker build --build-arg VERSION=$(VERSION) --build-arg COMMIT=$(COMMIT) . -t dydxprotocol-base --no-cache

localnet-build-amd64:
DOCKER_BUILDKIT=1 docker build --build-arg VERSION=$(VERSION) --build-arg COMMIT=$(COMMIT) -f Dockerfile . -t dydxprotocol-base --no-cache --platform linux/amd64

localnet-init:
rm -rf localnet
Expand Down
28 changes: 24 additions & 4 deletions protocol/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ package app
import (
"context"
"encoding/json"
"github.com/dydxprotocol/v4-chain/protocol/app/stoppable"
daemonservertypes "github.com/dydxprotocol/v4-chain/protocol/daemons/server/types"
"github.com/dydxprotocol/v4-chain/protocol/lib"
"github.com/dydxprotocol/v4-chain/protocol/x/clob/rate_limit"
"io"
"net/http"
"os"
"path/filepath"
"strings"

"github.com/dydxprotocol/v4-chain/protocol/app/stoppable"
daemonservertypes "github.com/dydxprotocol/v4-chain/protocol/daemons/server/types"
"github.com/dydxprotocol/v4-chain/protocol/lib"
"github.com/dydxprotocol/v4-chain/protocol/x/clob/rate_limit"

gometrics "github.com/armon/go-metrics"
"github.com/dydxprotocol/v4-chain/protocol/lib/metrics"

pricefeed_types "github.com/dydxprotocol/v4-chain/protocol/daemons/pricefeed/types"

Expand All @@ -37,6 +42,7 @@ import (
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
Expand Down Expand Up @@ -1169,6 +1175,20 @@ func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.R
proposerAddr := sdk.ConsAddress(req.Header.ProposerAddress)
middleware.Logger = ctx.Logger().With("proposer_cons_addr", proposerAddr.String())

// Report app version and git commit if not in dev. Delay by 100 blocks to get a metric on initial startup.
// TODO(DEC-2107): Doing this based on chain id seems brittle.
if !strings.Contains(req.Header.ChainID, "dev") && ctx.BlockHeight()%10_100 == 0 {
version := version.NewInfo()
telemetry.SetGaugeWithLabels(
[]string{metrics.AppInfo},
1,
[]gometrics.Label{
metrics.GetLabelForStringValue(metrics.AppVersion, version.Version),
metrics.GetLabelForStringValue(metrics.GitCommit, version.GitCommit),
},
)
}

app.scheduleForkUpgrade(ctx)
return app.ModuleManager.BeginBlock(ctx, req)
}
Expand Down
19 changes: 0 additions & 19 deletions protocol/cmd/dydxprotocold/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import (
"io"
"os"
"path/filepath"
"strings"

rosettaCmd "cosmossdk.io/tools/rosetta/cmd"

gometrics "github.com/armon/go-metrics"
dbm "github.com/cometbft/cometbft-db"
tmcli "github.com/cometbft/cometbft/libs/cli"
"github.com/cometbft/cometbft/libs/log"
Expand All @@ -26,9 +24,7 @@ import (
"github.com/cosmos/cosmos-sdk/snapshots"
snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types"
"github.com/cosmos/cosmos-sdk/store"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
"github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
Expand All @@ -39,7 +35,6 @@ import (
dydxapp "github.com/dydxprotocol/v4-chain/protocol/app"
"github.com/dydxprotocol/v4-chain/protocol/app/basic_manager"
"github.com/dydxprotocol/v4-chain/protocol/app/params"
"github.com/dydxprotocol/v4-chain/protocol/lib/metrics"
"github.com/spf13/cast"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -272,20 +267,6 @@ func (a appCreator) newApp(
cast.ToUint32(appOpts.Get(server.FlagStateSyncSnapshotKeepRecent)),
)

// Report app version and git commit if not in dev
// TODO(DEC-2107): Doing this based on chain id seems brittle.
if !strings.Contains(chainID, "dev") {
version := version.NewInfo()
telemetry.SetGaugeWithLabels(
[]string{metrics.AppInfo},
1,
[]gometrics.Label{
metrics.GetLabelForStringValue(metrics.AppVersion, version.Version),
metrics.GetLabelForStringValue(metrics.GitCommit, version.GitCommit),
},
)
}

return dydxapp.New(
logger,
db,
Expand Down
5 changes: 1 addition & 4 deletions protocol/scripts/build-push-ecr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ ecr="$aws_account.dkr.ecr.us-east-2.amazonaws.com/$ecr_repo"
current_time=$(date '+%Y%m%d%H%M')
commit_hash=$(git rev-parse --short=7 HEAD)

DOCKER_BUILDKIT=1 docker build \
--platform linux/amd64 \
-t dydxprotocol-base \
-f Dockerfile .
make localnet-build-amd64

docker_tag="$ecr:$current_time-$commit_hash-test-build"
docker_file="testing/testnet-dev/Dockerfile"
Expand Down

0 comments on commit d66436a

Please sign in to comment.