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

Export gauges for block files after the filtering #15

Merged
merged 1 commit into from
Feb 28, 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
38 changes: 35 additions & 3 deletions pkg/block/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"path"
"path/filepath"
"sort"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -56,20 +57,23 @@ type FetcherMetrics struct {
Modified *extprom.TxGaugeVec

SyncedByTenant *extprom.TxGaugeVec
Assigned *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()
s.Assigned.Submit()
}

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

const (
Expand Down Expand Up @@ -98,8 +102,10 @@ const (
// Modified label values.
replicaRemovedMeta = "replica-label-removed"

tenantLabel = "__tenant__"
defautTenant = "__unknown__"
tenantLabel = "__tenant__"
defautTenant = "__not_set__"
replicaLabel = "__replica__"
defaultReplica = ""
hczhu-db marked this conversation as resolved.
Show resolved Hide resolved
)

func NewBaseFetcherMetrics(reg prometheus.Registerer) *BaseFetcherMetrics {
Expand Down Expand Up @@ -163,6 +169,16 @@ func NewFetcherMetrics(reg prometheus.Registerer, syncedExtraLabels, modifiedExt
[]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.
)
m.Assigned = extprom.NewTxGaugeVec(
reg,
prometheus.GaugeOpts{
Subsystem: fetcherSubSys,
Name: "assigned",
Help: "Number of metadata blocks assigned to this pod after all filters.",
},
[]string{"tenant", "level", "replica"},
// 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 @@ -584,7 +600,23 @@ func (f *BaseFetcher) fetch(ctx context.Context, metrics *FetcherMetrics, filter
return nil, nil, errors.Wrap(err, "filter metas")
}
}
level.Debug(f.logger).Log("msg", "filtered out block meta data", "before", blockMetaBeforeFilters, "after", len(metas))
level.Info(f.logger).Log("msg", "filtered out block meta data", "before", blockMetaBeforeFilters, "after", len(metas), "filters", len(filters))
// If filters is empty, it's a global fetch for all block file metadata. metrics.Assigned is for the blocks assigned to this instance.
// Therefore, it's skipped to update the gauge.
if len(filters) > 0 {
hczhu-db marked this conversation as resolved.
Show resolved Hide resolved
for _, m := range metas {
var tenant, replica string
var ok bool
// tenant and replica will have the zero value ("") if the key is not in the map.
if tenant, ok = m.Thanos.Labels[tenantLabel]; !ok {
tenant = defautTenant
}
if replica, ok = m.Thanos.Labels[replicaLabel]; !ok {
replica = defaultReplica
}
metrics.Assigned.WithLabelValues(tenant, strconv.Itoa(m.BlockMeta.Compaction.Level), replica).Inc()
}
}

metrics.Synced.WithLabelValues(LoadedMeta).Set(float64(len(metas)))
metrics.Submit()
Expand Down
Loading