Skip to content

Commit

Permalink
use reset instead of unregister; minor nits
Browse files Browse the repository at this point in the history
Signed-off-by: metonymic-smokey <ahuja.aditi@gmail.com>
  • Loading branch information
metonymic-smokey committed Nov 6, 2021
1 parent 6999f7f commit 37848f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
20 changes: 5 additions & 15 deletions cmd/thanos/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (
"github.com/thanos-io/thanos/pkg/logging"
"github.com/thanos-io/thanos/pkg/objstore/client"
"github.com/thanos-io/thanos/pkg/prober"
"github.com/thanos-io/thanos/pkg/receive"
"github.com/thanos-io/thanos/pkg/runutil"
httpserver "github.com/thanos-io/thanos/pkg/server/http"
"github.com/thanos-io/thanos/pkg/ui"
Expand Down Expand Up @@ -462,11 +461,10 @@ func runCompact(

if conf.compactionProgressMetrics {
g.Add(func() error {
unRegisterer := &receive.UnRegisterer{Registerer: reg}
ps := compact.NewCompactionProgressCalculator(unRegisterer, tsdbPlanner)
ps := compact.NewCompactionProgressCalculator(reg, tsdbPlanner)
var ds *compact.DownsampleProgressCalculator
if !conf.disableDownsampling {
ds = compact.NewDownsampleProgressCalculator(unRegisterer)
ds = compact.NewDownsampleProgressCalculator(reg)
}

return runutil.Repeat(5*time.Minute, ctx.Done(), func() error {
Expand All @@ -478,12 +476,7 @@ func runCompact(
metas := sy.Metas()
groups, err := grouper.Groups(metas)
if err != nil {
return errors.Wrapf(err, "could not group original metadata")
}

for _, group := range groups {
ps.CompactProgressMetrics.NumberOfCompactionRuns.WithLabelValues(group.Key())
ps.CompactProgressMetrics.NumberOfCompactionBlocks.WithLabelValues(group.Key())
return errors.Wrapf(err, "could not group metadata")
}

if err = ps.ProgressCalculate(ctx, groups); err != nil {
Expand All @@ -493,10 +486,7 @@ func runCompact(
if !conf.disableDownsampling {
groups, err = grouper.Groups(metas)
if err != nil {
return errors.Wrapf(err, "could not group original metadata into downsample groups")
}
for _, group := range groups {
ds.DownsampleProgressMetrics.NumberOfBlocksDownsampled.WithLabelValues(group.Key())
return errors.Wrapf(err, "could not group metadata into downsample groups")
}
if err := ds.ProgressCalculate(ctx, groups); err != nil {
return errors.Wrapf(err, "could not calculate downsampling progress")
Expand Down Expand Up @@ -646,7 +636,7 @@ type compactConfig struct {
}

func (cc *compactConfig) registerFlag(cmd extkingpin.FlagClause) {
cmd.Flag("progress-metrics", "Enables the progress metrics, indicating the progress of compaction and downsampling").Default("false").BoolVar(&cc.compactionProgressMetrics)
cmd.Flag("progress-metrics", "Enables the progress metrics, indicating the progress of compaction and downsampling").Default("true").BoolVar(&cc.compactionProgressMetrics)

cmd.Flag("debug.halt-on-error", "Halt the process if a critical compaction error is detected.").
Hidden().Default("true").BoolVar(&cc.haltOnError)
Expand Down
6 changes: 5 additions & 1 deletion pkg/compact/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ func NewCompactionProgressCalculator(reg prometheus.Registerer, planner *tsdbBas
CompactProgressMetrics: &CompactProgressMetrics{
NumberOfCompactionRuns: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{
Name: "thanos_compact_todo_compactions",
Help: "number of iterations to be done",
Help: "number of compactions to be done",
}, []string{"group"}),
NumberOfCompactionBlocks: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{
Name: "thanos_compact_todo_compaction_blocks",
Expand Down Expand Up @@ -561,6 +561,9 @@ func (ps *CompactionProgressCalculator) ProgressCalculate(ctx context.Context, g
groups = tmpGroups
}

ps.CompactProgressMetrics.NumberOfCompactionRuns.Reset()
ps.CompactProgressMetrics.NumberOfCompactionBlocks.Reset()

for key, iters := range groupCompactions {
ps.CompactProgressMetrics.NumberOfCompactionRuns.WithLabelValues(key).Add(float64(iters))
ps.CompactProgressMetrics.NumberOfCompactionBlocks.WithLabelValues(key).Add(float64(groupBlocks[key]))
Expand Down Expand Up @@ -656,6 +659,7 @@ func (ds *DownsampleProgressCalculator) ProgressCalculate(ctx context.Context, g
}
}

ds.DownsampleProgressMetrics.NumberOfBlocksDownsampled.Reset()
for key, blocks := range groupBlocks {
ds.DownsampleProgressMetrics.NumberOfBlocksDownsampled.WithLabelValues(key).Add(float64(blocks))
}
Expand Down

0 comments on commit 37848f1

Please sign in to comment.