Skip to content

Commit

Permalink
fix(bridge-history): add cache hit tracing logs (#972)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinlyguo authored Sep 27, 2023
1 parent 7604612 commit 47e5a43
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 8 additions & 0 deletions bridge-history-api/internal/controller/history_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func (c *HistoryController) GetAllClaimableTxsByAddr(ctx *gin.Context) {
cacheKey := cacheKeyPrefixClaimableTxsByAddr + req.Address
if cachedData, found := c.cache.Get(cacheKey); found {
c.cacheMetrics.cacheHits.WithLabelValues("GetAllClaimableTxsByAddr").Inc()
// Log cache hit along with request param.
log.Info("cache hit", "request", req)
if cachedData == nil {
types.RenderSuccess(ctx, &types.ResultData{})
return
Expand All @@ -60,6 +62,8 @@ func (c *HistoryController) GetAllClaimableTxsByAddr(ctx *gin.Context) {
log.Error("unexpected type in cache", "expected", "*types.ResultData", "got", reflect.TypeOf(cachedData))
} else {
c.cacheMetrics.cacheMisses.WithLabelValues("GetAllClaimableTxsByAddr").Inc()
// Log cache miss along with request param.
log.Info("cache miss", "request", req)
}

result, err, _ := c.singleFlight.Do(cacheKey, func() (interface{}, error) {
Expand Down Expand Up @@ -110,6 +114,8 @@ func (c *HistoryController) PostQueryTxsByHash(ctx *gin.Context) {
cacheKey := cacheKeyPrefixQueryTxsByHash + hash
if cachedData, found := c.cache.Get(cacheKey); found {
c.cacheMetrics.cacheHits.WithLabelValues("PostQueryTxsByHash").Inc()
// Log cache hit along with tx hash.
log.Info("cache hit", "tx hash", hash)
if cachedData == nil {
continue
} else if txInfo, ok := cachedData.(*types.TxHistoryInfo); ok {
Expand All @@ -120,6 +126,8 @@ func (c *HistoryController) PostQueryTxsByHash(ctx *gin.Context) {
}
} else {
c.cacheMetrics.cacheMisses.WithLabelValues("PostQueryTxsByHash").Inc()
// Log cache miss along with tx hash.
log.Info("cache miss", "tx hash", hash)
uncachedHashes = append(uncachedHashes, hash)
}
}
Expand Down
4 changes: 1 addition & 3 deletions bridge-history-api/internal/types/history_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ const (

// QueryByAddressRequest the request parameter of address api
type QueryByAddressRequest struct {
Address string `form:"address" binding:"required"`
Page int `form:"page,default=1"`
PageSize int `form:"page_size,default=10"`
Address string `form:"address" binding:"required"`
}

// QueryByHashRequest the request parameter of hash api
Expand Down
2 changes: 1 addition & 1 deletion common/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"runtime/debug"
)

var tag = "v4.3.25"
var tag = "v4.3.26"

var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
Expand Down

0 comments on commit 47e5a43

Please sign in to comment.