github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/metrics/execution_data_requester.go (about) 1 package metrics 2 3 import ( 4 "time" 5 6 "github.com/prometheus/client_golang/prometheus" 7 "github.com/prometheus/client_golang/prometheus/promauto" 8 9 "github.com/onflow/flow-go/module" 10 ) 11 12 type ExecutionDataRequesterCollector struct { 13 fetchDuration prometheus.Histogram 14 15 downloadsInProgress prometheus.Gauge 16 outstandingNotifications prometheus.Gauge 17 18 highestNotificationHeight prometheus.Gauge 19 highestDownloadHeight prometheus.Gauge 20 21 downloadRetries prometheus.Counter 22 failedDownloads prometheus.Counter 23 } 24 25 func NewExecutionDataRequesterCollector() module.ExecutionDataRequesterMetrics { 26 27 fetchDuration := promauto.NewHistogram(prometheus.HistogramOpts{ 28 Namespace: namespaceStateSync, 29 Subsystem: subsystemExecutionDataRequester, 30 Name: "execution_requester_download_duration_ms", 31 Help: "the duration of execution data download operation", 32 Buckets: []float64{1, 100, 500, 1000, 2000, 5000}, 33 }) 34 35 downloadsInProgress := promauto.NewGauge(prometheus.GaugeOpts{ 36 Namespace: namespaceStateSync, 37 Subsystem: subsystemExecutionDataRequester, 38 Name: "execution_requester_in_progress_downloads", 39 Help: "number of concurrently running execution data download operations", 40 }) 41 42 outstandingNotifications := promauto.NewGauge(prometheus.GaugeOpts{ 43 Namespace: namespaceStateSync, 44 Subsystem: subsystemExecutionDataRequester, 45 Name: "execution_requester_outstanding_notifications", 46 Help: "number of execution data received notifications waiting to be processed", 47 }) 48 49 highestDownloadHeight := promauto.NewGauge(prometheus.GaugeOpts{ 50 Namespace: namespaceStateSync, 51 Subsystem: subsystemExecutionDataRequester, 52 Name: "execution_requester_highest_download_height", 53 Help: "highest block height for which execution data has been received", 54 }) 55 56 highestNotificationHeight := promauto.NewGauge(prometheus.GaugeOpts{ 57 Namespace: namespaceStateSync, 58 Subsystem: subsystemExecutionDataRequester, 59 Name: "execution_requester_highest_notification_height", 60 Help: "highest block height for which execution data notifications have been sent", 61 }) 62 63 downloadRetries := promauto.NewCounter(prometheus.CounterOpts{ 64 Namespace: namespaceStateSync, 65 Subsystem: subsystemExecutionDataRequester, 66 Name: "execution_requester_download_retries_total", 67 Help: "number of execution data download retries", 68 }) 69 70 failedDownloads := promauto.NewCounter(prometheus.CounterOpts{ 71 Namespace: namespaceStateSync, 72 Subsystem: subsystemExecutionDataRequester, 73 Name: "execution_data_failed_downloads_total", 74 Help: "number of failed execution data downloads", 75 }) 76 77 return &ExecutionDataRequesterCollector{ 78 fetchDuration: fetchDuration, 79 downloadsInProgress: downloadsInProgress, 80 outstandingNotifications: outstandingNotifications, 81 highestDownloadHeight: highestDownloadHeight, 82 highestNotificationHeight: highestNotificationHeight, 83 downloadRetries: downloadRetries, 84 failedDownloads: failedDownloads, 85 } 86 } 87 88 func (ec *ExecutionDataRequesterCollector) ExecutionDataFetchStarted() { 89 ec.downloadsInProgress.Inc() 90 } 91 92 func (ec *ExecutionDataRequesterCollector) ExecutionDataFetchFinished(duration time.Duration, success bool, height uint64) { 93 ec.downloadsInProgress.Dec() 94 ec.fetchDuration.Observe(float64(duration.Milliseconds())) 95 if success { 96 ec.highestDownloadHeight.Set(float64(height)) 97 ec.outstandingNotifications.Inc() 98 } else { 99 ec.failedDownloads.Inc() 100 } 101 } 102 103 func (ec *ExecutionDataRequesterCollector) NotificationSent(height uint64) { 104 ec.outstandingNotifications.Dec() 105 ec.highestNotificationHeight.Set(float64(height)) 106 } 107 108 func (ec *ExecutionDataRequesterCollector) FetchRetried() { 109 ec.downloadRetries.Inc() 110 }