Skip to content

Commit bba043f

Browse files
committed
Add the API ByteSize() to request
1 parent e8807bf commit bba043f

File tree

9 files changed

+64
-2
lines changed

9 files changed

+64
-2
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: exporterhelper
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Added a new API ByteSize() to exporter.request
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [3265]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: [api]

exporter/exporterhelper/internal/retry_sender_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,10 @@ func (mer *mockErrorRequest) ItemsCount() int {
418418
return 7
419419
}
420420

421+
func (mer *mockErrorRequest) ByteSize() int {
422+
return 7
423+
}
424+
421425
func (mer *mockErrorRequest) MergeSplit(context.Context, exporterbatcher.MaxSizeConfig, internal.Request) ([]internal.Request, error) {
422426
return nil, nil
423427
}
@@ -464,6 +468,10 @@ func (m *mockRequest) ItemsCount() int {
464468
return m.cnt
465469
}
466470

471+
func (m *mockRequest) ByteSize() int {
472+
return m.cnt
473+
}
474+
467475
func (m *mockRequest) MergeSplit(context.Context, exporterbatcher.MaxSizeConfig, internal.Request) ([]internal.Request, error) {
468476
return nil, nil
469477
}

exporter/exporterhelper/logs.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ func (req *logsRequest) setCachedItemsCount(count int) {
7272
req.cachedItemsCount = count
7373
}
7474

75+
func (req *logsRequest) ByteSize() int {
76+
return logsMarshaler.LogsSize(req.ld)
77+
}
78+
7579
type logsExporter struct {
7680
*internal.BaseExporter
7781
consumer.Logs

exporter/exporterhelper/metrics.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ func (req *metricsRequest) setCachedItemsCount(count int) {
7272
req.cachedItemsCount = count
7373
}
7474

75+
func (req *metricsRequest) ByteSize() int {
76+
return metricsMarshaler.MetricsSize(req.md)
77+
}
78+
7579
type metricsExporter struct {
7680
*internal.BaseExporter
7781
consumer.Metrics

exporter/exporterhelper/traces.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ func (req *tracesRequest) setCachedItemsCount(count int) {
7272
req.cachedItemsCount = count
7373
}
7474

75+
func (req *tracesRequest) ByteSize() int {
76+
return tracesMarshaler.TracesSize(req.td)
77+
}
78+
7579
type tracesExporter struct {
7680
*internal.BaseExporter
7781
consumer.Traces

exporter/exporterhelper/xexporterhelper/profiles.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ func (req *profilesRequest) setCachedItemsCount(count int) {
7575
req.cachedItemsCount = count
7676
}
7777

78+
func (req *profilesRequest) ByteSize() int {
79+
return profilesMarshaler.ProfilesSize(req.pd)
80+
}
81+
7882
type profileExporter struct {
7983
*internal.BaseExporter
8084
xconsumer.Profiles

exporter/exporterhelper/xexporterhelper/profiles_batch_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ func (req *dummyRequest) ItemsCount() int {
152152
return 1
153153
}
154154

155+
func (req *dummyRequest) ByteSize() int {
156+
return 1
157+
}
158+
155159
func (req *dummyRequest) MergeSplit(_ context.Context, _ exporterbatcher.MaxSizeConfig, _ exporterhelper.Request) (
156160
[]exporterhelper.Request, error,
157161
) {

exporter/internal/request.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ type Request interface {
1616
// Export exports the request to an external endpoint.
1717
Export(ctx context.Context) error
1818
// ItemsCount returns a number of basic items in the request where item is the smallest piece of data that can be
19-
// sent. For example, for OTLP exporter, this value represents the number of spans,
20-
// metric data points or log records.
19+
// sent. For example, for OTLP exporter, this value represents the number of spans, metric data points or log records.
2120
ItemsCount() int
21+
// ByteSize returns the serialized byte size of of the request.
22+
ByteSize() int
2223
// MergeSplit is a function that merge and/or splits this request with another one into multiple requests based on the
2324
// configured limit provided in MaxSizeConfig.
2425
// MergeSplit does not split if all fields in MaxSizeConfig are not initialized (zero).

exporter/internal/requesttest/fake_request.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ func (s *Sink) ItemsCount() int64 {
2525
return s.itemsCount.Load()
2626
}
2727

28+
func (s *Sink) ByteSize() int64 {
29+
return s.itemsCount.Load()
30+
}
31+
2832
func NewSink() *Sink {
2933
return &Sink{
3034
requestsCount: new(atomic.Int64),
@@ -60,6 +64,10 @@ func (r *FakeRequest) ItemsCount() int {
6064
return r.Items
6165
}
6266

67+
func (r *FakeRequest) ByteSize() int {
68+
return r.Items
69+
}
70+
6371
func (r *FakeRequest) MergeSplit(_ context.Context, cfg exporterbatcher.MaxSizeConfig, r2 internal.Request) ([]internal.Request, error) {
6472
if r.MergeErr != nil {
6573
return nil, r.MergeErr

0 commit comments

Comments
 (0)