Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #62 from Galbar/make_func_to_build_split_requests_…
Browse files Browse the repository at this point in the history
…public

Make function to build split requests public
  • Loading branch information
a-feld authored Apr 14, 2021
2 parents ee040f0 + 820d87e commit f3cf487
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion telemetry/events_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions telemetry/harvester.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion telemetry/logs_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions telemetry/metrics_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion telemetry/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
6 changes: 3 additions & 3 deletions telemetry/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion telemetry/spans_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit f3cf487

Please sign in to comment.