From ed65294c9886c9af0af3cbfe0899d61f01db5534 Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Mon, 17 Aug 2020 17:35:35 -0700 Subject: [PATCH] Add Reset for trace and metrics sinks, fix logs Reset (#1570) Signed-off-by: Bogdan Drutu --- exporter/exportertest/sink_exporter.go | 19 +++++++++++++++++++ exporter/exportertest/sink_exporter_test.go | 9 +++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/exporter/exportertest/sink_exporter.go b/exporter/exportertest/sink_exporter.go index 09f03478d95..3ce02eb4c03 100644 --- a/exporter/exportertest/sink_exporter.go +++ b/exporter/exportertest/sink_exporter.go @@ -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() @@ -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 @@ -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. diff --git a/exporter/exportertest/sink_exporter_test.go b/exporter/exportertest/sink_exporter_test.go index 309cbc2c6fc..62148cc83c1 100644 --- a/exporter/exportertest/sink_exporter_test.go +++ b/exporter/exportertest/sink_exporter_test.go @@ -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())) } @@ -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())) } @@ -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())) }