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

Separate query-service functionality from http handler #1312

Merged

Conversation

annanay25
Copy link
Member

Signed-off-by: Annanay annanay.a@media.net

Which problem is this PR solving?

Short description of the changes

  • Separate common utils (span reader/writer, logger, tracer) of the query-service from the APIHandler definition. This will be used by the gRPC handler as well.

Signed-off-by: Annanay <annanay.a@media.net>
@codecov
Copy link

codecov bot commented Feb 1, 2019

Codecov Report

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

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #1312   +/-   ##
======================================
  Coverage     100%    100%           
======================================
  Files         162     163    +1     
  Lines        7364    7374   +10     
======================================
+ Hits         7364    7374   +10
Impacted Files Coverage Δ
cmd/query/app/handler_options.go 100% <ø> (ø) ⬆️
cmd/query/app/http_handler.go 100% <100%> (ø)
cmd/query/app/querysvc/query_service.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 df6e276...20859e6. Read the comment docs.

cmd/query/app/query_service.go Outdated Show resolved Hide resolved
cmd/query/app/handler.go Outdated Show resolved Hide resolved
cmd/query/app/query_service.go Outdated Show resolved Hide resolved
Signed-off-by: Annanay <annanay.a@media.net>
@annanay25
Copy link
Member Author

Thanks for the review, @yurishkuro

I've addressed comments and updated the PR. (A few failing tests will be fixed soon).

cmd/query/app/querysvc/query_service.go Outdated Show resolved Hide resolved
cmd/query/app/querysvc/query_service.go Outdated Show resolved Hide resolved
cmd/query/app/querysvc/query_service_options.go Outdated Show resolved Hide resolved
cmd/query/app/http_handler.go Outdated Show resolved Hide resolved
Signed-off-by: Annanay <annanay.a@media.net>
Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

this looks pretty good, no major comments

cmd/query/app/http_handler.go Outdated Show resolved Hide resolved
cmd/query/app/http_handler.go Outdated Show resolved Hide resolved
cmd/query/app/querysvc/query_service_options.go Outdated Show resolved Hide resolved
cmd/query/app/querysvc/query_service.go Outdated Show resolved Hide resolved
cmd/query/app/querysvc/query_service.go Outdated Show resolved Hide resolved
cmd/query/app/querysvc/query_service.go Outdated Show resolved Hide resolved
cmd/query/app/querysvc/query_service.go Outdated Show resolved Hide resolved
cmd/query/main.go Outdated Show resolved Hide resolved
cmd/query/app/http_handler.go Outdated Show resolved Hide resolved
Signed-off-by: Annanay <annanay.a@media.net>
@annanay25
Copy link
Member Author

A couple of things I came across as I'm fixing the test cases after refactoring.

  1. Test cases like -
    func TestGetDependenciesSuccess(t *testing.T) {
    server, _, mock := initializeTestServer()
    defer server.Close()
    expectedDependencies := []model.DependencyLink{{Parent: "killer", Child: "queen", CallCount: 12}}
    endTs := time.Unix(0, 1476374248550*millisToNanosMultiplier)
    mock.On("GetDependencies", endTs, defaultDependencyLookbackDuration).Return(expectedDependencies, nil).Times(1)

... are going to change to -

func TestGetDependenciesSuccess(t *testing.T) {
	server, qs := initializeTestServer()
	defer server.Close()
	expectedDependencies := []model.DependencyLink{{Parent: "killer", Child: "queen", CallCount: 12}}
	endTs := time.Unix(0, 1476374248550*millisToNanosMultiplier)

And so we either need:

// Expose DependencyReader directly  
qs.DependencyReader.On("GetDependencies", endTs, defaultDependencyLookbackDuration).Return(expectedDependencies, nil).Times(1)

OR

// Expose dependencyReader through QueryService.getDepReader()
qs.getDepReader().On("GetDependencies", endTs, defaultDependencyLookbackDuration).Return(expectedDependencies, nil).Times(1)

.. (if we don't go with implementing a mock for QueryService)

  1. Since we're moving away from functional arguments, we'll now need constructors for QueryServiceOptions with signatures like -
// QueryServiceOptions has optional members of QueryService
type QueryServiceOptions struct {
	archiveSpanReader spanstore.Reader
	archiveSpanWriter spanstore.Writer
	adjuster          adjuster.Adjuster
}

// NewQueryServiceWithReader creates a QueryServiceOption with an archive reader.
func NewQueryServiceWithReader(archiveSpanReader spanstore.Reader) QueryServiceOptions

// NewQueryServiceWithWriter creates a QueryServiceOption with an archive writer.
func NewQueryServiceWithWriter(archiveSpanWriter spanstore.Writer) QueryServiceOptions 

.
.

@yurishkuro could you please review?

@yurishkuro
Copy link
Member

On the first question, initTestServer is the one that creates and returns the mocks for storage. It should continue doing that. The tests are testing the handler endpoints, they don't care if internally the init function constructs QueryService. It seems like I'm missing something that's confusing you.

On the second question, you need to make the fields of the options struct public, since they are part of the public API of the package.

Signed-off-by: Annanay <annanay.a@media.net>
Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

a couple minor nits, ready to merge otherwise

cmd/query/app/http_handler.go Show resolved Hide resolved
cmd/query/app/querysvc/query_service.go Outdated Show resolved Hide resolved
Annanay added 3 commits February 7, 2019 17:40
Signed-off-by: Annanay <annanay.a@media.net>
Signed-off-by: Annanay <annanay.a@media.net>
Signed-off-by: Annanay <annanay.a@media.net>
@annanay25
Copy link
Member Author

@yurishkuro One test is failing because the querysvc directory doesn't have a test file. Not sure what to do here.

Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

One test is failing because the querysvc directory doesn't have a test file. Not sure what to do here.

ideally, we should add tests, it's a simple one to test with mocks.

cmd/query/app/utils.go Outdated Show resolved Hide resolved
cmd/query/app/utils.go Outdated Show resolved Hide resolved
Annanay added 2 commits February 7, 2019 23:52
Signed-off-by: Annanay <annanay.a@media.net>
Signed-off-by: Annanay <annanay.a@media.net>
@annanay25 annanay25 mentioned this pull request Feb 8, 2019
4 tasks
@annanay25
Copy link
Member Author

I've added an empty test for now because we have all the mock-tests in place for the reader/writer handlers anyway. Could you re-run travis on this @yurishkuro? The build seems to be failing with an unrelated error.

@ghost ghost assigned yurishkuro Feb 10, 2019
@ghost ghost added the review label Feb 10, 2019
@yurishkuro
Copy link
Member

@annanay25 there is a drop in code coverage, which shouldn't happen with plain refactoring. Could you find a way to bring coverage back?

@annanay25
Copy link
Member Author

Looking into this.

Annanay added 3 commits February 12, 2019 10:19
Signed-off-by: Annanay <annanay.a@media.net>
Signed-off-by: Annanay <annanay.a@media.net>
Signed-off-by: Annanay <annanay.a@media.net>
Annanay added 3 commits February 15, 2019 00:38
Signed-off-by: Annanay <annanay.a@media.net>
Signed-off-by: Annanay <annanay.a@media.net>
Signed-off-by: Annanay <annanay.a@media.net>
@annanay25
Copy link
Member Author

@yurishkuro Build is green :)

@annanay25
Copy link
Member Author

@yurishkuro can we go ahead with this?

handler.RegisterRoutes(r)
return httptest.NewServer(r), readStorage, dependencyStorage, handler
}

func initializeTestServerWithQueryOptions(queryOptions querysvc.QueryServiceOptions, options ...HandlerOption) (*httptest.Server, *spanstoremocks.Reader, *depsmocks.Reader) {
Copy link
Member

Choose a reason for hiding this comment

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

this is identical to initializeTestServerWithOptions, please remove

Signed-off-by: Annanay <annanay.a@media.net>
@yurishkuro yurishkuro changed the title [query] Separate common utils of query-service from APIHandler Separate query-service functionality from http handler Feb 18, 2019
@yurishkuro yurishkuro merged commit ed6acfb into jaegertracing:master Feb 18, 2019
@ghost ghost removed the review label Feb 18, 2019
@yurishkuro
Copy link
Member

🎉 🎈

@annanay25
Copy link
Member Author

Thanks Yuri! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants