diff --git a/.github/workflows/go.yaml b/.github/workflows/go.yaml index 83d16f927c6..8b048b8dcf0 100644 --- a/.github/workflows/go.yaml +++ b/.github/workflows/go.yaml @@ -66,6 +66,41 @@ jobs: - name: Linting & vetting run: make go-lint + unit: + strategy: + fail-fast: false + runs-on: ubuntu-latest + name: Thanos unit tests + env: + GOBIN: /tmp/.bin + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Install Go. + uses: actions/setup-go@v3 + with: + go-version: 1.21.x + + - name: Install Prometheus + run: | + wget https://github.com/prometheus/prometheus/releases/download/v2.50.0/prometheus-2.50.0.linux-amd64.tar.gz + tar xvf prometheus-2.50.0.linux-amd64.tar.gz + mv prometheus-2.50.0.linux-amd64/prometheus prometheus-2.50.0.linux-amd64/prometheus-v0.37.0 + echo prometheus-2.50.0.linux-amd64 >> $GITHUB_PATH + + - uses: actions/cache@v3 + with: + path: | + ~/.cache/go-build + ~/.cache/golangci-lint + ~/go/pkg/mod + ~/prometheus-2.50.0.linux-amd64 + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + + - name: Run unit tests + run: make test-local + e2e: strategy: fail-fast: false diff --git a/pkg/compact/compact.go b/pkg/compact/compact.go index 454c322f495..38933bfc498 100644 --- a/pkg/compact/compact.go +++ b/pkg/compact/compact.go @@ -4,6 +4,7 @@ package compact import ( + "bytes" "context" "fmt" "math" @@ -1069,7 +1070,7 @@ func (cg *Group) removeOverlappingBlocks(ctx context.Context, toCompact []*metad for _, m := range toCompact { if m.ULID.Compare(kept.ULID) == 0 { level.Info(cg.logger).Log("msg", "skip the longest overlapping block", "block", m.String(), - "level", m.Compaction.Level, "source", m.Thanos.Source, "labels", m.Thanos.Labels) + "level", m.Compaction.Level, "source", m.Thanos.Source, "labels", map2str(m.Thanos.Labels)) continue } cg.overlappingBlocks.Inc() @@ -1078,9 +1079,17 @@ func (cg *Group) removeOverlappingBlocks(ctx context.Context, toCompact []*metad return nil } +func map2str(labels map[string]string) string { + b := new(bytes.Buffer) + for k, v := range labels { + fmt.Fprintf(b, "%s=%s,", k, v) + } + return b.String() +} + func DeleteBlockNow(ctx context.Context, logger log.Logger, bkt objstore.Bucket, m *metadata.Meta, dir string) error { level.Warn(logger).Log("msg", "delete polluted block immediately", "block", m.String(), - "level", m.Compaction.Level, "source", m.Thanos.Source, "labels", m.Thanos.Labels) + "level", m.Compaction.Level, "source", m.Thanos.Source, "labels", map2str(m.Thanos.Labels)) if err := block.Delete(ctx, logger, bkt, m.ULID); err != nil { return errors.Wrapf(err, "delete overlapping block %s", m.String()) }