Skip to content

Commit

Permalink
feat: useful makefiles and cache metrix fix (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
p0mvn authored Jan 4, 2024
1 parent f6712ad commit db33011
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 15 deletions.
31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,34 @@ docker-build:
--build-arg GIT_VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(COMMIT) \
-f Dockerfile .


###############################################################################
### Utils ###
###############################################################################

load-test-ui:
docker compose -f locust/docker-compose.yml up --scale worker=4

profile:
go tool pprof -http=:8080 http://localhost:9092/debug/pprof/profile?seconds=15

# Validates that SQS concentrated liquidity pool state is
# consistent with the state of the chain.
validate-cl-state:
scripts/validate-cl-state.sh "http://localhost:9092"

# Compares the quotes between SQS and chain over pool 1136
# which is concentrated.
quote-compare:
scripts/quote.sh "http://localhost:9092"

sqs-quote-compare-stage:
ingest/sqs/scripts/quote.sh "http://165.227.168.61"

# Updates go tests with the latest mainnet state
# Make sure that the node is running locally
sqs-update-mainnet-state:
curl -X POST "http:/localhost:9092/router/store-state"
mv pools.json router/usecase/routertesting/parsing/pools.json
mv taker_fees.json router/usecase/routertesting/parsing/taker_fees.json
19 changes: 9 additions & 10 deletions locust/locustfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,35 @@ class SQS(HttpUser):

@task
def all_pools(self):
self.client.get("/all-pools")
self.client.get("/pools/all")

# Quote the same pair of UOSMO and USDC (UOSMO in) while progressively
# increasing the amount of the tokenIn per endpoint.

@task
def quoteUOSMOUSDC_1In(self):
self.client.get(f"/quote?tokenIn=1000000{UOSMO}&tokenOutDenom={USDC}")
self.client.get(f"/router/quote?tokenIn=1000000{UOSMO}&tokenOutDenom={USDC}")

@task
def quoteUOSMOUSDC_1000In(self):
self.client.get(f"/quote?tokenIn=1000000000{UOSMO}&tokenOutDenom={USDC}")
self.client.get(f"/router/quote?tokenIn=1000000000{UOSMO}&tokenOutDenom={USDC}")

@task
def quoteUOSMOUSDC_1000000In(self):
self.client.get(f"/quote?tokenIn=1000000000000{UOSMO}&tokenOutDenom={USDC}")
self.client.get(f"/router/quote?tokenIn=1000000000000{UOSMO}&tokenOutDenom={USDC}")

@task
def singleQuoteUOSMOUSDC_1000000In(self):
self.client.get(f"/single-quote?tokenIn=1000000000000{UOSMO}&tokenOutDenom={USDC}")
self.client.get(f"/router/single-quote?tokenIn=1000000000000{UOSMO}&tokenOutDenom={USDC}")

# Quote the same pair of UOSMO and USDC (USDC in).
@task
def quoteUSDCUOSMO_1000000In(self):
self.client.get(f"/quote?tokenIn=100000000000{USDC}&tokenOutDenom={UOSMO}")
self.client.get(f"/router/quote?tokenIn=100000000000{USDC}&tokenOutDenom={UOSMO}")

@task
def quoteUSDCTUMEE_3000IN(self):
self.client.get(f"/quote?tokenIn=3000000000{USDT}&tokenOutDenom={UMEE}")
self.client.get(f"/router/quote?tokenIn=3000000000{USDT}&tokenOutDenom={UMEE}")

@task
def routesUOSMOUSDC(self):
Expand All @@ -77,8 +77,7 @@ def routesUOSMOUSDC(self):

@task
def routesUSDCUOSMO(self):
self.client.get(f"/routes?tokenIn={USDC}&tokenOutDenom={UOSMO}")
self.client.get(f"/router/routes?tokenIn={USDC}&tokenOutDenom={UOSMO}")

# TODO:
# Add tests for routes search

# Add tests for routes search
3 changes: 1 addition & 2 deletions middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import (
"time"

"github.com/labstack/echo"
"github.com/osmosis-labs/sqs/domain"
"github.com/prometheus/client_golang/prometheus"

"github.com/osmosis-labs/osmosis/v21/ingest/sqs/domain"
)

// GoMiddleware represent the data-struct for middleware
Expand Down
16 changes: 13 additions & 3 deletions router/usecase/router_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/prometheus/client_golang/prometheus"
"go.uber.org/zap"

"github.com/osmosis-labs/osmosis/osmomath"
poolmanagertypes "github.com/osmosis-labs/osmosis/v21/x/poolmanager/types"
"github.com/osmosis-labs/sqs/domain"
"github.com/osmosis-labs/sqs/domain/cache"
"github.com/osmosis-labs/sqs/domain/mvc"
Expand All @@ -18,9 +20,6 @@ import (
"github.com/osmosis-labs/sqs/router/usecase/routertesting/parsing"
"github.com/osmosis-labs/sqs/sqsdomain"
routerredisrepo "github.com/osmosis-labs/sqs/sqsdomain/repository/redis/router"

"github.com/osmosis-labs/osmosis/osmomath"
poolmanagertypes "github.com/osmosis-labs/osmosis/v21/x/poolmanager/types"
)

var _ mvc.RouterUsecase = &routerUseCaseImpl{}
Expand Down Expand Up @@ -485,8 +484,17 @@ func (r *routerUseCaseImpl) handleCandidateRoutes(ctx context.Context, router *R

r.logger.Debug("cached routes", zap.Int("num_routes", len(candidateRoutes.Routes)))

// Get request path for metrics
requestURLPath, err := domain.GetURLPathFromContext(ctx)
if err != nil {
return sqsdomain.CandidateRoutes{}, err
}

// If no routes are cached, find them
if len(candidateRoutes.Routes) == 0 {
// Increase cache misses
cacheMisses.WithLabelValues(requestURLPath, candidateRouteCacheLabel, tokenInDenom, tokenOutDenom).Inc()

r.logger.Debug("calculating routes")
allPools, err := r.poolsUsecase.GetAllPools(ctx)
if err != nil {
Expand All @@ -509,6 +517,8 @@ func (r *routerUseCaseImpl) handleCandidateRoutes(ctx context.Context, router *R
return sqsdomain.CandidateRoutes{}, err
}
}
} else {
cacheHits.WithLabelValues(requestURLPath, candidateRouteCacheLabel, tokenInDenom, tokenOutDenom).Inc()
}

return candidateRoutes, nil
Expand Down

0 comments on commit db33011

Please sign in to comment.