@@ -42,9 +42,10 @@ const (
4242 delKeysCountThreshold = 10
4343 lowSpaceThreshold = 50 // GB
4444 batchRetrieveSize = 1000
45- storeSameSymbolsBatchConcurrency = 3
46- fetchSymbolsBatchConcurrency = 6
47- minimumDataStoreSuccessRate = 75.0
45+
46+ storeSameSymbolsBatchConcurrency = 3
47+ fetchSymbolsBatchConcurrency = 6
48+ minimumDataStoreSuccessRate = 75.0
4849
4950 maxIterations = 4
5051 macConcurrentNetworkStoreCalls = 16
@@ -124,7 +125,7 @@ func (s *DHT) ConnPoolSnapshot() map[string]int64 {
124125
125126// Options contains configuration options for the queries node
126127type Options struct {
127- ID []byte
128+ ID []byte
128129
129130 // The queries IPv4 or IPv6 address
130131 IP string
@@ -139,8 +140,11 @@ type Options struct {
139140 // Lumera client for interacting with the blockchain
140141 LumeraClient lumera.Client
141142
142- // Keyring for credentials
143- Keyring keyring.Keyring
143+ // Keyring for credentials
144+ Keyring keyring.Keyring
145+
146+ // MetricsDisabled gates DHT-level metrics emission (p2pmetrics hooks and snapshots)
147+ MetricsDisabled bool
144148}
145149
146150// NewDHT returns a new DHT node
@@ -739,7 +743,9 @@ func (s *DHT) BatchRetrieve(ctx context.Context, keys []string, required int32,
739743 return nil , fmt .Errorf ("fetch and add local keys: %v" , err )
740744 }
741745 // Report how many were found locally, for event metrics
742- p2pmetrics .ReportFoundLocal (p2pmetrics .TaskIDFromContext (ctx ), int (foundLocalCount ))
746+ if ! s .options .MetricsDisabled {
747+ p2pmetrics .ReportFoundLocal (p2pmetrics .TaskIDFromContext (ctx ), int (foundLocalCount ))
748+ }
743749 if foundLocalCount >= required {
744750 return result , nil
745751 }
@@ -788,7 +794,9 @@ func (s *DHT) BatchRetrieve(ctx context.Context, keys []string, required int32,
788794 // Record batch retrieve stats for internal DHT snapshot window
789795 s .metrics .RecordBatchRetrieve (len (keys ), int (required ), int (foundLocalCount ), netFound , time .Since (start ))
790796 // Also feed retrieve counts into the per-task collector for stream events
791- p2pmetrics .SetRetrieveBatchSummary (p2pmetrics .TaskIDFromContext (ctx ), len (keys ), int (required ), int (foundLocalCount ), netFound , time .Since (start ).Milliseconds ())
797+ if ! s .options .MetricsDisabled {
798+ p2pmetrics .SetRetrieveBatchSummary (p2pmetrics .TaskIDFromContext (ctx ), len (keys ), int (required ), int (foundLocalCount ), netFound , time .Since (start ).Milliseconds ())
799+ }
792800
793801 return result , nil
794802}
@@ -946,14 +954,16 @@ func (s *DHT) iterateBatchGetValues(ctx context.Context, nodes map[string]*Node,
946954 }
947955 mu .Unlock ()
948956 // record failed RPC per-node
949- p2pmetrics .RecordRetrieve (p2pmetrics .TaskIDFromContext (ctx ), p2pmetrics.Call {
950- IP : node .IP ,
951- Address : node .String (),
952- Keys : 0 ,
953- Success : false ,
954- Error : err .Error (),
955- DurationMS : time .Since (callStart ).Milliseconds (),
956- })
957+ if ! s .options .MetricsDisabled {
958+ p2pmetrics .RecordRetrieve (p2pmetrics .TaskIDFromContext (ctx ), p2pmetrics.Call {
959+ IP : node .IP ,
960+ Address : node .String (),
961+ Keys : 0 ,
962+ Success : false ,
963+ Error : err .Error (),
964+ DurationMS : time .Since (callStart ).Milliseconds (),
965+ })
966+ }
957967 return
958968 }
959969
@@ -976,14 +986,16 @@ func (s *DHT) iterateBatchGetValues(ctx context.Context, nodes map[string]*Node,
976986 }
977987
978988 // record successful RPC per-node (returned may be 0). Success is true when no error.
979- p2pmetrics .RecordRetrieve (p2pmetrics .TaskIDFromContext (ctx ), p2pmetrics.Call {
980- IP : node .IP ,
981- Address : node .String (),
982- Keys : returned ,
983- Success : true ,
984- Error : "" ,
985- DurationMS : time .Since (callStart ).Milliseconds (),
986- })
989+ if ! s .options .MetricsDisabled {
990+ p2pmetrics .RecordRetrieve (p2pmetrics .TaskIDFromContext (ctx ), p2pmetrics.Call {
991+ IP : node .IP ,
992+ Address : node .String (),
993+ Keys : returned ,
994+ Success : true ,
995+ Error : "" ,
996+ DurationMS : time .Since (callStart ).Milliseconds (),
997+ })
998+ }
987999 }(node , nodeID )
9881000 }
9891001
@@ -1713,14 +1725,16 @@ func (s *DHT) IterateBatchStore(ctx context.Context, values [][]byte, typ int, i
17131725 }
17141726
17151727 // Emit per-node store RPC call via metrics bridge (no P2P API coupling)
1716- p2pmetrics .RecordStore (p2pmetrics .TaskIDFromContext (ctx ), p2pmetrics.Call {
1717- IP : nodeIP ,
1718- Address : nodeAddr ,
1719- Keys : response .KeysCount ,
1720- Success : errMsg == "" && response .Error == nil ,
1721- Error : errMsg ,
1722- DurationMS : response .DurationMS ,
1723- })
1728+ if ! s .options .MetricsDisabled {
1729+ p2pmetrics .RecordStore (p2pmetrics .TaskIDFromContext (ctx ), p2pmetrics.Call {
1730+ IP : nodeIP ,
1731+ Address : nodeAddr ,
1732+ Keys : response .KeysCount ,
1733+ Success : errMsg == "" && response .Error == nil ,
1734+ Error : errMsg ,
1735+ DurationMS : response .DurationMS ,
1736+ })
1737+ }
17241738
17251739 }
17261740
0 commit comments