Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instrument the number of data blocks broken down by tenant #14

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading