Skip to content

Commit 21a2739

Browse files
committed
use flush
1 parent 5ea4a96 commit 21a2739

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

exporter/splunkhecexporter/buffer.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,17 @@ func (c *cancellableGzipWriter) Reset() {
126126
}
127127

128128
func (c *cancellableGzipWriter) Flush() error {
129-
return c.innerWriter.Close()
129+
return c.innerWriter.Flush()
130130
}
131131

132132
func (c *cancellableGzipWriter) OnClose(onClose func() error) {
133133
c.onClose = onClose
134134
}
135135

136136
func (c *cancellableGzipWriter) Close() error {
137+
if err := c.innerWriter.Close(); err != nil {
138+
return err
139+
}
137140
return c.onClose()
138141
}
139142

exporter/splunkhecexporter/client.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,10 @@ func isProfilingData(sl plog.ScopeLogs) bool {
167167
// ld log records are parsed to Splunk events.
168168
func (c *client) pushLogDataInBatches(ctx context.Context, ld plog.Logs, headers map[string]string) error {
169169
buf := c.bufferPool.get()
170-
defer c.bufferPool.put(buf)
170+
buf.OnClose(func() error {
171+
c.bufferPool.put(buf)
172+
return nil
173+
})
171174
is := iterState{}
172175
var permanentErrors []error
173176

@@ -374,7 +377,10 @@ func (c *client) fillTracesBuffer(traces ptrace.Traces, buf buffer, is iterState
374377
// md metrics are parsed to Splunk events.
375378
func (c *client) pushMultiMetricsDataInBatches(ctx context.Context, md pmetric.Metrics, headers map[string]string) error {
376379
buf := c.bufferPool.get()
377-
defer c.bufferPool.put(buf)
380+
buf.OnClose(func() error {
381+
c.bufferPool.put(buf)
382+
return nil
383+
})
378384
is := iterState{}
379385

380386
var permanentErrors []error
@@ -419,7 +425,10 @@ func (c *client) pushMultiMetricsDataInBatches(ctx context.Context, md pmetric.M
419425
// md metrics are parsed to Splunk events.
420426
func (c *client) pushMetricsDataInBatches(ctx context.Context, md pmetric.Metrics, headers map[string]string) error {
421427
buf := c.bufferPool.get()
422-
defer c.bufferPool.put(buf)
428+
buf.OnClose(func() error {
429+
c.bufferPool.put(buf)
430+
return nil
431+
})
423432
is := iterState{}
424433
var permanentErrors []error
425434

0 commit comments

Comments
 (0)