Skip to content

Commit

Permalink
Add Reset for trace and metrics sinks, fix logs Reset (#1570)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Aug 18, 2020
1 parent 5b30651 commit ed65294
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
19 changes: 19 additions & 0 deletions exporter/exportertest/sink_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ func (ste *SinkTraceExporter) SpansCount() int {
return ste.spansCount
}

// Reset deletes any existing metrics.
func (ste *SinkTraceExporter) Reset() {
ste.mu.Lock()
defer ste.mu.Unlock()

ste.traces = nil
ste.spansCount = 0
}

// SetConsumeTraceError sets an error that will be returned by ConsumeTraces
func (ste *SinkTraceExporter) SetConsumeTraceError(err error) {
ste.mu.Lock()
Expand Down Expand Up @@ -235,6 +244,15 @@ func (sme *SinkMetricsExporter) MetricsCount() int {
return sme.metricsCount
}

// Reset deletes any existing metrics.
func (sme *SinkMetricsExporter) Reset() {
sme.mu.Lock()
defer sme.mu.Unlock()

sme.metrics = nil
sme.metricsCount = 0
}

// Shutdown stops the exporter and is invoked during shutdown.
func (sme *SinkMetricsExporter) Shutdown(context.Context) error {
return nil
Expand Down Expand Up @@ -301,6 +319,7 @@ func (sle *SinkLogsExporter) Reset() {
defer sle.mu.Unlock()

sle.logs = nil
sle.logRecordsCount = 0
}

// Shutdown stops the exporter and is invoked during shutdown.
Expand Down
9 changes: 7 additions & 2 deletions exporter/exportertest/sink_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func TestSinkTraceExporter(t *testing.T) {
}
assert.Equal(t, want, sink.AllTraces())
assert.Equal(t, len(want), sink.SpansCount())
sink.Reset()
assert.Equal(t, 0, len(sink.AllTraces()))
assert.Equal(t, 0, sink.SpansCount())
require.NoError(t, sink.Shutdown(context.Background()))
}

Expand Down Expand Up @@ -120,6 +123,9 @@ func TestSinkMetricsExporter(t *testing.T) {
}
assert.Equal(t, want, sink.AllMetrics())
assert.Equal(t, len(want), sink.MetricsCount())
sink.Reset()
assert.Equal(t, 0, len(sink.AllMetrics()))
assert.Equal(t, 0, sink.MetricsCount())
require.NoError(t, sink.Shutdown(context.Background()))
}

Expand All @@ -145,10 +151,9 @@ func TestSinkLogsExporter(t *testing.T) {
}
assert.Equal(t, want, sink.AllLogs())
assert.Equal(t, len(want), sink.LogRecordsCount())

sink.Reset()
assert.Equal(t, 0, len(sink.AllLogs()))

assert.Equal(t, 0, sink.LogRecordsCount())
require.NoError(t, sink.Shutdown(context.Background()))
}

Expand Down

0 comments on commit ed65294

Please sign in to comment.