Skip to content

Commit

Permalink
Instrument the number of data blocks broken down by tenant
Browse files Browse the repository at this point in the history
  • Loading branch information
hczhu-db committed Feb 15, 2024
1 parent dbc4213 commit f3c111f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pkg/block/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,22 @@ type FetcherMetrics struct {

Synced *extprom.TxGaugeVec
Modified *extprom.TxGaugeVec

SyncedByTenant *extprom.TxGaugeVec
}

// Submit applies new values for metrics tracked by transaction GaugeVec.
func (s *FetcherMetrics) Submit() {
s.Synced.Submit()
s.Modified.Submit()
s.SyncedByTenant.Submit()
}

// ResetTx starts new transaction for metrics tracked by transaction GaugeVec.
func (s *FetcherMetrics) ResetTx() {
s.Synced.ResetTx()
s.Modified.ResetTx()
s.SyncedByTenant.ResetTx()
}

const (
Expand Down Expand Up @@ -86,6 +90,9 @@ const (

// Modified label values.
replicaRemovedMeta = "replica-label-removed"

tenantLabel = "__tenant__"
defautTenant = "__unkown__"
)

func NewFetcherMetrics(reg prometheus.Registerer, syncedExtraLabels, modifiedExtraLabels [][]string) *FetcherMetrics {
Expand Down Expand Up @@ -140,6 +147,16 @@ func NewFetcherMetrics(reg prometheus.Registerer, syncedExtraLabels, modifiedExt
{replicaRemovedMeta},
}, modifiedExtraLabels...)...,
)
m.SyncedByTenant = extprom.NewTxGaugeVec(
reg,
prometheus.GaugeOpts{
Subsystem: fetcherSubSys,
Name: "synced_by_tenant",
Help: "Number of metadata blocks synced broken down by tenant",
},
[]string{"tenant"},
// No init label values is fine. The only downside is those guages won't be reset to 0, but it's fine for the use case.
)
return &m
}

Expand Down Expand Up @@ -470,10 +487,20 @@ func (f *BaseFetcher) fetch(ctx context.Context, metrics *FetcherMetrics, filter
}
resp := v.(response)

numBlocksByTenant := map[string]int{}
// Copy as same response might be reused by different goroutines.
metas := make(map[ulid.ULID]*metadata.Meta, len(resp.metas))
for id, m := range resp.metas {
metas[id] = m
if tenant, ok := m.Thanos.Labels[tenantLabel]; ok {
numBlocksByTenant[tenant]++
} else {
numBlocksByTenant[defautTenant]++
}
}

for tenant, numBlocks := range numBlocksByTenant {
metrics.SyncedByTenant.WithLabelValues(tenant).Set(float64(numBlocks))
}

metrics.Synced.WithLabelValues(FailedMeta).Set(float64(len(resp.metaErrs)))
Expand Down

0 comments on commit f3c111f

Please sign in to comment.