github.com/grafana/pyroscope@v1.18.0/pkg/metastore/index/tombstones/metrics.go (about)

     1  package tombstones
     2  
     3  import (
     4  	"github.com/prometheus/client_golang/prometheus"
     5  
     6  	metastorev1 "github.com/grafana/pyroscope/api/gen/proto/go/metastore/v1"
     7  	"github.com/grafana/pyroscope/pkg/util"
     8  )
     9  
    10  type metrics struct {
    11  	tombstones *prometheus.GaugeVec
    12  }
    13  
    14  func newMetrics(r prometheus.Registerer) *metrics {
    15  	m := &metrics{
    16  		tombstones: prometheus.NewGaugeVec(prometheus.GaugeOpts{
    17  			Name: "index_tombstones",
    18  			Help: "The number of tombstones in the queue.",
    19  		}, []string{"tenant", "type"}),
    20  	}
    21  
    22  	util.Register(r,
    23  		m.tombstones,
    24  	)
    25  
    26  	return m
    27  }
    28  
    29  const (
    30  	tombstoneTypeBlocks = "blocks"
    31  	tombstoneTypeShard  = "shard"
    32  )
    33  
    34  func (m *metrics) incrementTombstones(t *metastorev1.Tombstones) {
    35  	if t.Blocks != nil {
    36  		m.tombstones.WithLabelValues(t.Blocks.Tenant, tombstoneTypeBlocks).Inc()
    37  	}
    38  	if t.Shard != nil {
    39  		m.tombstones.WithLabelValues(t.Shard.Tenant, tombstoneTypeShard).Inc()
    40  	}
    41  }
    42  
    43  func (m *metrics) decrementTombstones(t *metastorev1.Tombstones) {
    44  	if t.Blocks != nil {
    45  		m.tombstones.WithLabelValues(t.Blocks.Tenant, tombstoneTypeBlocks).Dec()
    46  	}
    47  	if t.Shard != nil {
    48  		m.tombstones.WithLabelValues(t.Shard.Tenant, tombstoneTypeShard).Dec()
    49  	}
    50  }