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

chore: cleanup duplicate minio contents #4983

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
46 changes: 13 additions & 33 deletions router/batchrouter/batchrouter_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package batchrouter

import (
"compress/gzip"
"context"
jsonb "encoding/json"
"errors"
Expand All @@ -15,7 +14,6 @@ import (
"testing"
"time"

miniogo "github.com/minio/minio-go/v7"
"github.com/ory/dockertest/v3"
"github.com/samber/lo"

Expand All @@ -36,6 +34,7 @@ import (
"github.com/rudderlabs/rudder-go-kit/logger"
"github.com/rudderlabs/rudder-go-kit/testhelper/docker/resource/minio"
"github.com/rudderlabs/rudder-go-kit/testhelper/docker/resource/postgres"

"github.com/rudderlabs/rudder-server/admin"
backendconfig "github.com/rudderlabs/rudder-server/backend-config"
"github.com/rudderlabs/rudder-server/jobsdb"
Expand Down Expand Up @@ -652,39 +651,20 @@ func TestBatchRouter(t *testing.T) {
defer batchrouter.Shutdown()

require.Eventually(t, func() bool {
return len(minioContents(t, context.Background(), minioResource, "")) == len(bcs)
minioContents, err := minioResource.Contents(context.Background(), "")
if err != nil {
t.Logf("error getting minio contents: %v", err)
return false
}
return len(minioContents) == len(bcs)
}, 5*time.Second, 200*time.Millisecond)

filenames := lo.Map(
lo.Keys(minioContents(t, context.Background(), minioResource, "")),
func(k string, _ int) string { return path.Dir(k) },
)

require.ElementsMatch(t, filePrefixes, filenames)
}

func minioContents(t require.TestingT, ctx context.Context, dest *minio.Resource, prefix string) map[string]string {
contents := make(map[string]string)

doneCh := make(chan struct{})
defer close(doneCh)

opts := miniogo.ListObjectsOptions{
Recursive: true,
Prefix: prefix,
}
for objInfo := range dest.Client.ListObjects(ctx, dest.BucketName, opts) {
o, err := dest.Client.GetObject(ctx, dest.BucketName, objInfo.Key, miniogo.GetObjectOptions{})
require.NoError(t, err)

g, err := gzip.NewReader(o)
require.NoError(t, err)

b, err := io.ReadAll(g)
require.NoError(t, err)
minioContents, err := minioResource.Contents(context.Background(), "")
require.NoError(t, err)

contents[objInfo.Key] = string(b)
}
filenames := lo.Map(minioContents, func(k minio.File, _ int) string {
return path.Dir(k.Key)
})

return contents
require.ElementsMatch(t, filePrefixes, filenames)
}
37 changes: 7 additions & 30 deletions warehouse/archive/archiver_test.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package archive_test

import (
"compress/gzip"
"context"
"encoding/json"
"fmt"
"io"
"os"
"regexp"
"strings"
"testing"
"time"

miniogo "github.com/minio/minio-go/v7"
"github.com/ory/dockertest/v3"
"github.com/samber/lo"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -186,7 +184,12 @@ func TestArchiver(t *testing.T) {
}
}

contents := minioContents(t, ctx, minioResource, prefix)
minioContents, err := minioResource.Contents(ctx, prefix)
require.NoError(t, err)

contents := lo.SliceToMap(minioContents, func(item minio.File) (string, string) {
return item.Key, item.Content
})

var expectedContents map[string]string
jsonTestData(t, "testdata/storage.json", &expectedContents)
Expand All @@ -211,32 +214,6 @@ func TestArchiver(t *testing.T) {
}
}

func minioContents(t require.TestingT, ctx context.Context, dest *minio.Resource, prefix string) map[string]string {
contents := make(map[string]string)

doneCh := make(chan struct{})
defer close(doneCh)

opts := miniogo.ListObjectsOptions{
Recursive: true,
Prefix: prefix,
}
for objInfo := range dest.Client.ListObjects(ctx, dest.BucketName, opts) {
o, err := dest.Client.GetObject(ctx, dest.BucketName, objInfo.Key, miniogo.GetObjectOptions{})
require.NoError(t, err)

g, err := gzip.NewReader(o)
require.NoError(t, err)

b, err := io.ReadAll(g)
require.NoError(t, err)

contents[objInfo.Key] = string(b)
}

return contents
}

func jsonTestData(t require.TestingT, file string, value any) {
f, err := os.Open(file)
require.NoError(t, err)
Expand Down
Loading