Skip to content

Commit

Permalink
Add the API ByteSize() to request
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-sili committed Jan 22, 2025
1 parent 9757ead commit 5d09bf6
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 2 deletions.
25 changes: 25 additions & 0 deletions .chloggen/add-byte-size-to-exporter-request-api.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: exporterhelper

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Added a new API ByteSize() to exporter.request

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

# (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: [api]
8 changes: 8 additions & 0 deletions exporter/exporterhelper/internal/retry_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,10 @@ func (mer *mockErrorRequest) ItemsCount() int {
return 7
}

func (mer *mockErrorRequest) ByteSize() int {
return 7
}

func (mer *mockErrorRequest) MergeSplit(context.Context, exporterbatcher.MaxSizeConfig, internal.Request) ([]internal.Request, error) {
return nil, nil
}
Expand Down Expand Up @@ -464,6 +468,10 @@ func (m *mockRequest) ItemsCount() int {
return m.cnt
}

func (m *mockRequest) ByteSize() int {
return m.cnt
}

func (m *mockRequest) MergeSplit(context.Context, exporterbatcher.MaxSizeConfig, internal.Request) ([]internal.Request, error) {
return nil, nil
}
Expand Down
4 changes: 4 additions & 0 deletions exporter/exporterhelper/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ func (req *logsRequest) ItemsCount() int {
return req.ld.LogRecordCount()
}

func (req *logsRequest) ByteSize() int {
return logsMarshaler.LogsSize(req.ld)

Check warning on line 70 in exporter/exporterhelper/logs.go

View check run for this annotation

Codecov / codecov/patch

exporter/exporterhelper/logs.go#L69-L70

Added lines #L69 - L70 were not covered by tests
}

type logsExporter struct {
*internal.BaseExporter
consumer.Logs
Expand Down
4 changes: 4 additions & 0 deletions exporter/exporterhelper/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ func (req *metricsRequest) ItemsCount() int {
return req.md.DataPointCount()
}

func (req *metricsRequest) ByteSize() int {
return metricsMarshaler.MetricsSize(req.md)

Check warning on line 70 in exporter/exporterhelper/metrics.go

View check run for this annotation

Codecov / codecov/patch

exporter/exporterhelper/metrics.go#L69-L70

Added lines #L69 - L70 were not covered by tests
}

type metricsExporter struct {
*internal.BaseExporter
consumer.Metrics
Expand Down
4 changes: 4 additions & 0 deletions exporter/exporterhelper/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ func (req *tracesRequest) ItemsCount() int {
return req.td.SpanCount()
}

func (req *tracesRequest) ByteSize() int {
return tracesMarshaler.TracesSize(req.td)

Check warning on line 70 in exporter/exporterhelper/traces.go

View check run for this annotation

Codecov / codecov/patch

exporter/exporterhelper/traces.go#L69-L70

Added lines #L69 - L70 were not covered by tests
}

type tracesExporter struct {
*internal.BaseExporter
consumer.Traces
Expand Down
4 changes: 4 additions & 0 deletions exporter/exporterhelper/xexporterhelper/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ func (req *profilesRequest) ItemsCount() int {
return req.pd.SampleCount()
}

func (req *profilesRequest) ByteSize() int {
return profilesMarshaler.ProfilesSize(req.pd)

Check warning on line 73 in exporter/exporterhelper/xexporterhelper/profiles.go

View check run for this annotation

Codecov / codecov/patch

exporter/exporterhelper/xexporterhelper/profiles.go#L72-L73

Added lines #L72 - L73 were not covered by tests
}

type profileExporter struct {
*internal.BaseExporter
xconsumer.Profiles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ func (req *dummyRequest) ItemsCount() int {
return 1
}

func (req *dummyRequest) ByteSize() int {
return 1
}

func (req *dummyRequest) MergeSplit(_ context.Context, _ exporterbatcher.MaxSizeConfig, _ exporterhelper.Request) (
[]exporterhelper.Request, error,
) {
Expand Down
5 changes: 3 additions & 2 deletions exporter/internal/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ type Request interface {
// Export exports the request to an external endpoint.
Export(ctx context.Context) error
// ItemsCount returns a number of basic items in the request where item is the smallest piece of data that can be
// sent. For example, for OTLP exporter, this value represents the number of spans,
// metric data points or log records.
// sent. For example, for OTLP exporter, this value represents the number of spans, metric data points or log records.
ItemsCount() int
// ByteSize returns the serialized byte size of of the request.
ByteSize() int
// MergeSplit is a function that merge and/or splits this request with another one into multiple requests based on the
// configured limit provided in MaxSizeConfig.
// MergeSplit does not split if all fields in MaxSizeConfig are not initialized (zero).
Expand Down
8 changes: 8 additions & 0 deletions exporter/internal/requesttest/fake_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ func (s *Sink) ItemsCount() int64 {
return s.itemsCount.Load()
}

func (s *Sink) ByteSize() int64 {
return s.itemsCount.Load()

Check warning on line 29 in exporter/internal/requesttest/fake_request.go

View check run for this annotation

Codecov / codecov/patch

exporter/internal/requesttest/fake_request.go#L28-L29

Added lines #L28 - L29 were not covered by tests
}

func NewSink() *Sink {
return &Sink{
requestsCount: new(atomic.Int64),
Expand Down Expand Up @@ -60,6 +64,10 @@ func (r *FakeRequest) ItemsCount() int {
return r.Items
}

func (r *FakeRequest) ByteSize() int {
return r.Items

Check warning on line 68 in exporter/internal/requesttest/fake_request.go

View check run for this annotation

Codecov / codecov/patch

exporter/internal/requesttest/fake_request.go#L67-L68

Added lines #L67 - L68 were not covered by tests
}

func (r *FakeRequest) MergeSplit(_ context.Context, cfg exporterbatcher.MaxSizeConfig, r2 internal.Request) ([]internal.Request, error) {
if r.MergeErr != nil {
return nil, r.MergeErr
Expand Down

0 comments on commit 5d09bf6

Please sign in to comment.