Skip to content

Commit

Permalink
[chore][exporter/splunkhec] reuse metric buffer (open-telemetry#27776)
Browse files Browse the repository at this point in the history
Reuse the byte buffer used when encoding metrics to HEC events JSON.
  • Loading branch information
atoulme authored and JaredTan95 committed Oct 18, 2023
1 parent 15bc860 commit 04447dc
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion exporter/splunkhecexporter/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ func (c *client) fillMetricsBuffer(metrics pmetric.Metrics, buf buffer, is iterS
jsonStream := jsonStreamPool.Get().(*jsoniter.Stream)
defer jsonStreamPool.Put(jsonStream)

tempBuf := bytes.NewBuffer(make([]byte, 0, c.config.MaxContentLengthMetrics))
for i := is.resource; i < metrics.ResourceMetrics().Len(); i++ {
rm := metrics.ResourceMetrics().At(i)
for j := is.library; j < rm.ScopeMetrics().Len(); j++ {
Expand All @@ -259,7 +260,7 @@ func (c *client) fillMetricsBuffer(metrics pmetric.Metrics, buf buffer, is iterS

// Parsing metric record to Splunk event.
events := mapMetricToSplunkEvent(rm.Resource(), metric, c.config, c.logger)
tempBuf := bytes.NewBuffer(make([]byte, 0, c.config.MaxContentLengthMetrics))
tempBuf.Reset()
for _, event := range events {
// JSON encoding event and writing to buffer.
b, err := marshalEvent(event, c.config.MaxEventSize, jsonStream)
Expand Down

0 comments on commit 04447dc

Please sign in to comment.