diff --git a/protocol/lavasession/consumer_session_manager.go b/protocol/lavasession/consumer_session_manager.go index 744f33bd74..30c83c6c5f 100644 --- a/protocol/lavasession/consumer_session_manager.go +++ b/protocol/lavasession/consumer_session_manager.go @@ -639,6 +639,9 @@ func (csm *ConsumerSessionManager) getValidProviderAddresses(ignoredProvidersLis providers = csm.getTopTenProvidersForStatefulCalls(validAddresses, ignoredProvidersList) } else { providers = csm.providerOptimizer.ChooseProvider(validAddresses, ignoredProvidersList, cu, requestedBlock, OptimizerPerturbation) + for _, chosenProvider := range providers { + go csm.consumerMetricsManager.UpdateProviderChosenByOptimizerCount(csm.rpcEndpoint.ChainID, csm.rpcEndpoint.ApiInterface, chosenProvider, csm.currentEpoch) + } } utils.LavaFormatTrace("Choosing providers", diff --git a/protocol/metrics/consumer_metrics_manager.go b/protocol/metrics/consumer_metrics_manager.go index ef43923ba8..3ce6e3ddb7 100644 --- a/protocol/metrics/consumer_metrics_manager.go +++ b/protocol/metrics/consumer_metrics_manager.go @@ -54,6 +54,7 @@ type ConsumerMetricsManager struct { relayProcessingLatencyBeforeProvider *prometheus.GaugeVec relayProcessingLatencyAfterProvider *prometheus.GaugeVec averageProcessingLatency map[string]*LatencyTracker + providerChosenByOptimizerCount *prometheus.GaugeVec } type ConsumerMetricsManagerOptions struct { @@ -175,6 +176,11 @@ func NewConsumerMetricsManager(options ConsumerMetricsManagerOptions) *ConsumerM Help: "average latency of processing a successful relay after it is received from the provider in µs (10^6)", }, []string{"spec", "apiInterface"}) + providerChosenByOptimizerCount := prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "lava_consumer_provider_chosen_by_optimizer_count", + Help: "The total number of times a provider was chosen by the optimizer", + }, []string{"spec", "apiInterface", "provider_address", "epoch"}) + // Register the metrics with the Prometheus registry. prometheus.MustRegister(totalCURequestedMetric) prometheus.MustRegister(totalRelaysRequestedMetric) @@ -197,6 +203,7 @@ func NewConsumerMetricsManager(options ConsumerMetricsManagerOptions) *ConsumerM prometheus.MustRegister(totalNodeErroredRecoveryAttemptsMetric) prometheus.MustRegister(relayProcessingLatencyBeforeProvider) prometheus.MustRegister(relayProcessingLatencyAfterProvider) + prometheus.MustRegister(providerChosenByOptimizerCount) consumerMetricsManager := &ConsumerMetricsManager{ totalCURequestedMetric: totalCURequestedMetric, @@ -225,6 +232,7 @@ func NewConsumerMetricsManager(options ConsumerMetricsManagerOptions) *ConsumerM relayProcessingLatencyBeforeProvider: relayProcessingLatencyBeforeProvider, relayProcessingLatencyAfterProvider: relayProcessingLatencyAfterProvider, averageProcessingLatency: map[string]*LatencyTracker{}, + providerChosenByOptimizerCount: providerChosenByOptimizerCount, } http.Handle("/metrics", promhttp.Handler()) @@ -442,6 +450,7 @@ func (pme *ConsumerMetricsManager) ResetSessionRelatedMetrics() { pme.qosMetric.Reset() pme.qosExcellenceMetric.Reset() pme.providerRelays = map[string]uint64{} + pme.providerChosenByOptimizerCount.Reset() } func (pme *ConsumerMetricsManager) SetVersion(version string) { @@ -451,6 +460,13 @@ func (pme *ConsumerMetricsManager) SetVersion(version string) { SetVersionInner(pme.protocolVersionMetric, version) } +func (pme *ConsumerMetricsManager) UpdateProviderChosenByOptimizerCount(chainId string, apiInterface string, providerAddress string, epoch uint64) { + if pme == nil { + return + } + pme.providerChosenByOptimizerCount.WithLabelValues(chainId, apiInterface, providerAddress, strconv.FormatUint(epoch, 10)).Inc() +} + func SetVersionInner(protocolVersionMetric *prometheus.GaugeVec, version string) { var major, minor, patch int _, err := fmt.Sscanf(version, "%d.%d.%d", &major, &minor, &patch)