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

     1  package metrics
     2  
     3  import (
     4  	"sync"
     5  
     6  	"github.com/prometheus/client_golang/prometheus"
     7  	"github.com/prometheus/client_golang/prometheus/promauto"
     8  )
     9  
    10  type StorageCollector struct {
    11  	storageOperationModified *prometheus.CounterVec
    12  }
    13  
    14  const (
    15  	modifierLabel = "modifier"
    16  
    17  	skipDuplicates  = "skip_duplicates"
    18  	retryOnConflict = "retry_on_conflict"
    19  )
    20  
    21  var (
    22  	onlyOnce  sync.Once
    23  	collector *StorageCollector
    24  )
    25  
    26  func GetStorageCollector() *StorageCollector {
    27  	onlyOnce.Do(
    28  		func() {
    29  			collector = &StorageCollector{
    30  				storageOperationModified: promauto.NewCounterVec(prometheus.CounterOpts{
    31  					Name:      "operation_modifier",
    32  					Namespace: "storage",
    33  					Subsystem: "badger",
    34  					Help:      "report number of times a storage operation was modified using a modifier",
    35  				}, []string{modifierLabel}),
    36  			}
    37  		},
    38  	)
    39  
    40  	return collector
    41  }
    42  
    43  func (sc *StorageCollector) SkipDuplicate() {
    44  	sc.storageOperationModified.With(prometheus.Labels{modifierLabel: skipDuplicates}).Inc()
    45  }
    46  
    47  func (sc *StorageCollector) RetryOnConflict() {
    48  	sc.storageOperationModified.With(prometheus.Labels{modifierLabel: retryOnConflict}).Inc()
    49  }