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

Metrics for compaction and downsampling process #4801

Merged
merged 75 commits into from
Nov 6, 2021
Merged
Changes from 1 commit
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
6fb9752
fixed template; export metadata
metonymic-smokey Oct 16, 2021
f403fcc
added some error handling
metonymic-smokey Oct 16, 2021
02d7037
remove planned blocks from original
metonymic-smokey Oct 16, 2021
ea83250
moved to pkg/compact
metonymic-smokey Oct 17, 2021
ff2e36a
draft: export metrics to Prom
metonymic-smokey Oct 18, 2021
5961552
update metrics after entire plan sim; change func name
metonymic-smokey Oct 18, 2021
a2b2b97
added method to delete metas from group
metonymic-smokey Oct 18, 2021
8f13acc
preallocate meta slice
metonymic-smokey Oct 18, 2021
f52e056
changed func signature; started adding metrics to Group
metonymic-smokey Oct 18, 2021
ad639c1
added termination condition
metonymic-smokey Oct 18, 2021
845d497
metrics struct added
metonymic-smokey Oct 18, 2021
cc4efe4
draft: updating progress metric
metonymic-smokey Oct 19, 2021
322340b
added feature flag for compact
metonymic-smokey Oct 19, 2021
a4642f6
use tsdb planner as default
metonymic-smokey Oct 20, 2021
3092479
initialised maps with size; changed metrics update map
metonymic-smokey Oct 20, 2021
7f91580
removed extra vars; changed prom init location
metonymic-smokey Oct 20, 2021
5fd74c6
added labels and downsample resolution to metadata
metonymic-smokey Oct 20, 2021
6f0b74a
added termination condition; reverted planner type
metonymic-smokey Oct 21, 2021
ec3e767
Merge branch 'thanos-io:main' into metrics
metonymic-smokey Oct 21, 2021
a3dfae1
draft: downsampling metrics overview
metonymic-smokey Oct 22, 2021
772041a
Merge branch 'metrics' of https://github.com/metonymic-smokey/thanos …
metonymic-smokey Oct 22, 2021
ad4c704
removed extra bkt; processing individual blocks
metonymic-smokey Oct 22, 2021
3c7b8ac
Merge branch 'thanos-io:main' into metrics
metonymic-smokey Oct 22, 2021
e6739d7
changed downsample sim logic; changed plan metric names
metonymic-smokey Oct 22, 2021
b4a662b
re-used interface; refactoring
metonymic-smokey Oct 23, 2021
cdeb0d7
draft: added Prom metrics
metonymic-smokey Oct 23, 2021
7a53935
re-used planner; added flag; fixed interface
metonymic-smokey Oct 23, 2021
3b90846
increment exporters; renamed funcs/structs
metonymic-smokey Oct 24, 2021
da04db8
check if downsampling is disabled
metonymic-smokey Oct 24, 2021
8922b33
iterate through groups instead of meta
metonymic-smokey Oct 24, 2021
81a5066
run both simulations repeatedly
metonymic-smokey Oct 25, 2021
63ab795
made naming more consistent
metonymic-smokey Oct 25, 2021
235528d
added unit test for planning simulation
metonymic-smokey Oct 25, 2021
dc301ab
Merge branch 'thanos-io:main' into metrics
metonymic-smokey Oct 26, 2021
1810ba4
removed extra comments
metonymic-smokey Oct 26, 2021
a355886
fixed flag bug
metonymic-smokey Oct 26, 2021
40fa1fc
added docs for new compact flag
metonymic-smokey Oct 26, 2021
13bec69
lint fix
metonymic-smokey Oct 26, 2021
cec1c58
added sync meta to repeat loop
metonymic-smokey Oct 27, 2021
d8a1ab8
draft: downsampling unit test
metonymic-smokey Oct 28, 2021
8b23ef3
Merge branch 'thanos-io:main' into compact-metrics
metonymic-smokey Oct 28, 2021
fc71280
new group for downsample; re-used context
metonymic-smokey Oct 28, 2021
0460638
Merge branch 'compact-metrics' of https://github.com/metonymic-smokey…
metonymic-smokey Oct 28, 2021
5ea12ef
added test names and comments for downsample unit test
metonymic-smokey Oct 28, 2021
3629986
fixed copy error - changed to deep copy
metonymic-smokey Oct 28, 2021
fa40551
changed metric names
metonymic-smokey Oct 29, 2021
825a721
changed to regular flag; recreate simulator obj every run
metonymic-smokey Oct 29, 2021
6b9b326
added explanatory comments
metonymic-smokey Oct 29, 2021
adba129
removed extra var
metonymic-smokey Oct 29, 2021
87e9667
Merge branch 'thanos-io:main' into compact-metrics
metonymic-smokey Oct 29, 2021
4d7da02
re-register simulators
metonymic-smokey Oct 30, 2021
a0ea1d4
fixed names and comments
metonymic-smokey Oct 30, 2021
5c5d7b6
fix simulator obj registration
metonymic-smokey Oct 30, 2021
d788f99
added some more test cases; table test for plan simulate
metonymic-smokey Nov 2, 2021
daea946
added comments for some public methods
metonymic-smokey Nov 2, 2021
60bbe9e
lint fixes
metonymic-smokey Nov 2, 2021
9c3d11c
fixed names, logs and comments
metonymic-smokey Nov 2, 2021
afd48bf
refactored test
metonymic-smokey Nov 2, 2021
54b412f
Merge branch 'thanos-io:main' into compact-metrics
metonymic-smokey Nov 2, 2021
8f1fff7
added test cases with two groups
metonymic-smokey Nov 3, 2021
ff3ea04
added test case with non consecutive blocks
metonymic-smokey Nov 3, 2021
fa5f03f
fixed some nits
metonymic-smokey Nov 3, 2021
3c5cbce
fixed two_groups_test
metonymic-smokey Nov 3, 2021
35c4ff7
updated docs
metonymic-smokey Nov 3, 2021
639b964
draft: refactor compact progress test
metonymic-smokey Nov 5, 2021
c0caf42
draft: refactor downsample test
metonymic-smokey Nov 5, 2021
a58b63f
lint fixes and code clean up
metonymic-smokey Nov 5, 2021
8ec72e6
draft: refactored compact progress test
metonymic-smokey Nov 5, 2021
e10c845
changed func signature
metonymic-smokey Nov 5, 2021
3d0d375
draft: refactored downsample unit test to use helper func
metonymic-smokey Nov 5, 2021
6999f7f
improved test cases; CircleCI fix
metonymic-smokey Nov 6, 2021
37848f1
use reset instead of unregister; minor nits
metonymic-smokey Nov 6, 2021
e366232
improved downsample test case
metonymic-smokey Nov 6, 2021
50d1be4
E2E test fix
metonymic-smokey Nov 6, 2021
02bb607
added CHANGELOG
metonymic-smokey Nov 6, 2021
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
201 changes: 116 additions & 85 deletions pkg/compact/compact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
promtestutil "github.com/prometheus/client_golang/prometheus/testutil"
"github.com/prometheus/prometheus/pkg/labels"
"github.com/prometheus/prometheus/tsdb"

"github.com/thanos-io/thanos/pkg/block/metadata"
Expand Down Expand Up @@ -522,29 +521,44 @@ func TestCompactProgressCalculate(t *testing.T) {
return
}
}

}

func TestDownsampleProgressCalculate(t *testing.T) {
reg := prometheus.NewRegistry()
unRegisterer := &receive.UnRegisterer{Registerer: reg}
extLabels := labels.FromMap(map[string]string{"a": "1", "b": "2"})
logger := log.NewNopLogger()
type groupedResult map[string]float64

// pre calculating group keys
keys := make([]string, 3)
m := make([]metadata.Meta, 3)
m[0].Thanos.Labels = map[string]string{"a": "1"}
m[0].Thanos.Downsample.Resolution = downsample.ResLevel0
m[1].Thanos.Labels = map[string]string{"b": "2"}
m[1].Thanos.Downsample.Resolution = downsample.ResLevel1
m[2].Thanos.Labels = map[string]string{"a": "1", "b": "2"}
m[2].Thanos.Downsample.Resolution = downsample.ResLevel2
for ind, meta := range m {
keys[ind] = DefaultGroupKey(meta.Thanos)
}

var bkt objstore.Bucket
temp := prometheus.NewCounter(prometheus.CounterOpts{})
grouper := NewDefaultGrouper(logger, bkt, false, false, reg, temp, temp, temp, "")

for _, tcase := range []struct {
testName string
input []*metadata.Meta
expected float64
expected groupedResult
}{
{
// This test case has 1 block to be downsampled out of 2 since for the second block, the difference between MinTime and MaxTime is less than the acceptable threshold, DownsampleRange0
testName: "minTime_maxTime_diff_threshold_test",
testName: "first_test",
yeya24 marked this conversation as resolved.
Show resolved Hide resolved
input: []*metadata.Meta{
{
BlockMeta: tsdb.BlockMeta{
ULID: ulid.MustNew(0, nil),
MinTime: 0,
MaxTime: downsample.DownsampleRange1,
MaxTime: downsample.DownsampleRange0,
Compaction: tsdb.BlockMetaCompaction{
Sources: []ulid.ULID{ulid.MustNew(1, nil), ulid.MustNew(2, nil)},
},
Expand All @@ -553,33 +567,53 @@ func TestDownsampleProgressCalculate(t *testing.T) {
Version: 1,
Labels: map[string]string{"a": "1"},
Downsample: metadata.ThanosDownsample{
Resolution: downsample.ResLevel1,
Resolution: downsample.ResLevel0,
},
},
},
{
BlockMeta: tsdb.BlockMeta{
ULID: ulid.MustNew(3, nil),
MinTime: 1,
MaxTime: downsample.DownsampleRange0,
MaxTime: downsample.DownsampleRange1,
Compaction: tsdb.BlockMetaCompaction{
Sources: []ulid.ULID{ulid.MustNew(4, nil), ulid.MustNew(5, nil)},
},
},
Thanos: metadata.Thanos{
Version: 1,
Labels: map[string]string{"a": "1"},
Labels: map[string]string{"b": "2"},
Downsample: metadata.ThanosDownsample{
Resolution: downsample.ResLevel0,
Resolution: downsample.ResLevel1,
},
},
},
{
BlockMeta: tsdb.BlockMeta{
ULID: ulid.MustNew(4, nil),
MinTime: 1,
MaxTime: downsample.DownsampleRange1,
Compaction: tsdb.BlockMetaCompaction{
Sources: []ulid.ULID{ulid.MustNew(4, nil), ulid.MustNew(5, nil)},
},
},
Thanos: metadata.Thanos{
Version: 1,
Labels: map[string]string{"a": "1", "b": "2"},
Downsample: metadata.ThanosDownsample{
Resolution: downsample.ResLevel2,
},
},
},
},
expected: 1.0,
expected: map[string]float64{
keys[0]: 1.0,
keys[1]: 0.0,
keys[2]: 0.0,
},
},
{
// This test case returns 0 blocks to be downsampled since the resolution is resLevel2, which is skipped when grouping blocks for downsampling.
testName: "res_level_2_test",
testName: "second_test",
input: []*metadata.Meta{
{
BlockMeta: tsdb.BlockMeta{
Expand All @@ -593,16 +627,53 @@ func TestDownsampleProgressCalculate(t *testing.T) {
Thanos: metadata.Thanos{
Version: 1,
Labels: map[string]string{"a": "1"},
Downsample: metadata.ThanosDownsample{
Resolution: downsample.ResLevel0,
},
},
},
{
BlockMeta: tsdb.BlockMeta{
ULID: ulid.MustNew(7, nil),
MinTime: 1,
MaxTime: downsample.DownsampleRange1,
Compaction: tsdb.BlockMetaCompaction{
Sources: []ulid.ULID{ulid.MustNew(7, nil), ulid.MustNew(8, nil)},
},
},
Thanos: metadata.Thanos{
Version: 1,
Labels: map[string]string{"b": "2"},
Downsample: metadata.ThanosDownsample{
Resolution: downsample.ResLevel1,
},
},
},
{
BlockMeta: tsdb.BlockMeta{
ULID: ulid.MustNew(8, nil),
MinTime: 1,
MaxTime: downsample.DownsampleRange1,
Compaction: tsdb.BlockMetaCompaction{
Sources: []ulid.ULID{ulid.MustNew(7, nil), ulid.MustNew(8, nil)},
},
},
Thanos: metadata.Thanos{
Version: 1,
Labels: map[string]string{"a": "1", "b": "2"},
Downsample: metadata.ThanosDownsample{
Resolution: downsample.ResLevel2,
},
},
},
},
expected: 0.0,
expected: map[string]float64{
keys[0]: 0.0,
keys[1]: 0.0,
keys[2]: 0.0,
},
}, {
// This test case returns 1 block to be downsampled since for this block, which has a resolution of resLevel0, the difference between minTime and maxTime is greater than the acceptable threshold, DownsampleRange0.
testName: "res_level_0_test",
testName: "third_test",
input: []*metadata.Meta{
{
BlockMeta: tsdb.BlockMeta{
Expand All @@ -622,10 +693,13 @@ func TestDownsampleProgressCalculate(t *testing.T) {
},
},
},
expected: 1.0,
expected: map[string]float64{
keys[0]: 1.0,
keys[1]: 0.0,
keys[2]: 0.0,
},
}, {
// This test case returns 1 block to be downsampled since for this block, which has a resolution of resLevel1, the difference between minTime and maxTime is greater than the acceptable threshold, DownsampleRange1.
testName: "res_level_1_test",
testName: "fourth_test",
input: []*metadata.Meta{
{
BlockMeta: tsdb.BlockMeta{
Expand All @@ -645,12 +719,14 @@ func TestDownsampleProgressCalculate(t *testing.T) {
},
},
},
expected: 1.0,
expected: map[string]float64{
keys[0]: 0.0,
keys[1]: 0.0,
keys[2]: 0.0,
},
},
{
// This test case has metadata belonging to two input groups.
// It returns two blocks to be downsampled since for both the blocks, the difference between MinTime and MaxTime is above the accepted threshold for their resolution level.
testName: "two_groups_test",
testName: "fifth_test",
input: []*metadata.Meta{
{
BlockMeta: tsdb.BlockMeta{
Expand Down Expand Up @@ -687,78 +763,33 @@ func TestDownsampleProgressCalculate(t *testing.T) {
},
},
},
expected: 2.0,
expected: map[string]float64{
keys[0]: 0.0,
keys[1]: 0.0,
keys[2]: 0.0,
},
},
} {
groups := []*Group{
{
key: "a",
labels: extLabels,
resolution: downsample.ResLevel1,
metasByMinTime: tcase.input,
},
}
if ok := t.Run(tcase.testName, func(t *testing.T) {
groups := make([]*Group, 3)
yeya24 marked this conversation as resolved.
Show resolved Hide resolved

if tcase.testName == "two_groups_test" {
groups = append(groups, &Group{
resolution: 0,
key: "b",
metasByMinTime: []*metadata.Meta{
{
BlockMeta: tsdb.BlockMeta{
ULID: ulid.MustNew(0, nil),
MinTime: 0,
MaxTime: downsample.DownsampleRange1,
Compaction: tsdb.BlockMetaCompaction{
Sources: []ulid.ULID{ulid.MustNew(1, nil), ulid.MustNew(2, nil)},
},
},
Thanos: metadata.Thanos{
Version: 1,
Labels: map[string]string{"a": "1"},
Downsample: metadata.ThanosDownsample{
Resolution: downsample.ResLevel1,
},
},
},
{
BlockMeta: tsdb.BlockMeta{
ULID: ulid.MustNew(3, nil),
MinTime: 1,
MaxTime: downsample.DownsampleRange0,
Compaction: tsdb.BlockMetaCompaction{
Sources: []ulid.ULID{ulid.MustNew(4, nil), ulid.MustNew(5, nil)},
},
},
Thanos: metadata.Thanos{
Version: 1,
Labels: map[string]string{"a": "1"},
Downsample: metadata.ThanosDownsample{
Resolution: downsample.ResLevel0,
},
},
},
},
})
}
blocks := make(map[ulid.ULID]*metadata.Meta, len(tcase.input))
for _, meta := range tcase.input {
blocks[meta.ULID] = meta
}
groups, _ = grouper.Groups(blocks)
yeya24 marked this conversation as resolved.
Show resolved Hide resolved

ds := NewDownsampleProgressCalculator(unRegisterer)
if ok := t.Run(tcase.testName, func(t *testing.T) {
ds := NewDownsampleProgressCalculator(unRegisterer)
err := ds.ProgressCalculate(context.Background(), groups)
testutil.Ok(t, err)
metrics := ds.DownsampleProgressMetrics
if tcase.testName == "two_groups_test" {
a, err := metrics.NumberOfBlocksDownsampled.GetMetricWithLabelValues("b")
for _, key := range keys {
a, err := metrics.NumberOfBlocksDownsampled.GetMetricWithLabelValues(key)
if err != nil {
level.Warn(logger).Log("msg", "could not get number of blocks")
}
testutil.Equals(t, 1.0, promtestutil.ToFloat64(a))
}
a, err := metrics.NumberOfBlocksDownsampled.GetMetricWithLabelValues("a")
if err != nil {
level.Warn(logger).Log("msg", "could not get number of blocks")
testutil.Equals(t, tcase.expected[key], promtestutil.ToFloat64(a))
}
testutil.Equals(t, tcase.expected, promtestutil.ToFloat64(a))
}); !ok {
return
}
Expand Down