Skip to content

Commit

Permalink
Check whether or not we know the version once we start receiving mess…
Browse files Browse the repository at this point in the history
…ages from services

Fixes a case where daemon is up but service is not for the initial "Get Version" messages
  • Loading branch information
cmmarslender committed Nov 30, 2024
1 parent fd194a2 commit d893f46
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 3 deletions.
11 changes: 11 additions & 0 deletions internal/metrics/crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type CrawlerServiceMetrics struct {
metrics *Metrics

// General Service Metrics
gotVersionResponse bool
version *prometheus.GaugeVec

// Current network
Expand Down Expand Up @@ -128,6 +129,7 @@ func (s *CrawlerServiceMetrics) SetupPollingMetrics(ctx context.Context) {}
// Disconnected clears/unregisters metrics when the connection drops
func (s *CrawlerServiceMetrics) Disconnected() {
s.version.Reset()
s.gotVersionResponse = false
s.totalNodes5Days.Unregister()
s.reliableNodes.Unregister()
s.ipv4Nodes5Days.Unregister()
Expand All @@ -143,9 +145,18 @@ func (s *CrawlerServiceMetrics) Reconnected() {

// ReceiveResponse handles crawler responses that are returned over the websocket
func (s *CrawlerServiceMetrics) ReceiveResponse(resp *types.WebsocketResponse) {
// Sometimes, when we reconnect, or start exporter before chia is running
// the daemon is up before the service, and the initial request for the version
// doesn't make it to the service
// daemon doesn't queue these messages for later, they just get dropped
if !s.gotVersionResponse {
utils.LogErr(s.metrics.client.FullNodeService.GetVersion(&rpc.GetVersionOptions{}))
}

switch resp.Command {
case "get_version":
versionHelper(resp, s.version)
s.gotVersionResponse = true
case "get_peer_counts":
fallthrough
case "loaded_initial_peers":
Expand Down
11 changes: 11 additions & 0 deletions internal/metrics/farmer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type FarmerServiceMetrics struct {
metrics *Metrics

// General Service Metrics
gotVersionResponse bool
version *prometheus.GaugeVec

// Connection Metrics
Expand Down Expand Up @@ -108,6 +109,7 @@ func (s *FarmerServiceMetrics) SetupPollingMetrics(ctx context.Context) {}
// Disconnected clears/unregisters metrics when the connection drops
func (s *FarmerServiceMetrics) Disconnected() {
s.version.Reset()
s.gotVersionResponse = false
s.connectionCount.Reset()
s.plotFilesize.Reset()
s.plotCount.Reset()
Expand All @@ -123,9 +125,18 @@ func (s *FarmerServiceMetrics) Reconnected() {

// ReceiveResponse handles crawler responses that are returned over the websocket
func (s *FarmerServiceMetrics) ReceiveResponse(resp *types.WebsocketResponse) {
// Sometimes, when we reconnect, or start exporter before chia is running
// the daemon is up before the service, and the initial request for the version
// doesn't make it to the service
// daemon doesn't queue these messages for later, they just get dropped
if !s.gotVersionResponse {
utils.LogErr(s.metrics.client.FullNodeService.GetVersion(&rpc.GetVersionOptions{}))
}

switch resp.Command {
case "get_version":
versionHelper(resp, s.version)
s.gotVersionResponse = true
case "get_connections":
s.GetConnections(resp)
case "new_farming_info":
Expand Down
6 changes: 3 additions & 3 deletions internal/metrics/fullnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ func (s *FullNodeServiceMetrics) Reconnected() {

// ReceiveResponse handles full node related responses that are returned over the websocket
func (s *FullNodeServiceMetrics) ReceiveResponse(resp *types.WebsocketResponse) {
// Sometimes, when we reconnect, or start exporter before the full node is up
// the daemon is up before the full node, and the initial request for the version
// doesn't make it to the service, since it wasn't up yet
// Sometimes, when we reconnect, or start exporter before chia is running
// the daemon is up before the service, and the initial request for the version
// doesn't make it to the service
// daemon doesn't queue these messages for later, they just get dropped
if !s.gotVersionResponse {
utils.LogErr(s.metrics.client.FullNodeService.GetVersion(&rpc.GetVersionOptions{}))
Expand Down
11 changes: 11 additions & 0 deletions internal/metrics/harvester.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type HarvesterServiceMetrics struct {
metrics *Metrics

// General Service Metrics
gotVersionResponse bool
version *prometheus.GaugeVec

// Connection Metrics
Expand Down Expand Up @@ -124,6 +125,7 @@ func (s *HarvesterServiceMetrics) httpGetPlots() {
// Disconnected clears/unregisters metrics when the connection drops
func (s *HarvesterServiceMetrics) Disconnected() {
s.version.Reset()
s.gotVersionResponse = false
s.connectionCount.Reset()
s.totalPlots.Unregister()
s.plotFilesize.Reset()
Expand All @@ -140,9 +142,18 @@ func (s *HarvesterServiceMetrics) Reconnected() {

// ReceiveResponse handles crawler responses that are returned over the websocket
func (s *HarvesterServiceMetrics) ReceiveResponse(resp *types.WebsocketResponse) {
// Sometimes, when we reconnect, or start exporter before chia is running
// the daemon is up before the service, and the initial request for the version
// doesn't make it to the service
// daemon doesn't queue these messages for later, they just get dropped
if !s.gotVersionResponse {
utils.LogErr(s.metrics.client.FullNodeService.GetVersion(&rpc.GetVersionOptions{}))
}

switch resp.Command {
case "get_version":
versionHelper(resp, s.version)
s.gotVersionResponse = true
case "get_connections":
s.GetConnections(resp)
case "farming_info":
Expand Down
11 changes: 11 additions & 0 deletions internal/metrics/timelord.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type TimelordServiceMetrics struct {
metrics *Metrics

// General Service Metrics
gotVersionResponse bool
version *prometheus.GaugeVec

// Timelord Metrics
Expand Down Expand Up @@ -62,6 +63,7 @@ func (s *TimelordServiceMetrics) SetupPollingMetrics(ctx context.Context) {}
// Disconnected clears/unregisters metrics when the connection drops
func (s *TimelordServiceMetrics) Disconnected() {
s.version.Reset()
s.gotVersionResponse = false
s.fastestTimelord.Unregister()
s.slowTimelord.Unregister()
s.estimatedIPS.Unregister()
Expand All @@ -75,10 +77,19 @@ func (s *TimelordServiceMetrics) Reconnected() {

// ReceiveResponse handles crawler responses that are returned over the websocket
func (s *TimelordServiceMetrics) ReceiveResponse(resp *types.WebsocketResponse) {
// Sometimes, when we reconnect, or start exporter before chia is running
// the daemon is up before the service, and the initial request for the version
// doesn't make it to the service
// daemon doesn't queue these messages for later, they just get dropped
if !s.gotVersionResponse {
utils.LogErr(s.metrics.client.FullNodeService.GetVersion(&rpc.GetVersionOptions{}))
}

//("finished_pot_challenge", "new_compact_proof", "skipping_peak", "new_peak")
switch resp.Command {
case "get_version":
versionHelper(resp, s.version)
s.gotVersionResponse = true
case "finished_pot":
s.FinishedPoT(resp)
case "new_compact_proof":
Expand Down
11 changes: 11 additions & 0 deletions internal/metrics/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type WalletServiceMetrics struct {
metrics *Metrics

// General Service Metrics
gotVersionResponse bool
version *prometheus.GaugeVec

// Connection Metrics
Expand Down Expand Up @@ -93,6 +94,7 @@ func (s *WalletServiceMetrics) SetupPollingMetrics(ctx context.Context) {
// Disconnected clears/unregisters metrics when the connection drops
func (s *WalletServiceMetrics) Disconnected() {
s.version.Reset()
s.gotVersionResponse = false
s.connectionCount.Reset()
s.walletSynced.Unregister()
s.confirmedBalance.Reset()
Expand All @@ -109,9 +111,18 @@ func (s *WalletServiceMetrics) Reconnected() {

// ReceiveResponse handles wallet responses that are returned over the websocket
func (s *WalletServiceMetrics) ReceiveResponse(resp *types.WebsocketResponse) {
// Sometimes, when we reconnect, or start exporter before chia is running
// the daemon is up before the service, and the initial request for the version
// doesn't make it to the service
// daemon doesn't queue these messages for later, they just get dropped
if !s.gotVersionResponse {
utils.LogErr(s.metrics.client.FullNodeService.GetVersion(&rpc.GetVersionOptions{}))
}

switch resp.Command {
case "get_version":
versionHelper(resp, s.version)
s.gotVersionResponse = true
case "get_connections":
s.GetConnections(resp)
case "coin_added":
Expand Down

0 comments on commit d893f46

Please sign in to comment.