Skip to content

Commit

Permalink
Merge pull request #1 from ozonru/elastic-hour-indice
Browse files Browse the repository at this point in the history
create per hour indices
  • Loading branch information
mkabischev authored Apr 1, 2019
2 parents 6bbe8dc + 71275d4 commit 0eb6a13
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 37 deletions.
2 changes: 1 addition & 1 deletion plugin/storage/es/spanstore/index_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

// returns index name with date
func indexWithDate(indexPrefix string, date time.Time) string {
spanDate := date.UTC().Format("2006-01-02")
spanDate := date.UTC().Format("2006-01-02-15")
return indexPrefix + spanDate
}

Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/es/spanstore/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func timeRangeIndices(indexNames []string, startTime time.Time, endTime time.Tim
currentIndex := indexWithDate(indexName, endTime)
for currentIndex != firstIndex {
indices = append(indices, currentIndex)
endTime = endTime.Add(-24 * time.Hour)
endTime = endTime.Add(-time.Hour)
currentIndex = indexWithDate(indexName, endTime)
}
indices = append(indices, firstIndex)
Expand Down
69 changes: 37 additions & 32 deletions plugin/storage/es/spanstore/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/uber/jaeger-lib/metrics"
"github.com/uber/jaeger-lib/metrics/metricstest"
"go.uber.org/zap"
"gopkg.in/olivere/elastic.v5"
elastic "gopkg.in/olivere/elastic.v5"

"github.com/jaegertracing/jaeger/model"
"github.com/jaegertracing/jaeger/pkg/es/mocks"
Expand Down Expand Up @@ -142,32 +142,32 @@ func TestSpanReaderIndices(t *testing.T) {
logger, _ := testutils.NewLogger()
metricsFactory := metricstest.NewFactory(0)
date := time.Now()
dateFormat := date.UTC().Format("2006-01-02")
dateFormat := date.UTC().Format("2006-01-02-15")
testCases := []struct {
indices []string
params SpanReaderParams
}{
{params:SpanReaderParams{Client:client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix:"", Archive: false},
indices: []string{spanIndex+dateFormat}},
{params:SpanReaderParams{Client:client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix:"", UseReadWriteAliases: true},
indices: []string{spanIndex+"read"}},
{params:SpanReaderParams{Client:client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix:"foo:", Archive: false},
indices: []string{"foo:"+indexPrefixSeparator+spanIndex+dateFormat,"foo:"+indexPrefixSeparatorDeprecated+spanIndex+dateFormat}},
{params:SpanReaderParams{Client:client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix:"foo:", UseReadWriteAliases: true},
indices: []string{"foo:-"+spanIndex+"read", "foo::"+spanIndex+"read"}},
{params:SpanReaderParams{Client:client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix:"", Archive: true},
indices: []string{spanIndex+archiveIndexSuffix}},
{params:SpanReaderParams{Client:client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix:"foo:", Archive: true},
indices: []string{"foo:"+indexPrefixSeparator+spanIndex+archiveIndexSuffix}},
{params:SpanReaderParams{Client:client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix:"foo:", Archive: true, UseReadWriteAliases:true},
indices: []string{"foo:"+indexPrefixSeparator+spanIndex+archiveReadIndexSuffix}},
{params: SpanReaderParams{Client: client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix: "", Archive: false},
indices: []string{spanIndex + dateFormat}},
{params: SpanReaderParams{Client: client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix: "", UseReadWriteAliases: true},
indices: []string{spanIndex + "read"}},
{params: SpanReaderParams{Client: client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix: "foo:", Archive: false},
indices: []string{"foo:" + indexPrefixSeparator + spanIndex + dateFormat, "foo:" + indexPrefixSeparatorDeprecated + spanIndex + dateFormat}},
{params: SpanReaderParams{Client: client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix: "foo:", UseReadWriteAliases: true},
indices: []string{"foo:-" + spanIndex + "read", "foo::" + spanIndex + "read"}},
{params: SpanReaderParams{Client: client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix: "", Archive: true},
indices: []string{spanIndex + archiveIndexSuffix}},
{params: SpanReaderParams{Client: client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix: "foo:", Archive: true},
indices: []string{"foo:" + indexPrefixSeparator + spanIndex + archiveIndexSuffix}},
{params: SpanReaderParams{Client: client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix: "foo:", Archive: true, UseReadWriteAliases: true},
indices: []string{"foo:" + indexPrefixSeparator + spanIndex + archiveReadIndexSuffix}},
}
for _, testCase := range testCases {
r := NewSpanReader(testCase.params)
Expand Down Expand Up @@ -347,15 +347,20 @@ func TestSpanReader_esJSONtoJSONSpanModelError(t *testing.T) {
}

func TestSpanReaderFindIndices(t *testing.T) {
today := time.Date(1995, time.April, 21, 4, 12, 19, 95, time.UTC)
yesterday := today.AddDate(0, 0, -1)
twoDaysAgo := today.AddDate(0, 0, -2)
today := time.Date(1995, time.April, 21, 0, 12, 19, 95, time.UTC)

testCases := []struct {
startTime time.Time
endTime time.Time
expected []string
}{
{
startTime: today,
endTime: today,
expected: []string{
indexWithDate(spanIndex, today),
},
},
{
startTime: today.Add(-time.Millisecond),
endTime: today,
Expand All @@ -364,20 +369,20 @@ func TestSpanReaderFindIndices(t *testing.T) {
},
},
{
startTime: today.Add(-13 * time.Hour),
startTime: today.Add(-time.Hour),
endTime: today,
expected: []string{
indexWithDate(spanIndex, today),
indexWithDate(spanIndex, yesterday),
indexWithDate(spanIndex, today.Add(-time.Hour)),
},
},
{
startTime: today.Add(-48 * time.Hour),
startTime: today.Add(-2 * time.Hour),
endTime: today,
expected: []string{
indexWithDate(spanIndex, today),
indexWithDate(spanIndex, yesterday),
indexWithDate(spanIndex, twoDaysAgo),
indexWithDate(spanIndex, today.Add(-time.Hour)),
indexWithDate(spanIndex, today.Add(-2 * time.Hour)),
},
},
}
Expand All @@ -392,7 +397,7 @@ func TestSpanReaderFindIndices(t *testing.T) {
func TestSpanReader_indexWithDate(t *testing.T) {
withSpanReader(func(r *spanReaderTest) {
actual := indexWithDate(spanIndex, time.Date(1995, time.April, 21, 4, 21, 19, 95, time.UTC))
assert.Equal(t, "jaeger-span-1995-04-21", actual)
assert.Equal(t, "jaeger-span-1995-04-21-04", actual)
})
}

Expand Down
6 changes: 3 additions & 3 deletions plugin/storage/es/spanstore/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestSpanWriterIndices(t *testing.T) {
logger, _ := testutils.NewLogger()
metricsFactory := metricstest.NewFactory(0)
date := time.Now()
dateFormat := date.UTC().Format("2006-01-02")
dateFormat := date.UTC().Format("2006-01-02-15")
testCases := []struct {
indices []string
params SpanWriterParams
Expand Down Expand Up @@ -242,8 +242,8 @@ func TestSpanIndexName(t *testing.T) {
}
spanIndexName := indexWithDate(spanIndex, span.StartTime)
serviceIndexName := indexWithDate(serviceIndex, span.StartTime)
assert.Equal(t, "jaeger-span-1995-04-21", spanIndexName)
assert.Equal(t, "jaeger-service-1995-04-21", serviceIndexName)
assert.Equal(t, "jaeger-span-1995-04-21-22", spanIndexName)
assert.Equal(t, "jaeger-service-1995-04-21-22", serviceIndexName)
}

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

0 comments on commit 0eb6a13

Please sign in to comment.