Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion bridge-history-api/cmd/api/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app
import (
"crypto/tls"
"fmt"
"net/http"
"os"
"os/signal"
"time"
Expand Down Expand Up @@ -79,7 +80,13 @@ func action(ctx *cli.Context) error {

go func() {
port := ctx.Int(utils.ServicePortFlag.Name)
if runServerErr := router.Run(fmt.Sprintf(":%d", port)); runServerErr != nil {
server := &http.Server{
Addr: fmt.Sprintf(":%d", port),
Handler: router,
ReadHeaderTimeout: 10 * time.Second,
ReadTimeout: 30 * time.Second,
}
if runServerErr := server.ListenAndServe(); runServerErr != nil {
log.Crit("run http server failure", "error", runServerErr)
}
}()
Expand Down
2 changes: 1 addition & 1 deletion bridge-history-api/internal/logic/history_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ func (h *HistoryLogic) processAndCacheTxHistoryInfo(ctx context.Context, cacheKe

if !isHit {
log.Error("cache miss after write, expect hit", "cached key", cacheKey, "page", page, "page size", pageSize, "error", err)
return nil, 0, err
return nil, 0, errors.New("cache miss after write")
}

return pagedTxs, total, nil
Expand Down
2 changes: 1 addition & 1 deletion bridge-history-api/internal/types/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const (
// QueryByAddressRequest the request parameter of address api
type QueryByAddressRequest struct {
Address string `form:"address" binding:"required,eth_addr"`
Page uint64 `form:"page" binding:"required,min=1"`
Page uint64 `form:"page" binding:"required,min=1,max=10000"`
PageSize uint64 `form:"page_size" binding:"required,min=1,max=100"`
}

Expand Down
16 changes: 14 additions & 2 deletions common/observability/ginmetrics/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ginmetrics

import (
"fmt"
"net/http"
"strconv"
"time"

Expand Down Expand Up @@ -131,7 +132,7 @@ func (m *Monitor) ginMetricHandle(ctx *gin.Context, start time.Time) {
}

// set uri request total
_ = m.GetMetric(metricURIRequestTotal).Inc([]string{ctx.FullPath(), r.Method, errCode})
_ = m.GetMetric(metricURIRequestTotal).Inc([]string{ctx.FullPath(), metricMethod(r.Method), errCode})

// set request body size
// since r.ContentLength can be negative (in some occasions) guard the operation
Expand All @@ -142,7 +143,7 @@ func (m *Monitor) ginMetricHandle(ctx *gin.Context, start time.Time) {
// set slow request
latency := time.Since(start)
if int32(latency.Seconds()) > m.slowTime {
_ = m.GetMetric(metricSlowRequest).Inc([]string{ctx.FullPath(), r.Method, strconv.Itoa(w.Status())})
_ = m.GetMetric(metricSlowRequest).Inc([]string{ctx.FullPath(), metricMethod(r.Method), strconv.Itoa(w.Status())})
}

// set request duration
Expand All @@ -153,3 +154,14 @@ func (m *Monitor) ginMetricHandle(ctx *gin.Context, start time.Time) {
_ = m.GetMetric(metricResponseBody).Add(nil, float64(w.Size()))
}
}

// metricMethod bounds the method label, since clients can send any method token.
func metricMethod(method string) string {
switch method {
case http.MethodGet, http.MethodHead, http.MethodPost, http.MethodPut, http.MethodPatch,
http.MethodDelete, http.MethodConnect, http.MethodOptions, http.MethodTrace:
return method
default:
return "OTHER"
}
}
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.8.2"
var tag = "v4.8.3"

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