Skip to content

Commit

Permalink
only reason
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaojianli committed Jan 26, 2025
1 parent 8f33a50 commit 57ffad0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
10 changes: 2 additions & 8 deletions biz/handler/announce.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package handler

import (
"context"
"encoding/hex"
"errors"
"math/rand"

Expand All @@ -13,7 +12,6 @@ import (
"github.com/PBH-BTN/trunker/service/metrics"
"github.com/PBH-BTN/trunker/utils"
"github.com/PBH-BTN/trunker/utils/bencode"
"github.com/PBH-BTN/trunker/utils/conv"
"github.com/PBH-BTN/trunker/utils/http"
"github.com/cloudwego/hertz/pkg/app"
hertz "github.com/cloudwego/hertz/pkg/common/utils"
Expand Down Expand Up @@ -98,17 +96,13 @@ func validAnnounceReq(req *model.AnnounceRequest) bool {
}
if len(req.InfoHash) != 20 || len(req.PeerID) != 20 {
metrics.EmitCounter(metrics.CounterInvalidRequest, 1, map[string]string{
metrics.LabelReason: "info hash or peer id length error",
metrics.LabelPeerId: req.PeerID,
metrics.LabelInfoHash: hex.EncodeToString(conv.UnsafeStringToBytes(req.InfoHash)),
metrics.LabelReason: "info hash or peer id length error",
})
return false
}
if req.Port >= 0 && req.Port < 65535 {
metrics.EmitCounter(metrics.CounterInvalidRequest, 1, map[string]string{
metrics.LabelReason: "invalid port",
metrics.LabelPeerId: req.PeerID,
metrics.LabelInfoHash: hex.EncodeToString(conv.UnsafeStringToBytes(req.InfoHash)),
metrics.LabelReason: "invalid port",
})
return false
}
Expand Down
6 changes: 2 additions & 4 deletions service/metrics/counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ func histogramObserve(histogramVec *prometheus.HistogramVec, value time.Duration
}

const (
LabelPeerId = "peerId"
LabelInfoHash = "infoHash"
LabelReason = "reason"
LabelReason = "reason"
)

func registerCounter(registry *prometheus.Registry) map[counterMetrics]*prometheus.CounterVec {
Expand All @@ -41,7 +39,7 @@ func registerCounter(registry *prometheus.Registry) map[counterMetrics]*promethe
prometheus.NewCounterVec(prometheus.CounterOpts{
Name: counterPrefix + string(CounterInvalidRequest),
Help: "Total invalid announce counter",
}, []string{LabelPeerId, LabelInfoHash, LabelReason})
}, []string{LabelReason})

for _, h := range m {
registry.MustRegister(h)
Expand Down

0 comments on commit 57ffad0

Please sign in to comment.