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

The implementation of FindTraceIDs function for ElasticSearch reader. #1280

Merged

Conversation

vlamug
Copy link
Contributor

@vlamug vlamug commented Jan 11, 2019

Related to #1241

Which problem is this PR solving?

It allows to use FindTraceIDs function for ElasticSearch storage.

Short description of the changes

The implementations of FindTraceIDs function for ElasticSearch was added.

@vlamug vlamug changed the title The implementation of Find trace ids for es reader The implementation of FindTraceIDs function for ElasticSearch reader. Jan 11, 2019
@codecov
Copy link

codecov bot commented Jan 11, 2019

Codecov Report

Merging #1280 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #1280   +/-   ##
======================================
  Coverage     100%    100%           
======================================
  Files         162     162           
  Lines        7265    7277   +12     
======================================
+ Hits         7265    7277   +12
Impacted Files Coverage Δ
plugin/storage/es/spanstore/reader.go 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6115665...49a132a. Read the comment docs.

vlamug added 3 commits January 11, 2019 18:54
Signed-off-by: vlamug <vmugultyanov@ozon.ru>
Signed-off-by: vlamug <vmugultyanov@ozon.ru>
@vlamug vlamug force-pushed the find_trace_ids_for_es_reader branch from 470f16f to 4350e3a Compare January 11, 2019 14:54
Signed-off-by: vlamug <vmugultyanov@ozon.ru>
@vlamug vlamug force-pushed the find_trace_ids_for_es_reader branch from 15b1e4d to 0ace6df Compare January 11, 2019 15:20
Signed-off-by: vlamug <vmugultyanov@ozon.ru>
Copy link
Contributor

@vprithvi vprithvi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I'm curious about how we can reuse existing code around findTraceIDs

cc @pavolloffay

func (s *SpanReader) FindTraceIDs(ctx context.Context, traceQuery *spanstore.TraceQueryParameters) ([]model.TraceID, error) {
return nil, errors.New("not implemented") // TODO: Implement
if err := validateQuery(traceQuery); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a lot of repeated code between FindTraces and FindTraceIDs, are we able to refactor such that the initial validation and retrieval are shared?

Also, could you create a new span here - similar to L221

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks.


traceIDs := []model.TraceID{}
for _, ID := range esTraceIDs {
if len(traceIDs) >= traceQuery.NumTraces {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this required? I see that findTraceIDs already takes in traceQuery.NumTraces. Does it return a larger number of traces than specified?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I studied the implementation of such function for cassandra and there are some troubles with it, therefore the implementation for cassandra uses this condition. It seems that here it is ok. I will remove it.


traceID, err := model.TraceIDFromString(ID)
if err != nil {
return nil, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could you log the traceID string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion. Thanks.

return nil, err
}

traceIDs := []model.TraceID{}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know the length of result slice, so you can preallocate it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Thanks.

vlamug added 2 commits January 15, 2019 16:39
Signed-off-by: vlamug <vmugultyanov@ozon.ru>
Signed-off-by: vlamug <vmugultyanov@ozon.ru>
@vlamug
Copy link
Contributor Author

vlamug commented Jan 15, 2019

@vprithvi , @mkabischev , guys, the changes were added. Please, check it. Thanks.

@@ -317,6 +329,20 @@ func (s *SpanReader) multiRead(ctx context.Context, traceIDs []string, startTime
return traces, nil
}

func (s *SpanReader) validateQueryAndFindTraceIDs(ctx context.Context, traceQuery *spanstore.TraceQueryParameters) ([]string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@@ -668,11 +668,142 @@ func TestFindTraceIDs(t *testing.T) {
testGet(traceIDAggregation, t)
}

func TestFindTraceIDNotImplemented(t *testing.T) {
func TestSpanReader_TestFindTraceIDs(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests look very similar to the TestSpanReader_TestFindTraces, ... tests. Is there a way to DRY them up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, of course, I will make change soon.

Copy link
Member

@pavolloffay pavolloffay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add some integration tests to test this.

@@ -317,6 +329,20 @@ func (s *SpanReader) multiRead(ctx context.Context, traceIDs []string, startTime
return traces, nil
}

func (s *SpanReader) validateQueryAndFindTraceIDs(ctx context.Context, traceQuery *spanstore.TraceQueryParameters) ([]string, error) {
childSpan, _ := opentracing.StartSpanFromContext(ctx, "validateQueryAndFindTraceIDs")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need a span for this operation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks, I will delete it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please delete it

@pavolloffay
Copy link
Member

The integration tests can be done in a separate PR. This PR LGTM. It would be nice to reuse tests if possbile though as @vprithvi mentioned

@vlamug
Copy link
Contributor Author

vlamug commented Jan 23, 2019

Hello @vprithvi. Sorry for the late answer. I researched the possibility to refactor tests, but I do not have any idea how to do it right in such case. For example the method TestSpanReader_FindTraces has hits, but the method TestSpanReader_TestFindTraceIDs doest not. Then the method TestSpanReader_FindTraces makes call to mockMultiSearchService, but method TestSpanReader_TestFindTraceIDs does not. So, If I extract the similar functionality into separate function, it function will have many conditions: some for find traces methods, some for find trace ids methods.
If you have any suggestion, please let me know and I will make changes.
Thanks.

@vlamug
Copy link
Contributor Author

vlamug commented Jan 28, 2019

@vprithvi , hi) Could you please check the last update?)
We are waiting for the changes in this pull request in order to use FindTraceIDs function.

A lot of thanks.

@ghost ghost assigned vprithvi Jan 28, 2019
@ghost ghost added the review label Jan 28, 2019
Copy link
Contributor

@vprithvi vprithvi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vlamug While going through the code and tests, it seems that there might be a simpler way of implementing.

Could we have validateQueryAndFindTraceIDs return []model.TraceID, error instead of []string, error?

If we do this, we'll need to update multiRead to accept []model.TraceID instead of string, and update some maps inside multiRead to be indexed by model.TraceID instead of string.

On the plus side, we simplify tests because FindTraces will be using the same code paths.
FindTraceIDs could simply do:

return s.validateQueryAndFindTraceIDs(ctx, traceQuery)

and even better, we can rename validateQueryAndFindTraceIDs to FindTraceIDs.

Thanks for your contribution and the ping!

vlamug added 3 commits January 29, 2019 18:57
Signed-off-by: vlamug <vmugultyanov@ozon.ru>
… function.

Signed-off-by: vlamug <vmugultyanov@ozon.ru>
Copy link
Contributor

@vprithvi vprithvi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

Because FindTraceIDs is used by FindTraces, the old tests cover it's functionality well and thus we can remove nearly all new tests.
The new functionality that FindTraceIDs provides is converting []string to []model.TraceIDs, which we can test more easily by refactoring into something like func convertTraceStringsToTraceID([]string) ([]model.TraceID, error) and just testing that!

@@ -377,6 +395,7 @@ func validateQuery(p *spanstore.TraceQueryParameters) error {
func (s *SpanReader) findTraceIDs(ctx context.Context, traceQuery *spanstore.TraceQueryParameters) ([]string, error) {
childSpan, _ := opentracing.StartSpanFromContext(ctx, "findTraceIDs")
defer childSpan.Finish()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extraneous change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks!

@@ -333,18 +352,17 @@ func (s *SpanReader) multiRead(ctx context.Context, traceIDs []string, startTime
return nil, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that the integration tests failed. Perhaps L298 requires a traceID.String()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Thanks 👍

vlamug added 3 commits January 30, 2019 11:38
… to "convertTraceStringsToTraceID" function.

Signed-off-by: vlamug <vmugultyanov@ozon.ru>
…e of traceID models to slice of strings.

Signed-off-by: vlamug <vmugultyanov@ozon.ru>
Signed-off-by: vlamug <vmugultyanov@ozon.ru>
@vlamug
Copy link
Contributor Author

vlamug commented Jan 30, 2019

@vprithvi hello, thanks for your check and suggestion according refactoring. I fixed the integrations tests, but the ci tests were failed(https://travis-ci.org/jaegertracing/jaeger/jobs/486321151). I just run make cover command locally and all tests were finished with success result. Could you help me to understand what the problem is in these tests?
Many thanks!

assert.Nil(t, traceIDs)
assert.EqualError(t, err, "not implemented")
})
func TestTraceIDsStringsToModelsConvertation(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typo: s/convertation/conversion

assert.Equal(t, 0, len(traceIDs))
}

func TestTraceIDsModelsToStringsConvertation(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typo: s/convertation/conversion


childSpan, _ := opentracing.StartSpanFromContext(ctx, "multiRead")
childSpan.LogFields(otlog.Object("trace_ids", traceIDs))
childSpan.LogFields(otlog.Object("trace_ids", convertTraceIDsModelsToStrings(traceIDs)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this conversion necessary? The logging code is implemented as such:

func (ml fieldsAsMap) EmitObject(key string, value interface{}) {
	ml[key] = fmt.Sprintf("%+v", value)
}

which should print out traceIDs properly without doing additional work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. I just checked it and it really prints trace id is before. Ok, I will remove it. Thank you.

@vprithvi
Copy link
Contributor

@vlamug It looks like the failure wasn't related to your change! Once the question about the string conversion is answered, we can merge!

vlamug added 2 commits January 31, 2019 11:25
…edundant.

Signed-off-by: vlamug <vmugultyanov@ozon.ru>
@vlamug
Copy link
Contributor Author

vlamug commented Jan 31, 2019

@vprithvi , thank you for review. The all needed changes were made.

@vprithvi vprithvi merged commit d40ea34 into jaegertracing:master Jan 31, 2019
@ghost ghost removed the review label Jan 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants