diff --git a/plugin/storage/es/spanstore/writer.go b/plugin/storage/es/spanstore/writer.go index 141f40c9e9f..a0a8d77cd92 100644 --- a/plugin/storage/es/spanstore/writer.go +++ b/plugin/storage/es/spanstore/writer.go @@ -65,29 +65,20 @@ type SpanWriterParams struct { TagDotReplacement string Archive bool UseReadWriteAliases bool - ServiceCacheTTL string - IndexCacheTTL string + ServiceCacheTTL time.Duration + IndexCacheTTL time.Duration } // NewSpanWriter creates a new SpanWriter for use func NewSpanWriter(p SpanWriterParams) *SpanWriter { - var err error - serviceCacheTTL := serviceCacheTTLDefault - if p.ServiceCacheTTL != "" { - serviceCacheTTL, err = time.ParseDuration(p.ServiceCacheTTL) - if err != nil { - p.Logger.Warn("error parsing service cache duration. Using default", zap.Error(err), zap.Duration("default", serviceCacheTTLDefault)) - serviceCacheTTL = serviceCacheTTLDefault - } + serviceCacheTTL := p.ServiceCacheTTL + if p.ServiceCacheTTL == 0 { + serviceCacheTTL = serviceCacheTTLDefault } - indexCacheTTL := indexCacheTTLDefault - if p.ServiceCacheTTL != "" { - indexCacheTTL, err = time.ParseDuration(p.IndexCacheTTL) - if err != nil { - p.Logger.Warn("error parsing index cache duration. Using default", zap.Error(err), zap.Duration("default", indexCacheTTLDefault)) - indexCacheTTL = indexCacheTTLDefault - } + indexCacheTTL := p.IndexCacheTTL + if p.ServiceCacheTTL == 0 { + indexCacheTTL = indexCacheTTLDefault } serviceOperationStorage := NewServiceOperationStorage(p.Client, p.Logger, serviceCacheTTL) diff --git a/plugin/storage/es/spanstore/writer_test.go b/plugin/storage/es/spanstore/writer_test.go index 837b9b94c3f..b92cc98a0f8 100644 --- a/plugin/storage/es/spanstore/writer_test.go +++ b/plugin/storage/es/spanstore/writer_test.go @@ -360,26 +360,20 @@ func TestSpanWriterParamsTTL(t *testing.T) { logger, _ := testutils.NewLogger() metricsFactory := metricstest.NewFactory(0) testCases := []struct { - indexTTL string - serviceTTL string + indexTTL time.Duration + serviceTTL time.Duration name string expectedAddCalls int }{ { - indexTTL: indexCacheTTLDefault.String(), - serviceTTL: serviceCacheTTLDefault.String(), + indexTTL: 0, + serviceTTL: 0, name: "uses defaults", expectedAddCalls: 1, }, { - indexTTL: "invalid", - serviceTTL: "invalid2", - name: "uses defaults if invalid input", - expectedAddCalls: 1, - }, - { - indexTTL: "1ns", - serviceTTL: "1ns", + indexTTL: 1 * time.Nanosecond, + serviceTTL: 1 * time.Nanosecond, name: "uses provided values", expectedAddCalls: 3, },