Skip to content

Commit

Permalink
Cut down test times (thanos-io#7861)
Browse files Browse the repository at this point in the history
Refactor so that leak detection is happening in TestMain;
Use t.Parallel() everywhere;
Reduce series/samples count in some tests that reuse the same functions
we use for benchmarking i.e. leave higher loads for benchmarks

Signed-off-by: Giedrius Statkevičius <[email protected]>
  • Loading branch information
GiedriusS authored Oct 29, 2024
1 parent 5749c8c commit 19dc4b9
Show file tree
Hide file tree
Showing 36 changed files with 373 additions and 104 deletions.
52 changes: 0 additions & 52 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,49 +15,6 @@ executors:
- image: quay.io/thanos/docker-swift-onlyone-authv2-keystone:v0.1

jobs:
test:
executor: golang-test
environment:
GO111MODULE: "on"
steps:
- git-shallow-clone/checkout
- go/load-cache
- go/mod-download
- run:
name: Download bingo modules
command: |
make install-tool-deps
- go/save-cache
- setup_remote_docker:
version: docker24
- run:
name: Create Secret if PR is not forked
# GCS integration tests are run only for author's PR that have write access, because these tests
# require credentials. Env variables that sets up these tests will work only for these kind of PRs.
command: |
if ! [ -z ${GCP_PROJECT} ]; then
echo $GOOGLE_APPLICATION_CREDENTIALS_CONTENT > $GOOGLE_APPLICATION_CREDENTIALS
echo "Awesome! GCS and S3 AWS integration tests are enabled."
fi
- run:
name: "Run unit tests."
no_output_timeout: "30m"
environment:
THANOS_TEST_OBJSTORE_SKIP: GCS,S3,AZURE,COS,ALIYUNOSS,BOS,OCI,OBS
# Variables for Swift testing.
OS_AUTH_URL: http://127.0.0.1:5000/v2.0
OS_PASSWORD: s3cr3t
OS_PROJECT_NAME: admin
OS_REGION_NAME: RegionOne
OS_USERNAME: admin
# taskset sets CPU affinity to 2 (current CPU limit).
command: |
if [ -z ${GCP_PROJECT} ]; then
export THANOS_TEST_OBJSTORE_SKIP=${THANOS_TEST_OBJSTORE_SKIP}
fi
echo "Skipping tests for object storages: ${THANOS_TEST_OBJSTORE_SKIP}"
taskset 2 make test
# Cross build is needed for publish_release but needs to be done outside of docker.
cross_build:
machine: true
Expand Down Expand Up @@ -127,27 +84,18 @@ workflows:
version: 2
thanos:
jobs:
- test:
filters:
tags:
only: /.*/
- publish_main:
requires:
- test
filters:
branches:
only: main
- cross_build:
requires:
- test
filters:
tags:
only: /^v[0-9]+(\.[0-9]+){2}(-.+|[^-.]*)$/
branches:
ignore: /.*/
- publish_release:
requires:
- test
- cross_build
filters:
tags:
Expand Down
33 changes: 32 additions & 1 deletion .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,42 @@ on:
tags:
pull_request:

# TODO(bwplotka): Add tests here.
permissions:
contents: read

jobs:
unit:
runs-on: ubuntu-latest
name: Thanos unit tests
env:
THANOS_TEST_OBJSTORE_SKIP: GCS,S3,AZURE,COS,ALIYUNOSS,BOS,OCI,OBS,SWIFT
OS_AUTH_URL: http://127.0.0.1:5000/v2.0
OS_PASSWORD: s3cr3t
OS_PROJECT_NAME: admin
OS_REGION_NAME: RegionOne
OS_USERNAME: admin
GOBIN: /tmp/.bin
services:
swift:
image: 'quay.io/thanos/docker-swift-onlyone-authv2-keystone:v0.1'
ports:
- 5000:5000
steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Install Go.
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: 1.23.x

- name: Install bingo modules
run: make install-tool-deps
- name: Add GOBIN to path
run: echo "/tmp/.bin" >> $GITHUB_PATH
- name: Run unit tests
run: make test

cross-build-check:
runs-on: ubuntu-latest
name: Go build for different platforms
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ require (
)

require (
capnproto.org/go/capnp/v3 v3.0.1-alpha.1
capnproto.org/go/capnp/v3 v3.0.1-alpha.2.0.20240830165715-46ccd63a72af
github.com/cortexproject/promqlsmith v0.0.0-20240506042652-6cfdd9739a5e
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1
github.com/hashicorp/golang-lru/v2 v2.0.7
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
capnproto.org/go/capnp/v3 v3.0.1-alpha.1 h1:hYEclwXEKsnu+PdHASdx3nLP0fC9kZnR+x1CEvMp9ck=
capnproto.org/go/capnp/v3 v3.0.1-alpha.1/go.mod h1:B+ZjwFmHwTYv201x6CdIo7MmDC/TROJDa00kbjTnv1s=
capnproto.org/go/capnp/v3 v3.0.1-alpha.2.0.20240830165715-46ccd63a72af h1:A5wxH0ZidOtYYUGjhtBaRuB87M73bGfc06uWB8sHpg0=
capnproto.org/go/capnp/v3 v3.0.1-alpha.2.0.20240830165715-46ccd63a72af/go.mod h1:2vT5D2dtG8sJGEoEKU17e+j7shdaYp1Myl8X03B3hmc=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU=
Expand Down Expand Up @@ -2098,8 +2098,8 @@ github.com/ovh/go-ovh v1.6.0 h1:ixLOwxQdzYDx296sXcgS35TOPEahJkpjMGtzPadCjQI=
github.com/ovh/go-ovh v1.6.0/go.mod h1:cTVDnl94z4tl8pP1uZ/8jlVxntjSIf09bNcQ5TJSC7c=
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2DcNVpwGmV9E1BkGknEliJkfwQj0=
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y=
github.com/philhofer/fwd v1.1.1 h1:GdGcTjf5RNAxwS4QLsiMzJYj5KEvPJD3Abr261yRQXQ=
github.com/philhofer/fwd v1.1.1/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
github.com/philhofer/fwd v1.1.2 h1:bnDivRJ1EWPjUIRXV5KfORO897HTbpFAQddBdE8t7Gw=
github.com/philhofer/fwd v1.1.2/go.mod h1:qkPdfjR2SIEbspLqpe1tO4n5yICnr2DY7mqEx2tUTP0=
github.com/phpdave11/gofpdf v1.4.2/go.mod h1:zpO6xFn9yxo3YLyMvW8HcKWVdbNqgIfOOp2dXMnm1mY=
github.com/phpdave11/gofpdi v1.0.12/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
github.com/phpdave11/gofpdi v1.0.13/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
Expand Down Expand Up @@ -2255,8 +2255,8 @@ github.com/thanos-io/promql-engine v0.0.0-20240921092401-37747eddbd31 h1:xPaP58g
github.com/thanos-io/promql-engine v0.0.0-20240921092401-37747eddbd31/go.mod h1:wx0JlRZtsB2S10JYUgeg5GqLfMxw31SzArP+28yyE00=
github.com/themihai/gomemcache v0.0.0-20180902122335-24332e2d58ab h1:7ZR3hmisBWw77ZpO1/o86g+JV3VKlk3d48jopJxzTjU=
github.com/themihai/gomemcache v0.0.0-20180902122335-24332e2d58ab/go.mod h1:eheTFp954zcWZXCU8d0AT76ftsQOTo4DTqkN/h3k1MY=
github.com/tinylib/msgp v1.1.5 h1:2gXmtWueD2HefZHQe1QOy9HVzmFrLOVvsXwXBQ0ayy0=
github.com/tinylib/msgp v1.1.5/go.mod h1:eQsjooMTnV42mHu917E26IogZ2930nFyBQdofk10Udg=
github.com/tinylib/msgp v1.1.9 h1:SHf3yoO2sGA0veCJeCBYLHuttAVFHGm2RHgNodW7wQU=
github.com/tinylib/msgp v1.1.9/go.mod h1:BCXGB54lDD8qUEPmiG0cQQUANC4IUQyB2ItS2UDlO/k=
github.com/tj/assert v0.0.3 h1:Df/BlaZ20mq6kuai7f5z2TvPFiwC3xaWJSDQNiIS3Rk=
github.com/tj/assert v0.0.3/go.mod h1:Ne6X72Q+TB1AteidzQncjw9PabbMp4PBMZ1k+vd1Pvk=
github.com/tklauser/go-sysconf v0.3.4/go.mod h1:Cl2c8ZRWfHD5IrfHo9VN+FX9kCFjIOyVklgXycLB6ek=
Expand Down
2 changes: 2 additions & 0 deletions pkg/compact/clean_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
)

func TestBestEffortCleanAbortedPartialUploads(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

Expand Down
20 changes: 20 additions & 0 deletions pkg/compact/compact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import (
)

func TestHaltError(t *testing.T) {
t.Parallel()

err := errors.New("test")
testutil.Assert(t, !IsHaltError(err), "halt error")

Expand All @@ -46,6 +48,8 @@ func TestHaltError(t *testing.T) {
}

func TestHaltMultiError(t *testing.T) {
t.Parallel()

haltErr := halt(errors.New("halt error"))
nonHaltErr := errors.New("not a halt error")

Expand All @@ -59,6 +63,8 @@ func TestHaltMultiError(t *testing.T) {
}

func TestRetryMultiError(t *testing.T) {
t.Parallel()

retryErr := retry(errors.New("retry error"))
nonRetryErr := errors.New("not a retry error")

Expand All @@ -75,6 +81,8 @@ func TestRetryMultiError(t *testing.T) {
}

func TestRetryError(t *testing.T) {
t.Parallel()

err := errors.New("test")
testutil.Assert(t, !IsRetryError(err), "retry error")

Expand All @@ -92,6 +100,8 @@ func TestRetryError(t *testing.T) {
}

func TestGroupKey(t *testing.T) {
t.Parallel()

for _, tcase := range []struct {
input metadata.Thanos
expected string
Expand Down Expand Up @@ -131,6 +141,8 @@ func TestGroupKey(t *testing.T) {
}

func TestGroupMaxMinTime(t *testing.T) {
t.Parallel()

g := &Group{
metasByMinTime: []*metadata.Meta{
{BlockMeta: tsdb.BlockMeta{MinTime: 0, MaxTime: 10}},
Expand Down Expand Up @@ -207,6 +219,8 @@ func createBlockMeta(id uint64, minTime, maxTime int64, labels map[string]string
}

func TestRetentionProgressCalculate(t *testing.T) {
t.Parallel()

logger := log.NewNopLogger()
reg := prometheus.NewRegistry()

Expand Down Expand Up @@ -328,6 +342,8 @@ func TestRetentionProgressCalculate(t *testing.T) {
}

func TestCompactProgressCalculate(t *testing.T) {
t.Parallel()

type planResult struct {
compactionBlocks, compactionRuns float64
}
Expand Down Expand Up @@ -433,6 +449,8 @@ func TestCompactProgressCalculate(t *testing.T) {
}

func TestDownsampleProgressCalculate(t *testing.T) {
t.Parallel()

reg := prometheus.NewRegistry()
logger := log.NewNopLogger()

Expand Down Expand Up @@ -532,6 +550,8 @@ func TestDownsampleProgressCalculate(t *testing.T) {
}

func TestNoMarkFilterAtomic(t *testing.T) {
t.Parallel()

ctx := context.TODO()
logger := log.NewLogfmtLogger(io.Discard)

Expand Down
8 changes: 8 additions & 0 deletions pkg/compact/planner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ func (p *tsdbPlannerAdapter) Plan(_ context.Context, metasByMinTime []*metadata.

// Adapted from https://github.com/prometheus/prometheus/blob/6c56a1faaaad07317ff585bda75b99bdba0517ad/tsdb/compact_test.go#L167
func TestPlanners_Plan_Compatibility(t *testing.T) {
t.Parallel()

ranges := []int64{
20,
60,
Expand Down Expand Up @@ -387,6 +389,8 @@ func TestPlanners_Plan_Compatibility(t *testing.T) {

// Adapted form: https://github.com/prometheus/prometheus/blob/6c56a1faaaad07317ff585bda75b99bdba0517ad/tsdb/compact_test.go#L377
func TestRangeWithFailedCompactionWontGetSelected(t *testing.T) {
t.Parallel()

ranges := []int64{
20,
60,
Expand Down Expand Up @@ -454,6 +458,8 @@ func TestRangeWithFailedCompactionWontGetSelected(t *testing.T) {
}

func TestTSDBBasedPlanner_PlanWithNoCompactMarks(t *testing.T) {
t.Parallel()

ranges := []int64{
20,
60,
Expand Down Expand Up @@ -646,6 +652,8 @@ func TestTSDBBasedPlanner_PlanWithNoCompactMarks(t *testing.T) {
}

func TestLargeTotalIndexSizeFilter_Plan(t *testing.T) {
t.Parallel()

ranges := []int64{
20,
60,
Expand Down
2 changes: 2 additions & 0 deletions pkg/compact/retention_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
)

func TestApplyRetentionPolicyByResolution(t *testing.T) {
t.Parallel()

type testBlock struct {
id string
minTime time.Time
Expand Down
Loading

0 comments on commit 19dc4b9

Please sign in to comment.