Skip to content

Commit

Permalink
Add tracking around calls we initiate to limit to one at a time (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmmarslender authored Nov 30, 2023
1 parent d11b416 commit b384833
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
17 changes: 17 additions & 0 deletions internal/metrics/farmer.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ type FarmerServiceMetrics struct {

// Debug Metric
debug *prometheus.GaugeVec

// Tracking certain requests to make sure only one happens at any given time
gettingHarvesters bool
}

// InitMetrics sets all the metrics properties
Expand Down Expand Up @@ -131,6 +134,20 @@ func (s *FarmerServiceMetrics) ReceiveResponse(resp *types.WebsocketResponse) {
// GetConnections handler for get_connections events
func (s *FarmerServiceMetrics) GetConnections(resp *types.WebsocketResponse) {
connectionCountHelper(resp, s.connectionCount)
s.GetHarvesters()
}

// GetHarvesters loads data about harvesters connected to the farmer
func (s *FarmerServiceMetrics) GetHarvesters() {
if s.gettingHarvesters {
log.Debug("Skipping get_harvesters since another request is already in flight")
return
}
s.gettingHarvesters = true
defer func() {
s.gettingHarvesters = false
}()

harvesters, _, err := s.metrics.httpClient.FarmerService.GetHarvesters(&rpc.FarmerGetHarvestersOptions{})
if err != nil {
log.Errorf("farmer: Error getting harvesters: %s\n", err.Error())
Expand Down
12 changes: 12 additions & 0 deletions internal/metrics/fullnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ type FullNodeServiceMetrics struct {

// Debug Metric
debug *prometheus.GaugeVec

// Tracking certain requests to make sure only one happens at any given time
gettingFeeEstimate bool
}

// InitMetrics sets all the metrics properties
Expand Down Expand Up @@ -252,6 +255,15 @@ func (s *FullNodeServiceMetrics) GetBlockchainState(resp *types.WebsocketRespons
// We do this via http requests via async on the websocket since the fee estimate response doesn't
// indicate which cost the estimate is for
func (s *FullNodeServiceMetrics) GetFeeEstimates() {
if s.gettingFeeEstimate {
log.Debug("Skipping get_fee_estimate since another request is already in flight")
return
}
s.gettingFeeEstimate = true
defer func() {
s.gettingFeeEstimate = false
}()

toCheck := map[string]uint64{
"send-xch": CostSendXch,
"send-cat": CostSendCat,
Expand Down
12 changes: 12 additions & 0 deletions internal/metrics/harvester.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ type HarvesterServiceMetrics struct {

// Debug Metric
debug *prometheus.GaugeVec

// Tracking certain requests to make sure only one happens at any given time
gettingPlots bool
}

// InitMetrics sets all the metrics properties
Expand Down Expand Up @@ -81,6 +84,15 @@ func (s *HarvesterServiceMetrics) SetupPollingMetrics() {
}

func (s *HarvesterServiceMetrics) httpGetPlots() {
if s.gettingPlots {
log.Debug("Skipping get_plots since another request is already in flight")
return
}
s.gettingPlots = true
defer func() {
s.gettingPlots = false
}()

// get_plots seems to sometimes not respond on websockets, so doing http request for this
log.Debug("Calling get_plots with http client")
plots, _, err := s.metrics.httpClient.HarvesterService.GetPlots()
Expand Down

0 comments on commit b384833

Please sign in to comment.