github.com/koko1123/flow-go-1@v0.29.6/module/metrics/execution_data_sync.go (about)

     1  package metrics
     2  
     3  import (
     4  	"strconv"
     5  	"time"
     6  
     7  	"github.com/prometheus/client_golang/prometheus"
     8  	"github.com/prometheus/client_golang/prometheus/promauto"
     9  )
    10  
    11  type ExecutionDataRequesterV2Collector struct {
    12  	fulfilledHeight               prometheus.Gauge
    13  	receiptsSkipped               prometheus.Counter
    14  	requestDurations              prometheus.Summary
    15  	latestSuccessfulRequestHeight prometheus.Gauge
    16  	executionDataSizes            prometheus.Summary
    17  	requestAttempts               prometheus.Histogram
    18  	requestsFailed                *prometheus.CounterVec
    19  	requestsCancelled             prometheus.Counter
    20  	responsesDropped              prometheus.Counter
    21  }
    22  
    23  func NewExecutionDataRequesterV2Collector() *ExecutionDataRequesterV2Collector {
    24  	return &ExecutionDataRequesterV2Collector{
    25  		fulfilledHeight: promauto.NewGauge(prometheus.GaugeOpts{
    26  			Name:      "fulfilled_height",
    27  			Namespace: namespaceExecutionDataSync,
    28  			Subsystem: subsystemExeDataRequester,
    29  			Help:      "the latest sealed height for which all execution data has been retrieved and stored locally",
    30  		}),
    31  		receiptsSkipped: promauto.NewCounter(prometheus.CounterOpts{
    32  			Name:      "receipts_skipped",
    33  			Namespace: namespaceExecutionDataSync,
    34  			Subsystem: subsystemExeDataRequester,
    35  			Help:      "the number of skipped receipts",
    36  		}),
    37  		requestDurations: promauto.NewSummary(prometheus.SummaryOpts{
    38  			Name:      "request_durations_ms",
    39  			Namespace: namespaceExecutionDataSync,
    40  			Subsystem: subsystemExeDataRequester,
    41  			Help:      "the durations of requests in milliseconds",
    42  			Objectives: map[float64]float64{
    43  				0.01: 0.001,
    44  				0.1:  0.01,
    45  				0.25: 0.025,
    46  				0.5:  0.05,
    47  				0.75: 0.025,
    48  				0.9:  0.01,
    49  				0.99: 0.001,
    50  			},
    51  		}),
    52  		latestSuccessfulRequestHeight: promauto.NewGauge(prometheus.GaugeOpts{
    53  			Name:      "latest_successful_request_height",
    54  			Namespace: namespaceExecutionDataSync,
    55  			Subsystem: subsystemExeDataRequester,
    56  			Help:      "the block height of the latest successful request",
    57  		}),
    58  		executionDataSizes: promauto.NewSummary(prometheus.SummaryOpts{
    59  			Name:      "execution_data_sizes_bytes",
    60  			Namespace: namespaceExecutionDataSync,
    61  			Subsystem: subsystemExeDataRequester,
    62  			Help:      "the sizes of Block Execution Data in bytes",
    63  			Objectives: map[float64]float64{
    64  				0.01: 0.001,
    65  				0.1:  0.01,
    66  				0.25: 0.025,
    67  				0.5:  0.05,
    68  				0.75: 0.025,
    69  				0.9:  0.01,
    70  				0.99: 0.001,
    71  			},
    72  		}),
    73  		requestAttempts: promauto.NewHistogram(prometheus.HistogramOpts{
    74  			Name:      "request_attempts",
    75  			Namespace: namespaceExecutionDataSync,
    76  			Subsystem: subsystemExeDataRequester,
    77  			Buckets:   []float64{1, 2, 3, 4, 5},
    78  			Help:      "the number of attempts before a request succeeded",
    79  		}),
    80  		requestsFailed: promauto.NewCounterVec(prometheus.CounterOpts{
    81  			Name:      "requests_failed",
    82  			Namespace: namespaceExecutionDataSync,
    83  			Subsystem: subsystemExeDataRequester,
    84  			Help:      "the number of failed requests",
    85  		}, []string{ExecutionDataRequestRetryable}),
    86  		requestsCancelled: promauto.NewCounter(prometheus.CounterOpts{
    87  			Name:      "requests_cancelled",
    88  			Namespace: namespaceExecutionDataSync,
    89  			Subsystem: subsystemExeDataRequester,
    90  			Help:      "the number of cancelled requests",
    91  		}),
    92  		responsesDropped: promauto.NewCounter(prometheus.CounterOpts{
    93  			Name:      "responses_dropped",
    94  			Namespace: namespaceExecutionDataSync,
    95  			Subsystem: subsystemExeDataRequester,
    96  			Help:      "the number of dropped responses",
    97  		}),
    98  	}
    99  }
   100  
   101  func (c *ExecutionDataRequesterV2Collector) FulfilledHeight(blockHeight uint64) {
   102  	c.fulfilledHeight.Set(float64(blockHeight))
   103  }
   104  
   105  func (c *ExecutionDataRequesterV2Collector) ReceiptSkipped() {
   106  	c.receiptsSkipped.Inc()
   107  }
   108  
   109  func (c *ExecutionDataRequesterV2Collector) RequestSucceeded(blockHeight uint64, duration time.Duration, totalSize uint64, numberOfAttempts int) {
   110  	c.requestDurations.Observe(float64(duration.Milliseconds()))
   111  	c.latestSuccessfulRequestHeight.Set(float64(blockHeight))
   112  	c.executionDataSizes.Observe(float64(totalSize))
   113  	c.requestAttempts.Observe(float64(numberOfAttempts))
   114  }
   115  
   116  func (c *ExecutionDataRequesterV2Collector) RequestFailed(duration time.Duration, retryable bool) {
   117  	c.requestDurations.Observe(float64(duration.Milliseconds()))
   118  	c.requestsFailed.WithLabelValues(strconv.FormatBool(retryable)).Inc()
   119  }
   120  
   121  func (c *ExecutionDataRequesterV2Collector) RequestCanceled() {
   122  	c.requestsCancelled.Inc()
   123  }
   124  
   125  func (c *ExecutionDataRequesterV2Collector) ResponseDropped() {
   126  	c.responsesDropped.Inc()
   127  }
   128  
   129  type ExecutionDataProviderCollector struct {
   130  	computeRootIDDurations prometheus.Summary
   131  	numberOfChunks         prometheus.Histogram
   132  	addBlobsDurations      prometheus.Summary
   133  	executionDataSizes     prometheus.Summary
   134  	addBlobsFailed         prometheus.Counter
   135  }
   136  
   137  func NewExecutionDataProviderCollector() *ExecutionDataProviderCollector {
   138  	return &ExecutionDataProviderCollector{
   139  		computeRootIDDurations: promauto.NewSummary(prometheus.SummaryOpts{
   140  			Name:      "compute_root_id_durations_ms",
   141  			Namespace: namespaceExecutionDataSync,
   142  			Subsystem: subsystemExeDataProvider,
   143  			Help:      "the durations of computing root IDs in milliseconds",
   144  			Objectives: map[float64]float64{
   145  				0.01: 0.001,
   146  				0.1:  0.01,
   147  				0.25: 0.025,
   148  				0.5:  0.05,
   149  				0.75: 0.025,
   150  				0.9:  0.01,
   151  				0.99: 0.001,
   152  			},
   153  		}),
   154  		numberOfChunks: promauto.NewHistogram(prometheus.HistogramOpts{
   155  			Name:      "number_of_chunks",
   156  			Namespace: namespaceExecutionDataSync,
   157  			Subsystem: subsystemExeDataProvider,
   158  			Buckets:   []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25},
   159  			Help:      "the number of chunks in a Block Execution Data",
   160  		}),
   161  		addBlobsDurations: promauto.NewSummary(prometheus.SummaryOpts{
   162  			Name:      "add_blobs_durations_ms",
   163  			Namespace: namespaceExecutionDataSync,
   164  			Subsystem: subsystemExeDataProvider,
   165  			Help:      "the durations of adding blobs in milliseconds",
   166  			Objectives: map[float64]float64{
   167  				0.01: 0.001,
   168  				0.1:  0.01,
   169  				0.25: 0.025,
   170  				0.5:  0.05,
   171  				0.75: 0.025,
   172  				0.9:  0.01,
   173  				0.99: 0.001,
   174  			},
   175  		}),
   176  		executionDataSizes: promauto.NewSummary(prometheus.SummaryOpts{
   177  			Name:      "execution_data_sizes_bytes",
   178  			Namespace: namespaceExecutionDataSync,
   179  			Subsystem: subsystemExeDataProvider,
   180  			Help:      "the sizes of Block Execution Data in bytes",
   181  			Objectives: map[float64]float64{
   182  				0.01: 0.001,
   183  				0.1:  0.01,
   184  				0.25: 0.025,
   185  				0.5:  0.05,
   186  				0.75: 0.025,
   187  				0.9:  0.01,
   188  				0.99: 0.001,
   189  			},
   190  		}),
   191  		addBlobsFailed: promauto.NewCounter(prometheus.CounterOpts{
   192  			Name:      "add_blobs_failed",
   193  			Namespace: namespaceExecutionDataSync,
   194  			Subsystem: subsystemExeDataProvider,
   195  			Help:      "the number of failed attempts to add blobs",
   196  		}),
   197  	}
   198  }
   199  
   200  func (c *ExecutionDataProviderCollector) RootIDComputed(duration time.Duration, numberOfChunks int) {
   201  	c.computeRootIDDurations.Observe(float64(duration.Milliseconds()))
   202  	c.numberOfChunks.Observe(float64(numberOfChunks))
   203  }
   204  
   205  func (c *ExecutionDataProviderCollector) AddBlobsSucceeded(duration time.Duration, totalSize uint64) {
   206  	c.addBlobsDurations.Observe(float64(duration.Milliseconds()))
   207  	c.executionDataSizes.Observe(float64(totalSize))
   208  }
   209  
   210  func (c *ExecutionDataProviderCollector) AddBlobsFailed() {
   211  	c.addBlobsFailed.Inc()
   212  }
   213  
   214  type ExecutionDataPrunerCollector struct {
   215  	pruneDurations     prometheus.Summary
   216  	latestHeightPruned prometheus.Gauge
   217  }
   218  
   219  func NewExecutionDataPrunerCollector() *ExecutionDataPrunerCollector {
   220  	return &ExecutionDataPrunerCollector{
   221  		pruneDurations: promauto.NewSummary(prometheus.SummaryOpts{
   222  			Name:      "prune_durations_ms",
   223  			Namespace: namespaceExecutionDataSync,
   224  			Subsystem: subsystemExeDataPruner,
   225  			Help:      "the durations of pruning in milliseconds",
   226  			Objectives: map[float64]float64{
   227  				0.01: 0.001,
   228  				0.1:  0.01,
   229  				0.25: 0.025,
   230  				0.5:  0.05,
   231  				0.75: 0.025,
   232  				0.9:  0.01,
   233  				0.99: 0.001,
   234  			},
   235  		}),
   236  		latestHeightPruned: promauto.NewGauge(prometheus.GaugeOpts{
   237  			Name:      "latest_height_pruned",
   238  			Namespace: namespaceExecutionDataSync,
   239  			Subsystem: subsystemExeDataPruner,
   240  			Help:      "the latest height pruned",
   241  		}),
   242  	}
   243  }
   244  
   245  func (c *ExecutionDataPrunerCollector) Pruned(height uint64, duration time.Duration) {
   246  	c.pruneDurations.Observe(float64(duration.Milliseconds()))
   247  	c.latestHeightPruned.Set(float64(height))
   248  }