Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metrics: BlackHoleState type public #2917

Merged
merged 1 commit into from
Aug 19, 2024
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
16 changes: 8 additions & 8 deletions p2p/net/swarm/black_hole_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import (
manet "github.com/multiformats/go-multiaddr/net"
)

type blackHoleState int
type BlackHoleState int

const (
blackHoleStateProbing blackHoleState = iota
blackHoleStateProbing BlackHoleState = iota
blackHoleStateAllowed
blackHoleStateBlocked
)

func (st blackHoleState) String() string {
func (st BlackHoleState) String() string {
switch st {
case blackHoleStateProbing:
return "Probing"
Expand Down Expand Up @@ -57,7 +57,7 @@ type BlackHoleSuccessCounter struct {
// successes is the count of successful dials in outcomes
successes int
// state is the current state of the detector
state blackHoleState
state BlackHoleState
}

// RecordResult records the outcome of a dial. A successful dial in Blocked state will change the
Expand Down Expand Up @@ -91,7 +91,7 @@ func (b *BlackHoleSuccessCounter) RecordResult(success bool) {
}

// HandleRequest returns the result of applying the black hole filter for the request.
func (b *BlackHoleSuccessCounter) HandleRequest() blackHoleState {
func (b *BlackHoleSuccessCounter) HandleRequest() BlackHoleState {
b.mu.Lock()
defer b.mu.Unlock()

Expand Down Expand Up @@ -129,7 +129,7 @@ func (b *BlackHoleSuccessCounter) updateState() {
}
}

func (b *BlackHoleSuccessCounter) State() blackHoleState {
func (b *BlackHoleSuccessCounter) State() BlackHoleState {
b.mu.Lock()
defer b.mu.Unlock()

Expand All @@ -138,7 +138,7 @@ func (b *BlackHoleSuccessCounter) State() blackHoleState {

type blackHoleInfo struct {
name string
state blackHoleState
state BlackHoleState
nextProbeAfter int
successFraction float64
}
Expand Down Expand Up @@ -251,7 +251,7 @@ func (d *blackHoleDetector) RecordResult(addr ma.Multiaddr, success bool) {
}
}

func (d *blackHoleDetector) getFilterState(f *BlackHoleSuccessCounter) blackHoleState {
func (d *blackHoleDetector) getFilterState(f *BlackHoleSuccessCounter) BlackHoleState {
if d.readOnly {
if f.State() != blackHoleStateAllowed {
return blackHoleStateBlocked
Expand Down
2 changes: 1 addition & 1 deletion p2p/net/swarm/black_hole_detector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestBlackHoleSuccessCounterSuccessFraction(t *testing.T) {
n := 10
tests := []struct {
minSuccesses, successes int
result blackHoleState
result BlackHoleState
}{
{minSuccesses: 5, successes: 5, result: blackHoleStateAllowed},
{minSuccesses: 3, successes: 3, result: blackHoleStateAllowed},
Expand Down
4 changes: 2 additions & 2 deletions p2p/net/swarm/swarm_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ type MetricsTracer interface {
FailedDialing(ma.Multiaddr, error, error)
DialCompleted(success bool, totalDials int)
DialRankingDelay(d time.Duration)
UpdatedBlackHoleSuccessCounter(name string, state blackHoleState, nextProbeAfter int, successFraction float64)
UpdatedBlackHoleSuccessCounter(name string, state BlackHoleState, nextProbeAfter int, successFraction float64)
}

type metricsTracer struct{}
Expand Down Expand Up @@ -274,7 +274,7 @@ func (m *metricsTracer) DialRankingDelay(d time.Duration) {
dialRankingDelay.Observe(d.Seconds())
}

func (m *metricsTracer) UpdatedBlackHoleSuccessCounter(name string, state blackHoleState,
func (m *metricsTracer) UpdatedBlackHoleSuccessCounter(name string, state BlackHoleState,
nextProbeAfter int, successFraction float64) {
tags := metricshelper.GetStringSlice()
defer metricshelper.PutStringSlice(tags)
Expand Down
2 changes: 1 addition & 1 deletion p2p/net/swarm/swarm_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestMetricsNoAllocNoCover(t *testing.T) {
}

bhfNames := []string{"udp", "ipv6", "tcp", "icmp"}
bhfState := []blackHoleState{blackHoleStateAllowed, blackHoleStateBlocked}
bhfState := []BlackHoleState{blackHoleStateAllowed, blackHoleStateBlocked}

tests := map[string]func(){
"OpenedConnection": func() {
Expand Down
Loading