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 ae1330e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
28 changes: 22 additions & 6 deletions dashboards/autorelay/autorelay.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
],
"__elements": {},
"__requires": [
{
"type": "panel",
"id": "gauge",
"name": "Gauge",
"version": ""
},
{
"type": "grafana",
"id": "grafana",
Expand Down Expand Up @@ -230,9 +236,6 @@
},
"id": 4,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "auto",
"orientation": "auto",
"reduceOptions": {
"calcs": [
Expand All @@ -241,7 +244,8 @@
"fields": "",
"values": false
},
"textMode": "auto"
"showThresholdLabels": false,
"showThresholdMarkers": true
},
"pluginVersion": "9.3.6",
"targets": [
Expand All @@ -255,10 +259,22 @@
"legendFormat": "current reservations",
"range": true,
"refId": "A"
},
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"expr": "libp2p_autorelay_desired_reservations",
"hide": true,
"legendFormat": "__auto",
"range": true,
"refId": "B"
}
],
"title": "Current Reservations",
"type": "stat"
"type": "gauge"
},
{
"datasource": {
Expand Down Expand Up @@ -840,7 +856,7 @@
"list": []
},
"time": {
"from": "now-1h",
"from": "now-5m",
"to": "now"
},
"timepicker": {},
Expand Down
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 ae1330e

Please sign in to comment.