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

Change memorylimiter and queue full errors to carry time-after information #12368

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
25 changes: 25 additions & 0 deletions .chloggen/use-retry-after-errors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: memorylimiter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Change memorylimiter and queue full errors to carry time-after information

# One or more tracking issues or pull requests related to the change
issues: [12368]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
18 changes: 16 additions & 2 deletions exporter/exporterqueue/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@

import (
"context"
"errors"
"time"

"google.golang.org/genproto/googleapis/rpc/errdetails"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/durationpb"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter"
Expand All @@ -16,7 +21,16 @@
// not block.
// Experimental: This API is at the early stage of development and may change without backward compatibility
// until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved.
var ErrQueueIsFull = errors.New("sending queue is full")
var ErrQueueIsFull = func() error {
st := status.New(codes.ResourceExhausted, "sending queue is full")
dt, err := st.WithDetails(&errdetails.RetryInfo{
RetryDelay: durationpb.New(1 * time.Second),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion:

Make ErrQueueIsFull a struct type supporting the Golang errors package's Is() and As() methods, and let the OTLP receiver translate this into a status.New(codes.ResourceExhausted, err.Error()) and the WithDetails parts itself.

type QueueIsFullError struct {
  Duration time.Duration
} 
func (e QueueIsFullError) Error() string {
  return fmt.Sprintf("sending queue is full: retry after %v", e.Duration)
}
var ErrQueueIsFull = QueueIsFullError{time.Second}

Then, allow the component to configure a specific retry-after constant via the Config struct. At runtime, inside the component, use the configured retry-after and store a queueFullErr field in the component, then the user can configure this value (e.g., self.queueFullErr = QueueIsFullError{cfg.RetryAfter}. The OTLP receiver will use e.g.,

  err := pipe.Consume(ctx, request)
  candidate := exporterqueue.QueueIsFullError{}
  if errors.As(err, &candidate) {
    gst := status.New(codes.ResourceExhausted, ...)
    if dt, err := gst.withDetails(...)
       gst = dt
    }
    return gst.Err()
  }
  // ...

 

Choose a reason for hiding this comment

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

I feel that this is not a scalable solution that you are proposing unless we say there is only one error like this that we support.

Choose a reason for hiding this comment

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

The reason is because if we start adding checks for 10s of types of errors in every receiver this will become a big problem to maintain.

})
if err != nil {
panic(err)

Check warning on line 30 in exporter/exporterqueue/queue.go

View check run for this annotation

Codecov / codecov/patch

exporter/exporterqueue/queue.go#L30

Added line #L30 was not covered by tests
}
Comment on lines +29 to +31
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if err != nil {
panic(err)
}

return dt.Err()
}()

// Done represents the callback that will be called when the read request is completely processed by the
// downstream components.
Expand Down
15 changes: 14 additions & 1 deletion internal/memorylimiter/memorylimiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
"time"

"go.uber.org/zap"
"google.golang.org/genproto/googleapis/rpc/errdetails"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/durationpb"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/internal/memorylimiter/iruntime"
Expand All @@ -29,7 +33,16 @@
var (
// ErrDataRefused will be returned to callers of ConsumeTraceData to indicate
// that data is being refused due to high memory usage.
ErrDataRefused = errors.New("data refused due to high memory usage")
ErrDataRefused = func() error {
st := status.New(codes.ResourceExhausted, "data refused due to high memory usage")
dt, err := st.WithDetails(&errdetails.RetryInfo{
RetryDelay: durationpb.New(1 * time.Second),
})
if err != nil {
panic(err)

Check warning on line 42 in internal/memorylimiter/memorylimiter.go

View check run for this annotation

Codecov / codecov/patch

internal/memorylimiter/memorylimiter.go#L42

Added line #L42 was not covered by tests
}
return dt.Err()
}()

// ErrShutdownNotStarted indicates no memorylimiter has not start when shutdown
ErrShutdownNotStarted = errors.New("no existing monitoring routine is running")
Expand Down
Loading