Skip to content

Commit cf461ca

Browse files
committed
Add the API ByteSize() to request
1 parent 9757ead commit cf461ca

File tree

7 files changed

+56
-2
lines changed

7 files changed

+56
-2
lines changed
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

+8
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

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ func (req *logsRequest) ItemsCount() int {
6666
return req.ld.LogRecordCount()
6767
}
6868

69+
func (req *logsRequest) ByteSize() int {
70+
return logsMarshaler.LogsSize(req.ld)
71+
}
72+
6973
type logsExporter struct {
7074
*internal.BaseExporter
7175
consumer.Logs

exporter/exporterhelper/metrics.go

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ func (req *metricsRequest) ItemsCount() int {
6666
return req.md.DataPointCount()
6767
}
6868

69+
func (req *metricsRequest) ByteSize() int {
70+
return metricsMarshaler.MetricsSize(req.md)
71+
}
72+
6973
type metricsExporter struct {
7074
*internal.BaseExporter
7175
consumer.Metrics

exporter/exporterhelper/traces.go

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ func (req *tracesRequest) ItemsCount() int {
6666
return req.td.SpanCount()
6767
}
6868

69+
func (req *tracesRequest) ByteSize() int {
70+
return tracesMarshaler.TracesSize(req.td)
71+
}
72+
6973
type tracesExporter struct {
7074
*internal.BaseExporter
7175
consumer.Traces

exporter/internal/request.go

+3-2
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

+8
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)