Skip to content

Commit

Permalink
lint fixes and code clean up
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 5, 2021
1 parent c0caf42 commit a58b63f
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions pkg/compact/compact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/oklog/ulid"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
promtestutil "github.com/prometheus/client_golang/prometheus/testutil"
"github.com/prometheus/prometheus/tsdb"

Expand Down Expand Up @@ -207,7 +208,7 @@ func TestCompactProgressCalculate(t *testing.T) {
}

var bkt objstore.Bucket
temp := prometheus.NewCounter(prometheus.CounterOpts{})
temp := promauto.NewCounter(prometheus.CounterOpts{Name: "test_metric_for_group", Help: "this is a test metric for compact progress tests"})
grouper := NewDefaultGrouper(logger, bkt, false, false, reg, temp, temp, temp, "")

for _, tcase := range []struct {
Expand Down Expand Up @@ -311,15 +312,15 @@ func TestCompactProgressCalculate(t *testing.T) {
},
},
expected: map[string]planResult{
keys[0]: planResult{
keys[0]: {
compactionRuns: 0.0,
compactionBlocks: 0.0,
},
keys[1]: planResult{
keys[1]: {
compactionRuns: 1.0,
compactionBlocks: 2.0,
},
keys[2]: planResult{
keys[2]: {
compactionRuns: 0.0,
compactionBlocks: 0.0,
},
Expand Down Expand Up @@ -399,15 +400,15 @@ func TestCompactProgressCalculate(t *testing.T) {
},
},
expected: map[string]planResult{
keys[0]: planResult{
keys[0]: {
compactionRuns: 0.0,
compactionBlocks: 0.0,
},
keys[1]: planResult{
keys[1]: {
compactionRuns: 0.0,
compactionBlocks: 0.0,
},
keys[2]: planResult{
keys[2]: {
compactionRuns: 0.0,
compactionBlocks: 0.0,
},
Expand Down Expand Up @@ -475,15 +476,15 @@ func TestCompactProgressCalculate(t *testing.T) {
},
},
expected: map[string]planResult{
keys[0]: planResult{
keys[0]: {
compactionRuns: 0.0,
compactionBlocks: 0.0,
},
keys[1]: planResult{
keys[1]: {
compactionRuns: 0.0,
compactionBlocks: 0.0,
},
keys[2]: planResult{
keys[2]: {
compactionRuns: 0.0,
compactionBlocks: 0.0,
},
Expand All @@ -492,16 +493,17 @@ func TestCompactProgressCalculate(t *testing.T) {
{},
} {
if ok := t.Run(tcase.testName, func(t *testing.T) {
groups := make([]*Group, 3)

blocks := make(map[ulid.ULID]*metadata.Meta, len(tcase.input))
for _, meta := range tcase.input {
blocks[meta.ULID] = meta
}
// form groups from the input metadata - do not hardcode groups. hence, grouper.Groups should stay
groups, _ = grouper.Groups(blocks)
groups, err := grouper.Groups(blocks)
if err != nil {
level.Warn(logger).Log("msg, unable to form groups")
}
ps := NewCompactionProgressCalculator(unRegisterer, planner)
err := ps.ProgressCalculate(context.Background(), groups)
err = ps.ProgressCalculate(context.Background(), groups)
metrics := ps.CompactProgressMetrics
testutil.Ok(t, err)
for _, key := range keys {
Expand Down Expand Up @@ -543,7 +545,7 @@ func TestDownsampleProgressCalculate(t *testing.T) {
}

var bkt objstore.Bucket
temp := prometheus.NewCounter(prometheus.CounterOpts{})
temp := promauto.NewCounter(prometheus.CounterOpts{Name: "test_metric_for_group", Help: "this is a test metric for downsample progress tests"})
grouper := NewDefaultGrouper(logger, bkt, false, false, reg, temp, temp, temp, "")

for _, tcase := range []struct {
Expand Down Expand Up @@ -771,16 +773,17 @@ func TestDownsampleProgressCalculate(t *testing.T) {
},
} {
if ok := t.Run(tcase.testName, func(t *testing.T) {
groups := make([]*Group, 3)

blocks := make(map[ulid.ULID]*metadata.Meta, len(tcase.input))
for _, meta := range tcase.input {
blocks[meta.ULID] = meta
}
groups, _ = grouper.Groups(blocks)
groups, err := grouper.Groups(blocks)
if err != nil {
level.Warn(logger).Log("msg", "unable to form groups")
}

ds := NewDownsampleProgressCalculator(unRegisterer)
err := ds.ProgressCalculate(context.Background(), groups)
err = ds.ProgressCalculate(context.Background(), groups)
testutil.Ok(t, err)
metrics := ds.DownsampleProgressMetrics
for _, key := range keys {
Expand Down

0 comments on commit a58b63f

Please sign in to comment.