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

Refactor handlers to separate transport and span format concerns #1458

Merged
merged 5 commits into from
Apr 4, 2019

Conversation

yurishkuro
Copy link
Member

implements #1446 (comment)

@yurishkuro yurishkuro changed the title Refactor handlers WIP Refactor handlers Apr 3, 2019
@yurishkuro yurishkuro changed the title WIP Refactor handlers Refactor handlers to separate transport and span format concerns Apr 3, 2019
"github.com/jaegertracing/jaeger/thrift-gen/zipkincore"
)

type tchannelHandler struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can add an interface for tchannel handler, that way it's more clear this handler is satisfying the thrift definition?

type tchanHandler struct {
	zipkinSpansHandler ZipkinSpansHandler
	jaegerSpansHandler JaegerBatchesHandler
}

Copy link
Member Author

Choose a reason for hiding this comment

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

it already implements existing interfaces, no benefit of defining more. I added comments and the API checks to the test file,

@codecov
Copy link

codecov bot commented Apr 3, 2019

Codecov Report

Merging #1458 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1458      +/-   ##
==========================================
+ Coverage   99.82%   99.82%   +<.01%     
==========================================
  Files         172      173       +1     
  Lines        8146     8162      +16     
==========================================
+ Hits         8132     8148      +16     
  Misses          7        7              
  Partials        7        7
Impacted Files Coverage Δ
cmd/collector/app/tchannel_handler.go 100% <100%> (ø)
cmd/collector/app/zipkin/http_handler.go 100% <100%> (ø) ⬆️
cmd/collector/app/span_processor.go 100% <100%> (ø) ⬆️
cmd/collector/app/grpc_handler.go 100% <100%> (ø) ⬆️
cmd/collector/app/thrift_span_handler.go 100% <100%> (ø)
cmd/collector/app/http_handler.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 1703bae...60cbb71. Read the comment docs.

Yuri Shkuro added 5 commits April 3, 2019 19:00
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
@guanw
Copy link
Contributor

guanw commented Apr 4, 2019

Actually can we put handlers into separate folders (e.g transport/representation/processor)? The current flat app folder doesn't help people understand handler layers.

@yurishkuro
Copy link
Member Author

We could, but the packages will be very small, one file, it's not the recommended practice in Go to have so small packages.

@@ -26,6 +26,18 @@ import (
"github.com/jaegertracing/jaeger/storage/spanstore"
)

// ProcessSpansOptions additional options passed to processor along with the spans.
type ProcessSpansOptions struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

What would happen if neither SpanFormat nor InboundTransport are set?

@@ -35,22 +34,21 @@ const (
UnknownFormatType = "unknown"
)

// SubmitBatchOptions are passed to Submit methods of the handlers.
type SubmitBatchOptions struct {
InboundTransport string
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above: what are the implications of having the InboundTransport not being specified?

Copy link
Contributor

@guanw guanw Apr 4, 2019

Choose a reason for hiding this comment

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

I have a followup story to take care of that. I imagine if InBoundTransport is not set, we would simply skip setting another dimension for span counter metrics.

Copy link
Member Author

Choose a reason for hiding this comment

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

We shouldn't skip, but assign an "undefined" value so that the total counter is still correct.

Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't skip, but assign an "undefined" value so that the total counter is still correct.

hmmm. What I meant was something like the following:

    tags := map[string]string{"svc": serviceName, "debug": debugStr}
    if endpointType != "" {
	  tags["transport"] = endpointType
    }
    c := m.factory.Counter(metrics.Options{Name: m.category, Tags: tags})

so if endpointType is empty we still count it just not having a transport tag. Is adding undefined tag mandatory here for metrics to work correctly?

Copy link
Member Author

@yurishkuro yurishkuro Apr 4, 2019

Choose a reason for hiding this comment

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

Well, first, we don't create counter objects with labels in real time, because it's expensive and we always prefer to pre-create them when possible and cache. Second, when creating a counter we must define a set of labels (tags) it has. Some metrics backends may not like the value of the label to be blank. Why not be explicit about the value then?

    tags := map[string]string{
        "svc": serviceName, 
        "debug": debugStr,  
        "transport": "undefined", // default
    }
    if endpointType != "" {
	 tags["transport"] = endpointType
    }

Copy link
Contributor

Choose a reason for hiding this comment

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

gotcha

@@ -43,7 +43,10 @@ func (g *GRPCHandler) PostSpans(ctx context.Context, r *api_v2.PostSpansRequest)
span.Process = r.Batch.Process
}
}
_, err := g.spanProcessor.ProcessSpans(r.GetBatch().Spans, JaegerFormatType)
_, err := g.spanProcessor.ProcessSpans(r.GetBatch().Spans, ProcessSpansOptions{
InboundTransport: "grpc", // TODO do we have a constant?
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we create constants if they don't exist?

Copy link
Member Author

Choose a reason for hiding this comment

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

Jude is doing it in the next PR. Right now these strings are not used anywhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I have the followup story to address that.

@yurishkuro yurishkuro merged commit 5c6fd91 into jaegertracing:master Apr 4, 2019
@yurishkuro yurishkuro deleted the refactor-handlers branch April 4, 2019 17:04
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.

4 participants