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

fix: check limit in loop additional to pageSize to avoid google rate … #22

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions internal/cli/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ var listAction = func(c *cli.Context) error {
if !c.IsSet("project") {
return fmt.Errorf("missing project")
}
var limit int32 = 10

opts := []tracer.ListOption{tracer.WithOnlyRootSpanView(), tracer.WithLimit(10)}

if c.IsSet("limit") {
opts = append(opts, tracer.WithLimit(int32(c.Int("limit"))))
limit = int32(c.Int("limit"))
opts = append(opts, tracer.WithLimit(limit))
}

if c.IsSet("since") {
Expand Down Expand Up @@ -55,7 +57,7 @@ var listAction = func(c *cli.Context) error {
}
defer func() { _ = trc.Close() }()

traces, err := trc.List(ctx, c.String("project"), opts...)
traces, err := trc.List(ctx, c.String("project"), limit, opts...)
if err != nil {
return fmt.Errorf("list traces: %w", err)
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (t *Tracer) MultiGet(ctx context.Context, projects []string, traceIDs []str
}

// List returns of a list of traces that match the specified options conditions.
func (t *Tracer) List(ctx context.Context, projectID string, opts ...ListOption) ([]*cloudtrace.Trace, error) {
func (t *Tracer) List(ctx context.Context, projectID string, limit int32, opts ...ListOption) ([]*cloudtrace.Trace, error) {
req := &cloudtrace.ListTracesRequest{
ProjectId: projectID,
View: cloudtrace.ListTracesRequest_COMPLETE,
Expand All @@ -63,6 +63,7 @@ func (t *Tracer) List(ctx context.Context, projectID string, opts ...ListOption)

var traces []*cloudtrace.Trace
it := t.client.ListTraces(ctx, req)
var count int32 = 0
for {
trace, err := it.Next()
if err == iterator.Done {
Expand All @@ -71,8 +72,11 @@ func (t *Tracer) List(ctx context.Context, projectID string, opts ...ListOption)
if err != nil {
return nil, err
}

count++
traces = append(traces, trace)
if count >= limit {
break
}
}

return traces, nil
Expand Down