From fd194a22bf9b7fcbe98a0370cf941a69ba9c245c Mon Sep 17 00:00:00 2001 From: Chris Marslender Date: Sat, 30 Nov 2024 15:24:05 -0600 Subject: [PATCH] if version isn't set when receiving responses, try to get it again --- internal/metrics/fullnode.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/metrics/fullnode.go b/internal/metrics/fullnode.go index 35f6caa..f445421 100644 --- a/internal/metrics/fullnode.go +++ b/internal/metrics/fullnode.go @@ -36,7 +36,8 @@ type FullNodeServiceMetrics struct { metrics *Metrics // General Service Metrics - version *prometheus.GaugeVec + gotVersionResponse bool + version *prometheus.GaugeVec // GetBlockchainState Metrics difficulty *wrappedPrometheus.LazyGauge @@ -187,6 +188,7 @@ func (s *FullNodeServiceMetrics) SetupPollingMetrics(ctx context.Context) { // Disconnected clears/unregisters metrics when the connection drops func (s *FullNodeServiceMetrics) Disconnected() { s.version.Reset() + s.gotVersionResponse = false s.difficulty.Unregister() s.mempoolCost.Unregister() s.mempoolMinFee.Reset() @@ -228,9 +230,18 @@ 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 + // 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_blockchain_state": s.GetBlockchainState(resp) // Ask for connection info when we get updated blockchain state