Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: switch the client for alerts from rpc to grpc for new kava version #72

Merged
merged 16 commits into from
Sep 26, 2024
Merged
19 changes: 15 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,28 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with: { fetch-depth: 0 }

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: '1.21'
go-version-file: go.mod

- name: Load Version
id: load-version
run: |
ls -lah
GOLANGCI_VERSION=$(cat .golangci-version)
REV=$(git merge-base origin/master HEAD)
echo "GOLANGCI_VERSION=$GOLANGCI_VERSION" >> $GITHUB_ENV
echo "REV=$REV" >> $GITHUB_ENV

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
args: --timeout=10m
version: ${{ env.GOLANGCI_VERSION }}
args: -v -c .golangci.yml --new-from-rev ${{ env.REV }}

integration-tests:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .golangci-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.59
137 changes: 137 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
run:
timeout: 20m # set maximum time allowed for the linter to run. If the linting process exceeds this duration, it will be terminated
modules-download-mode: readonly # Ensures that modules are not modified during the linting process
allow-parallel-runners: true # enables parallel execution of linters to speed up linting process
skip-dirs:
- vendor
- hard-keeper-bot # TODO(boodyvo): a lot of errors for old code, need to fix during the hard-keeper-bot update

linters:
disable-all: true
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- containedctx
- contextcheck
- decorder
- dogsled
# - dupl
# - dupword
- durationcheck
- errcheck
- errchkjson
- errname
- errorlint
# - exhaustive
- exportloopref
- funlen
- gci
- ginkgolinter
- gocheckcompilerdirectives
# - gochecknoglobals
# - gochecknoinits
- goconst
- gocritic
- godox
- gofmt
# - gofumpt
- goheader
- goimports
- mnd
# - gomodguard
- goprintffuncname
- gosec
- gosimple
- govet
- grouper
- importas
- ineffassign
# - interfacebloat
- lll
- loggercheck
- makezero
- mirror
- misspell
- musttag
# - nakedret
# - nestif
- nilerr
# - nilnil
# - noctx
- nolintlint
# - nonamedreturns
- nosprintfhostport
- prealloc
- predeclared
- promlinter
# - reassign
- revive
- rowserrcheck
- staticcheck
# - stylecheck
- tagalign
# - testpackage
# - thelper
# - tparallel
- typecheck
# - unconvert
- unparam
- unused
# - usestdlibvars
- wastedassign
# - whitespace
- wrapcheck

issues:
exclude-rules:
# Disable funlen for "func Test..." or func (suite *Suite) Test..." type functions
# These functions tend to be descriptive and exceed length limits.
- source: "^func (\\(.*\\) )?Test"
linters:
- funlen

linters-settings:
errcheck:
check-blank: true # check for assignments to the blank identifier '_' when errors are returned
check-type-assertions: false # check type assertion
errorlint:
check-generated: false # disabled linting of generated files
default-signifies-exhaustive: false # exhaustive handling of error types
exhaustive:
default-signifies-exhaustive: false # exhaustive handling of error types
gci:
sections: # defines the order of import sections
- standard
- default
- localmodule
goconst:
min-len: 3 # min length for string constants to be checked
min-occurrences: 3 # min occurrences of the same constant before it's flagged
godox:
keywords: # specific keywords to flag for further action
- BUG
- FIXME
- HACK
gosec:
exclude-generated: true
lll:
line-length: 120
misspell:
locale: US
ignore-words: expect
nolintlint:
allow-leading-space: false
require-explanation: true
require-specific: true
prealloc:
simple: true # enables simple preallocation checks
range-loops: true # enabled preallocation checks in range loops
for-loops: false # disables preallocation checks in for loops
unparam:
check-exported: true # checks exported functions and methods for unused params
revive:
rules:
- name: unused-parameter
severity: error
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ vet:
go vet ./...

.PHONY: test
# Find all directories containing go.mod, and run go test for each module, excluding auction-audit
test:
go test -v ./...
find . -name "go.mod" -not -path "*/vendor/*" -not -path "*/auction-audit/*" -exec dirname {} \; | \
while read dir; do \
echo "Running tests in $$dir..."; \
(cd $$dir && go test ./... -v) || exit 1; \
done


.PHONY: test-integration
test-integration:
Expand Down
6 changes: 4 additions & 2 deletions alerts/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
FROM golang:1.20-bullseye as build-env
FROM golang:1.21.9-bullseye AS build-env

ADD . /src
RUN cd /src && go build -o /alerts
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
cd /src && go build -o /alerts

FROM debian:bullseye

Expand Down
25 changes: 25 additions & 0 deletions alerts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,28 @@ make install

AWS_PROFILE=development $GOPATH/bin/alerts usdx run
```

## Alerts

### Auction

Auction alerts tracks ongoing auctions on the Kava Chain and alerts for:

- Total value of auctions above configured value
- Percentage price deviation of auction clearing price above configured value

Runs with:
```bash
go run . auctions run
```

### USDX

USDX alerts tracks the USDX price on the Kava Chain and alerts for:

- Price deviation of USDX below configured value

Runs with:
```bash
go run . usdx run
```
4 changes: 2 additions & 2 deletions alerts/auctions/calc.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ func CalculateTotalAuctionsUSDValue(data *AuctionData) (sdk.Dec, error) {
return totalValue, nil
}

// calculateUSDValue calculates the USD value of a given Coin and AssetInfo
// CalculateUSDValue calculates the USD value of a given Coin and AssetInfo
func CalculateUSDValue(coin sdk.Coin, assetInfo AssetInfo) sdk.Dec {
return coin.Amount.ToDec().Quo(assetInfo.ConversionFactor.ToDec()).Mul(assetInfo.Price)
return coin.Amount.ToLegacyDec().Quo(assetInfo.ConversionFactor.ToLegacyDec()).Mul(assetInfo.Price)
}

func CheckInefficientAuctions(data *AuctionData, thresholdUSD, thresholdRatio sdk.Dec, thresholdTime time.Duration) ([]auctiontypes.Auction, error) {
Expand Down
21 changes: 21 additions & 0 deletions alerts/auctions/calc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package auctions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a readme to this folder?

Auction alerts tracks ongoing auctions on the Kava Chain and alerts for:

  • Total value of auctions above configured value
  • Percentage price deviation of auction clearing price above configured value
  • Price deviation of USDX below configured value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to the module README.md as those alerts you described are actually 2 different services (one for auctions and one for usdx)


import (
sdk "github.com/cosmos/cosmos-sdk/types"
"testing"

"github.com/stretchr/testify/require"
)

func TestAuctionsTotal(t *testing.T) {
usdValue, err := sdk.NewDecFromStr("0.000001705763333334")
require.NoError(t, err)

data, err := getAuctionDataAtHeight(dataQueryClient, 11800020)
require.NoError(t, err)

totalValue, err := CalculateTotalAuctionsUSDValue(data)
require.NoError(t, err)

require.True(t, totalValue.Equal(usdValue))
}
Loading
Loading