-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor handlers to separate transport and span format concerns (#1458)
* Refactor handlers Signed-off-by: Yuri Shkuro <ys@uber.com> * Fix tests Signed-off-by: Yuri Shkuro <ys@uber.com> * Fix all-in-one main Signed-off-by: Yuri Shkuro <ys@uber.com> * Appease lint Signed-off-by: Yuri Shkuro <ys@uber.com> * de-lint Signed-off-by: Yuri Shkuro <ys@uber.com>
- Loading branch information
1 parent
1703bae
commit 5c6fd91
Showing
15 changed files
with
175 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) 2019 The Jaeger Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package app | ||
|
||
import ( | ||
"github.com/uber/tchannel-go/thrift" | ||
|
||
"github.com/jaegertracing/jaeger/thrift-gen/jaeger" | ||
"github.com/jaegertracing/jaeger/thrift-gen/zipkincore" | ||
) | ||
|
||
// TChannelHandler implements jaeger.TChanCollector and zipkincore.TChanZipkinCollector. | ||
type TChannelHandler struct { | ||
jaegerHandler JaegerBatchesHandler | ||
zipkinHandler ZipkinSpansHandler | ||
} | ||
|
||
// NewTChannelHandler creates new handler that implements both Jaeger and Zipkin endpoints. | ||
func NewTChannelHandler( | ||
jaegerHandler JaegerBatchesHandler, | ||
zipkinHandler ZipkinSpansHandler, | ||
) *TChannelHandler { | ||
return &TChannelHandler{ | ||
jaegerHandler: jaegerHandler, | ||
zipkinHandler: zipkinHandler, | ||
} | ||
} | ||
|
||
// SubmitZipkinBatch implements zipkincore.TChanZipkinCollector. | ||
func (h *TChannelHandler) SubmitZipkinBatch( | ||
_ thrift.Context, | ||
spans []*zipkincore.Span, | ||
) ([]*zipkincore.Response, error) { | ||
return h.zipkinHandler.SubmitZipkinBatch(spans, SubmitBatchOptions{InboundTransport: "tchannel"}) | ||
} | ||
|
||
// SubmitBatches implements jaeger.TChanCollector. | ||
func (h *TChannelHandler) SubmitBatches( | ||
_ thrift.Context, | ||
batches []*jaeger.Batch, | ||
) ([]*jaeger.BatchSubmitResponse, error) { | ||
return h.jaegerHandler.SubmitBatches(batches, SubmitBatchOptions{InboundTransport: "tchannel"}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) 2019 The Jaeger Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package app | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/jaegertracing/jaeger/thrift-gen/jaeger" | ||
"github.com/jaegertracing/jaeger/thrift-gen/zipkincore" | ||
) | ||
|
||
var ( | ||
// verify API compliance | ||
_ jaeger.TChanCollector = new(TChannelHandler) | ||
_ zipkincore.TChanZipkinCollector = new(TChannelHandler) | ||
) | ||
|
||
type mockZipkinHandler struct { | ||
spans []*zipkincore.Span | ||
} | ||
|
||
func (p *mockZipkinHandler) SubmitZipkinBatch(spans []*zipkincore.Span, opts SubmitBatchOptions) ([]*zipkincore.Response, error) { | ||
p.spans = append(p.spans, spans...) | ||
return nil, nil | ||
} | ||
|
||
func TestTChannelHandler(t *testing.T) { | ||
jh := &mockJaegerHandler{} | ||
zh := &mockZipkinHandler{} | ||
h := NewTChannelHandler(jh, zh) | ||
h.SubmitBatches(nil, []*jaeger.Batch{ | ||
&jaeger.Batch{ | ||
Spans: []*jaeger.Span{ | ||
&jaeger.Span{OperationName: "jaeger"}, | ||
}, | ||
}, | ||
}) | ||
assert.Len(t, jh.getBatches(), 1) | ||
h.SubmitZipkinBatch(nil, []*zipkincore.Span{ | ||
&zipkincore.Span{ | ||
Name: "zipkin", | ||
}, | ||
}) | ||
assert.Len(t, zh.spans, 1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.