From 820d87ecdc8943e8f4344ff7fc04546c171d0176 Mon Sep 17 00:00:00 2001 From: Alessio Linares Date: Wed, 14 Apr 2021 18:35:11 +0200 Subject: [PATCH] Make function to build split requests public --- telemetry/events_group_test.go | 2 +- telemetry/harvester.go | 8 ++++---- telemetry/logs_group_test.go | 2 +- telemetry/metrics_group_test.go | 4 ++-- telemetry/request.go | 3 ++- telemetry/request_test.go | 6 +++--- telemetry/spans_group_test.go | 2 +- 7 files changed, 14 insertions(+), 13 deletions(-) diff --git a/telemetry/events_group_test.go b/telemetry/events_group_test.go index 94989c6..a358f3b 100644 --- a/telemetry/events_group_test.go +++ b/telemetry/events_group_test.go @@ -16,7 +16,7 @@ func testEventGroupJSON(t testing.TB, batches []Batch, expect string) { th.Helper() } factory, _ := NewEventRequestFactory(WithNoDefaultKey()) - reqs, err := newRequests(batches, factory) + reqs, err := BuildSplitRequests(batches, factory) if nil != err { t.Fatal(err) } diff --git a/telemetry/harvester.go b/telemetry/harvester.go index e3471f9..c02dd25 100644 --- a/telemetry/harvester.go +++ b/telemetry/harvester.go @@ -332,7 +332,7 @@ func (h *Harvester) swapOutMetrics(now time.Time) []*http.Request { } group := &metricGroup{Metrics: rawMetrics} entries := []MapEntry{commonBlock, group} - reqs, err := newRequests([]Batch{entries}, h.metricRequestFactory) + reqs, err := BuildSplitRequests([]Batch{entries}, h.metricRequestFactory) if nil != err { h.config.logError(map[string]interface{}{ "err": err.Error(), @@ -358,7 +358,7 @@ func (h *Harvester) swapOutSpans() []*http.Request { entries = append(entries, &spanCommonBlock{attributes: h.commonAttributes}) } entries = append(entries, &spanGroup{Spans: sps}) - reqs, err := newRequests([]Batch{entries}, h.spanRequestFactory) + reqs, err := BuildSplitRequests([]Batch{entries}, h.spanRequestFactory) if nil != err { h.config.logError(map[string]interface{}{ "err": err.Error(), @@ -381,7 +381,7 @@ func (h *Harvester) swapOutEvents() []*http.Request { group := &eventGroup{ Events: events, } - reqs, err := newRequests([]Batch{{group}}, h.eventRequestFactory) + reqs, err := BuildSplitRequests([]Batch{{group}}, h.eventRequestFactory) if nil != err { h.config.logError(map[string]interface{}{ "err": err.Error(), @@ -407,7 +407,7 @@ func (h *Harvester) swapOutLogs() []*http.Request { entries = append(entries, &logCommonBlock{attributes: h.commonAttributes}) } entries = append(entries, &logGroup{Logs: logs}) - reqs, err := newRequests([]Batch{entries}, h.logRequestFactory) + reqs, err := BuildSplitRequests([]Batch{entries}, h.logRequestFactory) if nil != err { h.config.logError(map[string]interface{}{ "err": err.Error(), diff --git a/telemetry/logs_group_test.go b/telemetry/logs_group_test.go index feba80a..770e87b 100644 --- a/telemetry/logs_group_test.go +++ b/telemetry/logs_group_test.go @@ -16,7 +16,7 @@ func testLogGroupJSON(t testing.TB, batches []Batch, expect string) { th.Helper() } factory, _ := NewLogRequestFactory(WithNoDefaultKey()) - reqs, err := newRequests(batches, factory) + reqs, err := BuildSplitRequests(batches, factory) if nil != err { t.Fatal(err) } diff --git a/telemetry/metrics_group_test.go b/telemetry/metrics_group_test.go index e0f02b8..d712222 100644 --- a/telemetry/metrics_group_test.go +++ b/telemetry/metrics_group_test.go @@ -81,7 +81,7 @@ func TestMetrics(t *testing.T) { }]`) factory, _ := NewMetricRequestFactory(WithNoDefaultKey()) - reqs, err := newRequests([]Batch{{commonBlock, NewMetricGroup(metrics)}}, factory) + reqs, err := BuildSplitRequests([]Batch{{commonBlock, NewMetricGroup(metrics)}}, factory) if err != nil { t.Error("error creating request", err) } @@ -117,7 +117,7 @@ func testGroupJSON(t testing.TB, batches []Batch, expect string) { th.Helper() } factory, _ := NewMetricRequestFactory(WithNoDefaultKey()) - reqs, err := newRequests(batches, factory) + reqs, err := BuildSplitRequests(batches, factory) if nil != err { t.Fatal(err) } diff --git a/telemetry/request.go b/telemetry/request.go index 595e056..7696482 100644 --- a/telemetry/request.go +++ b/telemetry/request.go @@ -25,7 +25,8 @@ func requestNeedsSplit(r *http.Request) bool { return r.ContentLength >= maxCompressedSizeBytes } -func newRequests(batches []Batch, factory RequestFactory) ([]*http.Request, error) { +// BuildSplitRequests converts a []Batch into a collection of appropiately sized requests +func BuildSplitRequests(batches []Batch, factory RequestFactory) ([]*http.Request, error) { return newRequestsInternal(batches, factory, requestNeedsSplit) } diff --git a/telemetry/request_test.go b/telemetry/request_test.go index 6347bd8..f550976 100644 --- a/telemetry/request_test.go +++ b/telemetry/request_test.go @@ -214,7 +214,7 @@ func TestNeedsToSplitBatchesAndEntries(t *testing.T) { rawData: randomJSON(maxCompressedSizeBytes), }, } - reqs, err := newRequests([]Batch{group1, group2}, testFactory()) + reqs, err := BuildSplitRequests([]Batch{group1, group2}, testFactory()) if err != nil { t.Fatal(err) } @@ -226,7 +226,7 @@ func TestNeedsToSplitBatchesAndEntries(t *testing.T) { func TestLargeRequestNeedsSplit(t *testing.T) { js := randomJSON(4 * maxCompressedSizeBytes) payloadEntry := testUnsplittablePayloadEntry{rawData: js} - reqs, err := newRequests([]Batch{{&payloadEntry}}, testFactory()) + reqs, err := BuildSplitRequests([]Batch{{&payloadEntry}}, testFactory()) if reqs != nil { t.Error(reqs) } @@ -238,7 +238,7 @@ func TestLargeRequestNeedsSplit(t *testing.T) { func TestLargeRequestNoSplit(t *testing.T) { js := randomJSON(maxCompressedSizeBytes / 2) payloadEntry := testUnsplittablePayloadEntry{rawData: js} - reqs, err := newRequests([]Batch{{&payloadEntry}}, testFactory()) + reqs, err := BuildSplitRequests([]Batch{{&payloadEntry}}, testFactory()) if err != nil { t.Fatal(err) } diff --git a/telemetry/spans_group_test.go b/telemetry/spans_group_test.go index ba88192..4774313 100644 --- a/telemetry/spans_group_test.go +++ b/telemetry/spans_group_test.go @@ -16,7 +16,7 @@ func testSpanGroupJSON(t testing.TB, batches []Batch, expect string) { th.Helper() } factory, _ := NewSpanRequestFactory(WithNoDefaultKey()) - reqs, err := newRequests(batches, factory) + reqs, err := BuildSplitRequests(batches, factory) if nil != err { t.Fatal(err) }