-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
The implementation of FindTraceIDs function for ElasticSearch reader. #1280
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1280 +/- ##
======================================
Coverage 100% 100%
======================================
Files 162 162
Lines 7265 7277 +12
======================================
+ Hits 7265 7277 +12
Continue to review full report at Codecov.
|
Signed-off-by: vlamug <vmugultyanov@ozon.ru>
Signed-off-by: vlamug <vmugultyanov@ozon.ru>
Signed-off-by: vlamug <vmugultyanov@ozon.ru>
470f16f
to
4350e3a
Compare
Signed-off-by: vlamug <vmugultyanov@ozon.ru>
15b1e4d
to
0ace6df
Compare
Signed-off-by: vlamug <vmugultyanov@ozon.ru>
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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{} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Thanks.
Signed-off-by: vlamug <vmugultyanov@ozon.ru>
Signed-off-by: vlamug <vmugultyanov@ozon.ru>
@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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please delete it
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 |
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 |
@vprithvi , hi) Could you please check the last update?) A lot of thanks. |
There was a problem hiding this 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!
Signed-off-by: vlamug <vmugultyanov@ozon.ru>
… function. Signed-off-by: vlamug <vmugultyanov@ozon.ru>
…to find_trace_ids_for_es_reader
There was a problem hiding this 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() | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: extraneous change
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Thanks 👍
… 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>
@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 |
assert.Nil(t, traceIDs) | ||
assert.EqualError(t, err, "not implemented") | ||
}) | ||
func TestTraceIDsStringsToModelsConvertation(t *testing.T) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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))) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@vlamug It looks like the failure wasn't related to your change! Once the question about the string conversion is answered, we can merge! |
…edundant. Signed-off-by: vlamug <vmugultyanov@ozon.ru>
…to find_trace_ids_for_es_reader
@vprithvi , thank you for review. The all needed changes were made. |
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.