mirror of
https://github.com/LBRYFoundation/tracker.git
synced 2025-08-28 16:01:32 +00:00
commit
ff15955dcc
7 changed files with 109 additions and 95 deletions
|
@ -20,10 +20,7 @@ var peerStringTestCases = []struct {
|
||||||
{
|
{
|
||||||
input: Peer{
|
input: Peer{
|
||||||
ID: PeerIDFromBytes(b),
|
ID: PeerIDFromBytes(b),
|
||||||
IP: IP{
|
IP: IP{net.IPv4(10, 11, 12, 1), IPv4},
|
||||||
IP: net.IPv4(10, 11, 12, 1),
|
|
||||||
AddressFamily: IPv4,
|
|
||||||
},
|
|
||||||
Port: 1234,
|
Port: 1234,
|
||||||
},
|
},
|
||||||
expected: fmt.Sprintf("%s@[10.11.12.1]:1234", expected),
|
expected: fmt.Sprintf("%s@[10.11.12.1]:1234", expected),
|
||||||
|
@ -31,10 +28,7 @@ var peerStringTestCases = []struct {
|
||||||
{
|
{
|
||||||
input: Peer{
|
input: Peer{
|
||||||
ID: PeerIDFromBytes(b),
|
ID: PeerIDFromBytes(b),
|
||||||
IP: IP{
|
IP: IP{net.ParseIP("2001:db8::ff00:42:8329"), IPv6},
|
||||||
IP: net.ParseIP("2001:db8::ff00:42:8329"),
|
|
||||||
AddressFamily: IPv6,
|
|
||||||
},
|
|
||||||
Port: 1234,
|
Port: 1234,
|
||||||
},
|
},
|
||||||
expected: fmt.Sprintf("%s@[2001:db8::ff00:42:8329]:1234", expected),
|
expected: fmt.Sprintf("%s@[2001:db8::ff00:42:8329]:1234", expected),
|
||||||
|
|
|
@ -10,52 +10,12 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/julienschmidt/httprouter"
|
"github.com/julienschmidt/httprouter"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
|
||||||
|
|
||||||
"github.com/chihaya/chihaya/bittorrent"
|
"github.com/chihaya/chihaya/bittorrent"
|
||||||
"github.com/chihaya/chihaya/frontend"
|
"github.com/chihaya/chihaya/frontend"
|
||||||
"github.com/chihaya/chihaya/pkg/log"
|
"github.com/chihaya/chihaya/pkg/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
prometheus.MustRegister(promResponseDurationMilliseconds)
|
|
||||||
}
|
|
||||||
|
|
||||||
var promResponseDurationMilliseconds = prometheus.NewHistogramVec(
|
|
||||||
prometheus.HistogramOpts{
|
|
||||||
Name: "chihaya_http_response_duration_milliseconds",
|
|
||||||
Help: "The duration of time it takes to receive and write a response to an API request",
|
|
||||||
Buckets: prometheus.ExponentialBuckets(9.375, 2, 10),
|
|
||||||
},
|
|
||||||
[]string{"action", "address_family", "error"},
|
|
||||||
)
|
|
||||||
|
|
||||||
// recordResponseDuration records the duration of time to respond to a Request
|
|
||||||
// in milliseconds .
|
|
||||||
func recordResponseDuration(action string, af *bittorrent.AddressFamily, err error, duration time.Duration) {
|
|
||||||
var errString string
|
|
||||||
if err != nil {
|
|
||||||
if _, ok := err.(bittorrent.ClientError); ok {
|
|
||||||
errString = err.Error()
|
|
||||||
} else {
|
|
||||||
errString = "internal error"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var afString string
|
|
||||||
if af == nil {
|
|
||||||
afString = "Unknown"
|
|
||||||
} else if *af == bittorrent.IPv4 {
|
|
||||||
afString = "IPv4"
|
|
||||||
} else if *af == bittorrent.IPv6 {
|
|
||||||
afString = "IPv6"
|
|
||||||
}
|
|
||||||
|
|
||||||
promResponseDurationMilliseconds.
|
|
||||||
WithLabelValues(action, afString, errString).
|
|
||||||
Observe(float64(duration.Nanoseconds()) / float64(time.Millisecond))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Config represents all of the configurable options for an HTTP BitTorrent
|
// Config represents all of the configurable options for an HTTP BitTorrent
|
||||||
// Frontend.
|
// Frontend.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
|
48
frontend/http/prometheus.go
Normal file
48
frontend/http/prometheus.go
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
package http
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
|
||||||
|
"github.com/chihaya/chihaya/bittorrent"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
prometheus.MustRegister(promResponseDurationMilliseconds)
|
||||||
|
}
|
||||||
|
|
||||||
|
var promResponseDurationMilliseconds = prometheus.NewHistogramVec(
|
||||||
|
prometheus.HistogramOpts{
|
||||||
|
Name: "chihaya_http_response_duration_milliseconds",
|
||||||
|
Help: "The duration of time it takes to receive and write a response to an API request",
|
||||||
|
Buckets: prometheus.ExponentialBuckets(9.375, 2, 10),
|
||||||
|
},
|
||||||
|
[]string{"action", "address_family", "error"},
|
||||||
|
)
|
||||||
|
|
||||||
|
// recordResponseDuration records the duration of time to respond to a Request
|
||||||
|
// in milliseconds.
|
||||||
|
func recordResponseDuration(action string, af *bittorrent.AddressFamily, err error, duration time.Duration) {
|
||||||
|
var errString string
|
||||||
|
if err != nil {
|
||||||
|
if _, ok := err.(bittorrent.ClientError); ok {
|
||||||
|
errString = err.Error()
|
||||||
|
} else {
|
||||||
|
errString = "internal error"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var afString string
|
||||||
|
if af == nil {
|
||||||
|
afString = "Unknown"
|
||||||
|
} else if *af == bittorrent.IPv4 {
|
||||||
|
afString = "IPv4"
|
||||||
|
} else if *af == bittorrent.IPv6 {
|
||||||
|
afString = "IPv6"
|
||||||
|
}
|
||||||
|
|
||||||
|
promResponseDurationMilliseconds.
|
||||||
|
WithLabelValues(action, afString, errString).
|
||||||
|
Observe(float64(duration.Nanoseconds()) / float64(time.Millisecond))
|
||||||
|
}
|
|
@ -12,8 +12,6 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
|
||||||
|
|
||||||
"github.com/chihaya/chihaya/bittorrent"
|
"github.com/chihaya/chihaya/bittorrent"
|
||||||
"github.com/chihaya/chihaya/frontend"
|
"github.com/chihaya/chihaya/frontend"
|
||||||
"github.com/chihaya/chihaya/frontend/udp/bytepool"
|
"github.com/chihaya/chihaya/frontend/udp/bytepool"
|
||||||
|
@ -24,45 +22,6 @@ import (
|
||||||
|
|
||||||
var allowedGeneratedPrivateKeyRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890")
|
var allowedGeneratedPrivateKeyRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890")
|
||||||
|
|
||||||
func init() {
|
|
||||||
prometheus.MustRegister(promResponseDurationMilliseconds)
|
|
||||||
}
|
|
||||||
|
|
||||||
var promResponseDurationMilliseconds = prometheus.NewHistogramVec(
|
|
||||||
prometheus.HistogramOpts{
|
|
||||||
Name: "chihaya_udp_response_duration_milliseconds",
|
|
||||||
Help: "The duration of time it takes to receive and write a response to an API request",
|
|
||||||
Buckets: prometheus.ExponentialBuckets(9.375, 2, 10),
|
|
||||||
},
|
|
||||||
[]string{"action", "address_family", "error"},
|
|
||||||
)
|
|
||||||
|
|
||||||
// recordResponseDuration records the duration of time to respond to a UDP
|
|
||||||
// Request in milliseconds .
|
|
||||||
func recordResponseDuration(action string, af *bittorrent.AddressFamily, err error, duration time.Duration) {
|
|
||||||
var errString string
|
|
||||||
if err != nil {
|
|
||||||
if _, ok := err.(bittorrent.ClientError); ok {
|
|
||||||
errString = err.Error()
|
|
||||||
} else {
|
|
||||||
errString = "internal error"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var afString string
|
|
||||||
if af == nil {
|
|
||||||
afString = "Unknown"
|
|
||||||
} else if *af == bittorrent.IPv4 {
|
|
||||||
afString = "IPv4"
|
|
||||||
} else if *af == bittorrent.IPv6 {
|
|
||||||
afString = "IPv6"
|
|
||||||
}
|
|
||||||
|
|
||||||
promResponseDurationMilliseconds.
|
|
||||||
WithLabelValues(action, afString, errString).
|
|
||||||
Observe(float64(duration.Nanoseconds()) / float64(time.Millisecond))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Config represents all of the configurable options for a UDP BitTorrent
|
// Config represents all of the configurable options for a UDP BitTorrent
|
||||||
// Tracker.
|
// Tracker.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
|
48
frontend/udp/prometheus.go
Normal file
48
frontend/udp/prometheus.go
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
package udp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
|
||||||
|
"github.com/chihaya/chihaya/bittorrent"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
prometheus.MustRegister(promResponseDurationMilliseconds)
|
||||||
|
}
|
||||||
|
|
||||||
|
var promResponseDurationMilliseconds = prometheus.NewHistogramVec(
|
||||||
|
prometheus.HistogramOpts{
|
||||||
|
Name: "chihaya_udp_response_duration_milliseconds",
|
||||||
|
Help: "The duration of time it takes to receive and write a response to an API request",
|
||||||
|
Buckets: prometheus.ExponentialBuckets(9.375, 2, 10),
|
||||||
|
},
|
||||||
|
[]string{"action", "address_family", "error"},
|
||||||
|
)
|
||||||
|
|
||||||
|
// recordResponseDuration records the duration of time to respond to a UDP
|
||||||
|
// Request in milliseconds.
|
||||||
|
func recordResponseDuration(action string, af *bittorrent.AddressFamily, err error, duration time.Duration) {
|
||||||
|
var errString string
|
||||||
|
if err != nil {
|
||||||
|
if _, ok := err.(bittorrent.ClientError); ok {
|
||||||
|
errString = err.Error()
|
||||||
|
} else {
|
||||||
|
errString = "internal error"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var afString string
|
||||||
|
if af == nil {
|
||||||
|
afString = "Unknown"
|
||||||
|
} else if *af == bittorrent.IPv4 {
|
||||||
|
afString = "IPv4"
|
||||||
|
} else if *af == bittorrent.IPv6 {
|
||||||
|
afString = "IPv6"
|
||||||
|
}
|
||||||
|
|
||||||
|
promResponseDurationMilliseconds.
|
||||||
|
WithLabelValues(action, afString, errString).
|
||||||
|
Observe(float64(duration.Nanoseconds()) / float64(time.Millisecond))
|
||||||
|
}
|
|
@ -9,7 +9,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func createNew() s.PeerStore {
|
func createNew() s.PeerStore {
|
||||||
ps, err := New(Config{ShardCount: 1024, GarbageCollectionInterval: 10 * time.Minute, PrometheusReportingInterval: 10 * time.Minute, PeerLifetime: 30 * time.Minute})
|
ps, err := New(Config{
|
||||||
|
ShardCount: 1024,
|
||||||
|
GarbageCollectionInterval: 10 * time.Minute,
|
||||||
|
PrometheusReportingInterval: 10 * time.Minute,
|
||||||
|
PeerLifetime: 30 * time.Minute,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -520,7 +520,7 @@ func (ps *peerStore) AnnouncePeers(ih bittorrent.InfoHash, seeder bool, numWant
|
||||||
// Append the rest of the leechers.
|
// Append the rest of the leechers.
|
||||||
if numWant > 0 {
|
if numWant > 0 {
|
||||||
for subnet := range shard.swarms[ih].leechers {
|
for subnet := range shard.swarms[ih].leechers {
|
||||||
// Already appended from this subnet explictly first.
|
// Already appended from this subnet explicitly first.
|
||||||
if subnet == preferredSubnet {
|
if subnet == preferredSubnet {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -568,7 +568,7 @@ func (ps *peerStore) AnnouncePeers(ih bittorrent.InfoHash, seeder bool, numWant
|
||||||
// Append as the rest of the seeders.
|
// Append as the rest of the seeders.
|
||||||
if numWant > 0 {
|
if numWant > 0 {
|
||||||
for subnet := range shard.swarms[ih].seeders {
|
for subnet := range shard.swarms[ih].seeders {
|
||||||
// Already appended from this subnet explictly first.
|
// Already appended from this subnet explicitly first.
|
||||||
if subnet == preferredSubnet {
|
if subnet == preferredSubnet {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -587,7 +587,7 @@ func (ps *peerStore) AnnouncePeers(ih bittorrent.InfoHash, seeder bool, numWant
|
||||||
// Append the rest of the leechers.
|
// Append the rest of the leechers.
|
||||||
if numWant > 0 {
|
if numWant > 0 {
|
||||||
for subnet := range shard.swarms[ih].leechers {
|
for subnet := range shard.swarms[ih].leechers {
|
||||||
// Already appended from this subnet explictly first.
|
// Already appended from this subnet explicitly first.
|
||||||
if subnet == preferredSubnet {
|
if subnet == preferredSubnet {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue