From bba043f6f482cd53f5e8846d7cbd1d9848eed4c0 Mon Sep 17 00:00:00 2001 From: Sindy Li Date: Tue, 21 Jan 2025 19:02:26 -0800 Subject: [PATCH] Add the API ByteSize() to request --- ...add-byte-size-to-exporter-request-api.yaml | 25 +++++++++++++++++++ .../internal/retry_sender_test.go | 8 ++++++ exporter/exporterhelper/logs.go | 4 +++ exporter/exporterhelper/metrics.go | 4 +++ exporter/exporterhelper/traces.go | 4 +++ .../xexporterhelper/profiles.go | 4 +++ .../xexporterhelper/profiles_batch_test.go | 4 +++ exporter/internal/request.go | 5 ++-- exporter/internal/requesttest/fake_request.go | 8 ++++++ 9 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 .chloggen/add-byte-size-to-exporter-request-api.yaml diff --git a/.chloggen/add-byte-size-to-exporter-request-api.yaml b/.chloggen/add-byte-size-to-exporter-request-api.yaml new file mode 100644 index 00000000000..7d184d96a31 --- /dev/null +++ b/.chloggen/add-byte-size-to-exporter-request-api.yaml @@ -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] diff --git a/exporter/exporterhelper/internal/retry_sender_test.go b/exporter/exporterhelper/internal/retry_sender_test.go index 470f4c62e82..e6b5ae94ce2 100644 --- a/exporter/exporterhelper/internal/retry_sender_test.go +++ b/exporter/exporterhelper/internal/retry_sender_test.go @@ -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 } @@ -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 } diff --git a/exporter/exporterhelper/logs.go b/exporter/exporterhelper/logs.go index 8da4c0a7233..a2726d874f0 100644 --- a/exporter/exporterhelper/logs.go +++ b/exporter/exporterhelper/logs.go @@ -72,6 +72,10 @@ func (req *logsRequest) setCachedItemsCount(count int) { req.cachedItemsCount = count } +func (req *logsRequest) ByteSize() int { + return logsMarshaler.LogsSize(req.ld) +} + type logsExporter struct { *internal.BaseExporter consumer.Logs diff --git a/exporter/exporterhelper/metrics.go b/exporter/exporterhelper/metrics.go index 3dd7de63bd9..d95f2f62fc4 100644 --- a/exporter/exporterhelper/metrics.go +++ b/exporter/exporterhelper/metrics.go @@ -72,6 +72,10 @@ func (req *metricsRequest) setCachedItemsCount(count int) { req.cachedItemsCount = count } +func (req *metricsRequest) ByteSize() int { + return metricsMarshaler.MetricsSize(req.md) +} + type metricsExporter struct { *internal.BaseExporter consumer.Metrics diff --git a/exporter/exporterhelper/traces.go b/exporter/exporterhelper/traces.go index c79baec4cd9..2f49c8a07c8 100644 --- a/exporter/exporterhelper/traces.go +++ b/exporter/exporterhelper/traces.go @@ -72,6 +72,10 @@ func (req *tracesRequest) setCachedItemsCount(count int) { req.cachedItemsCount = count } +func (req *tracesRequest) ByteSize() int { + return tracesMarshaler.TracesSize(req.td) +} + type tracesExporter struct { *internal.BaseExporter consumer.Traces diff --git a/exporter/exporterhelper/xexporterhelper/profiles.go b/exporter/exporterhelper/xexporterhelper/profiles.go index 5b5f7d440b8..890c2722ce1 100644 --- a/exporter/exporterhelper/xexporterhelper/profiles.go +++ b/exporter/exporterhelper/xexporterhelper/profiles.go @@ -75,6 +75,10 @@ func (req *profilesRequest) setCachedItemsCount(count int) { req.cachedItemsCount = count } +func (req *profilesRequest) ByteSize() int { + return profilesMarshaler.ProfilesSize(req.pd) +} + type profileExporter struct { *internal.BaseExporter xconsumer.Profiles diff --git a/exporter/exporterhelper/xexporterhelper/profiles_batch_test.go b/exporter/exporterhelper/xexporterhelper/profiles_batch_test.go index 291a18b0c63..206f8d87ada 100644 --- a/exporter/exporterhelper/xexporterhelper/profiles_batch_test.go +++ b/exporter/exporterhelper/xexporterhelper/profiles_batch_test.go @@ -152,6 +152,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, ) { diff --git a/exporter/internal/request.go b/exporter/internal/request.go index 88a914b9e36..865f508b355 100644 --- a/exporter/internal/request.go +++ b/exporter/internal/request.go @@ -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). diff --git a/exporter/internal/requesttest/fake_request.go b/exporter/internal/requesttest/fake_request.go index d5e8e511f2c..2219c0014a2 100644 --- a/exporter/internal/requesttest/fake_request.go +++ b/exporter/internal/requesttest/fake_request.go @@ -25,6 +25,10 @@ func (s *Sink) ItemsCount() int64 { return s.itemsCount.Load() } +func (s *Sink) ByteSize() int64 { + return s.itemsCount.Load() +} + func NewSink() *Sink { return &Sink{ requestsCount: new(atomic.Int64), @@ -60,6 +64,10 @@ func (r *FakeRequest) ItemsCount() int { return r.Items } +func (r *FakeRequest) ByteSize() int { + return r.Items +} + func (r *FakeRequest) MergeSplit(_ context.Context, cfg exporterbatcher.MaxSizeConfig, r2 internal.Request) ([]internal.Request, error) { if r.MergeErr != nil { return nil, r.MergeErr