Skip to content

Commit

Permalink
Set lookback in ES rollover to distant past (#3169)
Browse files Browse the repository at this point in the history
* Set lookback in ES rollover to distant past

Signed-off-by: Pavol Loffay <p.loffay@gmail.com>

* Add test

Signed-off-by: Pavol Loffay <p.loffay@gmail.com>

* Fix test

Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
  • Loading branch information
pavolloffay committed Aug 5, 2021
1 parent 8faef4f commit 5110efd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
10 changes: 9 additions & 1 deletion plugin/storage/es/spanstore/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ const (
tagValueField = "value"

defaultNumTraces = 100

rolloverMaxSpanAge = time.Hour * 24 * 365 * 100
)

var (
Expand Down Expand Up @@ -129,10 +131,16 @@ type SpanReaderParams struct {

// NewSpanReader returns a new SpanReader with a metrics.
func NewSpanReader(p SpanReaderParams) *SpanReader {
maxSpanAge := p.MaxSpanAge
// Setting the maxSpanAge to a large duration will ensure all spans in the "read" alias are accessible by queries (query window = [now - maxSpanAge, now]).
// When read/write aliases are enabled, which are required for index rollovers, only the "read" alias is queried and therefore should not affect performance.
if p.UseReadWriteAliases {
maxSpanAge = rolloverMaxSpanAge
}
return &SpanReader{
client: p.Client,
logger: p.Logger,
maxSpanAge: p.MaxSpanAge,
maxSpanAge: maxSpanAge,
serviceOperationStorage: NewServiceOperationStorage(p.Client, p.Logger, 0), // the decorator takes care of metrics
spanIndexPrefix: indexNames(p.IndexPrefix, spanIndex),
serviceIndexPrefix: indexNames(p.IndexPrefix, serviceIndex),
Expand Down
37 changes: 28 additions & 9 deletions plugin/storage/es/spanstore/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/uber/jaeger-lib/metrics"
"github.com/uber/jaeger-lib/metrics/metricstest"
"go.uber.org/zap"

Expand Down Expand Up @@ -132,14 +131,34 @@ func withArchiveSpanReader(readAlias bool, fn func(r *spanReaderTest)) {
var _ spanstore.Reader = &SpanReader{} // check API conformance

func TestNewSpanReader(t *testing.T) {
client := &mocks.Client{}
reader := NewSpanReader(SpanReaderParams{
Client: client,
Logger: zap.NewNop(),
MaxSpanAge: 0,
MetricsFactory: metrics.NullFactory,
IndexPrefix: ""})
assert.NotNil(t, reader)
tests := []struct {
name string
params SpanReaderParams
maxSpanAge time.Duration
}{
{
name: "no rollover",
params: SpanReaderParams{
MaxSpanAge: time.Hour * 72,
},
maxSpanAge: time.Hour * 72,
},
{
name: "rollover enabled",
params: SpanReaderParams{
MaxSpanAge: time.Hour * 72,
UseReadWriteAliases: true,
},
maxSpanAge: time.Hour * 24 * 365 * 100,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
reader := NewSpanReader(test.params)
require.NotNil(t, reader)
assert.Equal(t, test.maxSpanAge, reader.maxSpanAge)
})
}
}

func TestSpanReaderIndices(t *testing.T) {
Expand Down

0 comments on commit 5110efd

Please sign in to comment.