Skip to content

Commit

Permalink
autorelay: fix refresh reservations bug
Browse files Browse the repository at this point in the history
  • Loading branch information
sukunrt committed Mar 21, 2023
1 parent bb3a62c commit a7ead08
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
27 changes: 23 additions & 4 deletions p2p/host/autorelay/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ var (
[]string{"work_type"},
)

desiredReservations = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: metricNamespace,
Name: "desired_reservations",
Help: "Desired Reservations",
},
)

collectors = []prometheus.Collector{
status,
reservationsOpenedTotal,
Expand All @@ -87,6 +95,7 @@ var (
candidatesCircuitV2SupportTotal,
candidatesTotal,
scheduledWorkTime,
desiredReservations,
}
)

Expand All @@ -105,6 +114,8 @@ type MetricsTracer interface {
CandidateRemoved()

ScheduledWorkUpdated(scheduledWork *scheduledWorkTimes)

DesiredReservations(int)
}

type metricsTracer struct{}
Expand Down Expand Up @@ -230,6 +241,10 @@ func (mt *metricsTracer) ScheduledWorkUpdated(scheduledWork *scheduledWorkTimes)
scheduledWorkTime.WithLabelValues(*tags...).Set(float64(scheduledWork.nextOldCandidateCheck.Unix()))
}

func (mt *metricsTracer) DesiredReservations(cnt int) {
desiredReservations.Set(float64(cnt))
}

// wrappedMetricsTracer wraps MetricsTracer and ignores all calls when mt is nil
type wrappedMetricsTracer struct {
mt MetricsTracer
Expand All @@ -238,10 +253,8 @@ type wrappedMetricsTracer struct {
var _ MetricsTracer = &wrappedMetricsTracer{}

func (mt *wrappedMetricsTracer) RelayFinderStatus(isActive bool) {
if isActive {
status.Set(1)
} else {
status.Set(2)
if mt.mt != nil {
mt.mt.RelayFinderStatus(isActive)
}
}

Expand Down Expand Up @@ -292,3 +305,9 @@ func (mt *wrappedMetricsTracer) ScheduledWorkUpdated(scheduledWork *scheduledWor
mt.mt.ScheduledWorkUpdated(scheduledWork)
}
}

func (mt *wrappedMetricsTracer) DesiredReservations(cnt int) {
if mt.mt != nil {
mt.mt.DesiredReservations(cnt)
}
}
4 changes: 3 additions & 1 deletion p2p/host/autorelay/relay_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ func (rf *relayFinder) background(ctx context.Context) {
}
defer subConnectedness.Close()

rf.metricsTracer.DesiredReservations(rf.conf.desiredRelays)

bootDelayTimer := rf.conf.clock.Timer(rf.conf.bootDelay)
defer bootDelayTimer.Stop()

Expand Down Expand Up @@ -609,7 +611,7 @@ func (rf *relayFinder) refreshReservations(ctx context.Context, now time.Time) b
p := p
g.Go(func() error {
err := rf.refreshRelayReservation(ctx, p)
rf.metricsTracer.ReservationRequestFinished(true, err != nil)
rf.metricsTracer.ReservationRequestFinished(true, err == nil)

return err
})
Expand Down

0 comments on commit a7ead08

Please sign in to comment.