Skip to content

Commit

Permalink
switching to time.Duration
Browse files Browse the repository at this point in the history
Signed-off-by: Tyghe Vallard <tyghe.vallard@target.com>
  • Loading branch information
Tyghe committed Jan 21, 2021
1 parent 8a8182c commit b8afaff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 29 deletions.
25 changes: 8 additions & 17 deletions plugin/storage/es/spanstore/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 6 additions & 12 deletions plugin/storage/es/spanstore/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down

0 comments on commit b8afaff

Please sign in to comment.