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

refactor(blooms): Implement retry in builder #13306

Merged
merged 8 commits into from
Jun 26, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix test
  • Loading branch information
salvacorts committed Jun 25, 2024
commit e30b37fa67223e035f37a15c0fd49c2d46b358f5
18 changes: 8 additions & 10 deletions pkg/bloombuild/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"net"
"os"
"testing"
"time"

Expand All @@ -15,7 +14,6 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/stretchr/testify/require"
"go.uber.org/atomic"
"google.golang.org/grpc"

"github.com/grafana/loki/v3/pkg/bloombuild/protos"
Expand All @@ -27,8 +25,8 @@ import (
)

func Test_BuilderLoop(t *testing.T) {
//logger := log.NewNopLogger()
logger := log.NewLogfmtLogger(os.Stdout)
logger := log.NewNopLogger()
//logger := log.NewLogfmtLogger(os.Stdout)

schemaCfg := config.SchemaConfig{
Configs: []config.PeriodConfig{
Expand Down Expand Up @@ -116,9 +114,9 @@ func Test_BuilderLoop(t *testing.T) {
// Now we start the server so the builder can connect and receive tasks.
server.Start()

require.Eventuallyf(t, func() bool {
return server.CompletedTasks() == len(tasks)
}, 30*time.Second, 100*time.Millisecond, "expected all tasks to be processed, got %d. Expected %d.", server.CompletedTasks(), len(tasks))
require.Eventually(t, func() bool {
return server.CompletedTasks() >= len(tasks)
}, 10*time.Second, 500*time.Millisecond)

err = services.StopAndAwaitTerminated(context.Background(), builder)
require.NoError(t, err)
Expand All @@ -128,7 +126,7 @@ func Test_BuilderLoop(t *testing.T) {

type fakePlannerServer struct {
tasks []*protos.ProtoTask
completedTasks atomic.Int64
completedTasks int
shutdownCalled bool

lisAddr string
Expand Down Expand Up @@ -193,7 +191,7 @@ func (f *fakePlannerServer) BuilderLoop(srv protos.PlannerForBuilder_BuilderLoop
if _, err := srv.Recv(); err != nil {
return fmt.Errorf("failed to receive task response: %w", err)
}
f.completedTasks.Add(1)
f.completedTasks++
time.Sleep(10 * time.Millisecond) // Simulate task processing time to add some latency.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the sleep be before the task is counted as completed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarilly but I changed that.

}

Expand All @@ -203,7 +201,7 @@ func (f *fakePlannerServer) BuilderLoop(srv protos.PlannerForBuilder_BuilderLoop
}

func (f *fakePlannerServer) CompletedTasks() int {
return int(f.completedTasks.Load())
return f.completedTasks
}

func (f *fakePlannerServer) NotifyBuilderShutdown(_ context.Context, _ *protos.NotifyBuilderShutdownRequest) (*protos.NotifyBuilderShutdownResponse, error) {
Expand Down