Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add startTimeMillis field to JSON Spans submitted to ElasticSearch, #491

Merged
merged 4 commits into from
Nov 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions plugin/storage/es/spanstore/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ var (
"startTime":{
"type":"long"
},
"startTimeMillis":{
"type":"date",
"format":"epoch_millis"
},
"duration":{
"type":"long"
},
Expand Down
12 changes: 11 additions & 1 deletion plugin/storage/es/spanstore/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ type Service struct {
OperationName string `json:"operationName"`
}

// Span adds a StartTimeMillis field to the standard JSON span.
// ElasticSearch does not support a UNIX Epoch timestamp in microseconds,
// so Jaeger maps StartTime to a 'long' type. This extra StartTimeMillis field
// works around this issue, enabling timerange queries.
type Span struct {
*jModel.Span
StartTimeMillis uint64 `json:"startTimeMillis"`
}

// NewSpanWriter creates a new SpanWriter for use
func NewSpanWriter(
client es.Client,
Expand Down Expand Up @@ -164,7 +173,8 @@ func (s *SpanWriter) writeService(indexName string, jsonSpan *jModel.Span) error

func (s *SpanWriter) writeSpan(indexName string, jsonSpan *jModel.Span) error {
start := time.Now()
_, err := s.client.Index().Index(indexName).Type(spanType).BodyJson(jsonSpan).Do(s.ctx)
elasticSpan := Span{Span: jsonSpan, StartTimeMillis: jsonSpan.StartTime / 1000} // Microseconds to milliseconds
_, err := s.client.Index().Index(indexName).Type(spanType).BodyJson(&elasticSpan).Do(s.ctx)
s.writerMetrics.spans.Emit(err, time.Since(start))
if err != nil {
return s.logError(jsonSpan, err, "Failed to insert span", s.logger)
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 @@ -194,7 +194,7 @@ func TestSpanWriter_WriteSpan(t *testing.T) {
indexServicePut.On("Do", mock.AnythingOfType("*context.emptyCtx")).Return(nil, testCase.servicePutError)

indexSpanPut.On("Id", mock.AnythingOfType("string")).Return(indexSpanPut)
indexSpanPut.On("BodyJson", mock.AnythingOfType("*json.Span")).Return(indexSpanPut)
indexSpanPut.On("BodyJson", mock.AnythingOfType("*spanstore.Span")).Return(indexSpanPut)
indexSpanPut.On("Do", mock.AnythingOfType("*context.emptyCtx")).Return(nil, testCase.spanPutError)

w.client.On("IndexExists", stringMatcher(spanIndexName)).Return(spanExistsService)
Expand Down Expand Up @@ -346,7 +346,7 @@ func TestWriteSpanInternal(t *testing.T) {
indexName := "jaeger-1995-04-21"
indexService.On("Index", stringMatcher(indexName)).Return(indexService)
indexService.On("Type", stringMatcher(spanType)).Return(indexService)
indexService.On("BodyJson", mock.AnythingOfType("*json.Span")).Return(indexService)
indexService.On("BodyJson", mock.AnythingOfType("*spanstore.Span")).Return(indexService)
indexService.On("Do", mock.AnythingOfType("*context.emptyCtx")).Return(&elastic.IndexResponse{}, nil)

w.client.On("Index").Return(indexService)
Expand All @@ -368,7 +368,7 @@ func TestWriteSpanInternalError(t *testing.T) {
indexName := "jaeger-1995-04-21"
indexService.On("Index", stringMatcher(indexName)).Return(indexService)
indexService.On("Type", stringMatcher(spanType)).Return(indexService)
indexService.On("BodyJson", mock.AnythingOfType("*json.Span")).Return(indexService)
indexService.On("BodyJson", mock.AnythingOfType("*spanstore.Span")).Return(indexService)
indexService.On("Do", mock.AnythingOfType("*context.emptyCtx")).Return(nil, errors.New("span insertion error"))

w.client.On("Index").Return(indexService)
Expand Down