Skip to content

Commit ea4ffba

Browse files
authored
Use OTEL fork with patched Jaeger receiver (hypertrace#23)
* Use OTEL fork with patched Jaeger receiver with request header and test it Signed-off-by: Pavol Loffay <[email protected]> * use branch Signed-off-by: Pavol Loffay <[email protected]>
1 parent cfa8fe5 commit ea4ffba

File tree

3 files changed

+123
-10
lines changed

3 files changed

+123
-10
lines changed

go.mod

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ go 1.15
44

55
require (
66
github.com/antlr/antlr4 v0.0.0-20210127121638-62a0b02bf460
7+
github.com/apache/thrift v0.13.0
8+
github.com/jaegertracing/jaeger v1.21.0
79
github.com/json-iterator/go v1.1.10
8-
github.com/stretchr/testify v1.6.1
10+
github.com/stretchr/testify v1.7.0
911
go.opencensus.io v0.22.5
1012
go.opentelemetry.io/collector v0.18.0
1113
go.uber.org/zap v1.16.0
12-
google.golang.org/grpc v1.34.1
14+
google.golang.org/grpc v1.35.0
1315
)
16+
17+
// branch jaeger-thrift-http-headers
18+
replace go.opentelemetry.io/collector => github.com/hypertrace/opentelemetry-collector v0.7.1-0.20210203140508-3124456ebb6a

go.sum

+10-8
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4
175175
github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI=
176176
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
177177
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
178-
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
178+
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
179179
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
180180
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd h1:qMd81Ts1T2OTKmB4acZcyKaMtRnY5Y44NuXGX2GFJ1w=
181181
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
@@ -245,7 +245,7 @@ github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4s
245245
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
246246
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
247247
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
248-
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
248+
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
249249
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
250250
github.com/evanphx/json-patch v4.9.0+incompatible h1:kLcOMZeuLAJvL2BPWLMIj5oaZQobrkAqrL+WFZwQses=
251251
github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
@@ -463,8 +463,8 @@ github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
463463
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
464464
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
465465
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
466-
github.com/google/uuid v1.1.4 h1:0ecGp3skIrHWPNGPJDaBIghfA6Sp7Ruo2Io8eLKzWm0=
467-
github.com/google/uuid v1.1.4/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
466+
github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs=
467+
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
468468
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
469469
github.com/googleapis/gax-go/v2 v2.0.5 h1:sjZBwGj9Jlw33ImPtvFviGYvseOtDM7hkSKB7+Tv3SM=
470470
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
@@ -563,6 +563,8 @@ github.com/hetznercloud/hcloud-go v1.22.0 h1:CC0jwkaBzwP4ObFE0sdJBTvGh5DE9kB/tuD
563563
github.com/hetznercloud/hcloud-go v1.22.0/go.mod h1:xng8lbDUg+xM1dgc0yGHX5EeqbwIq7UYlMWMTx3SQVg=
564564
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
565565
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
566+
github.com/hypertrace/opentelemetry-collector v0.7.1-0.20210203140508-3124456ebb6a h1:+BFhazwjnosnBh0oe8k3HrBYDVaQVnpTkDpRTD0K1RU=
567+
github.com/hypertrace/opentelemetry-collector v0.7.1-0.20210203140508-3124456ebb6a/go.mod h1:KZcMoF4fYwruBKDP0e3Xi4fW6sYnia0xqw+WlVQzeuA=
566568
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
567569
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
568570
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
@@ -959,6 +961,8 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
959961
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
960962
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
961963
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
964+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
965+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
962966
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
963967
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
964968
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
@@ -1011,8 +1015,6 @@ go.opencensus.io v0.22.4 h1:LYy1Hy3MJdrCdMwwzxA/dRok4ejH+RwNGbuoD9fCjto=
10111015
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
10121016
go.opencensus.io v0.22.5 h1:dntmOdLpSpHlVqbW5Eay97DelsZHe+55D+xC6i0dDS0=
10131017
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
1014-
go.opentelemetry.io/collector v0.18.0 h1:Y9f40zmV5gfIuyy8CHujW0vdBpCYs7d10GAyFGBhs+U=
1015-
go.opentelemetry.io/collector v0.18.0/go.mod h1:AtTlgj8BFatJAkL4+2lM5+DkK7tqHzjeci6rB97HbhQ=
10161018
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
10171019
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
10181020
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
@@ -1416,8 +1418,8 @@ google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM
14161418
google.golang.org/grpc v1.32.0 h1:zWTV+LMdc3kaiJMSTOFz2UgSBgx8RNQoTGiZu3fR9S0=
14171419
google.golang.org/grpc v1.32.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
14181420
google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
1419-
google.golang.org/grpc v1.34.1 h1:ugq+9++ZQPFzM2pKUMCIK8gj9M0pFyuUWO9Q8kwEDQw=
1420-
google.golang.org/grpc v1.34.1/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8=
1421+
google.golang.org/grpc v1.35.0 h1:TwIQcH3es+MojMVojxxfQ3l3OF2KzlRxML2xZq0kRo8=
1422+
google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
14211423
google.golang.org/grpc/examples v0.0.0-20200728065043-dfc0c05b2da9 h1:f+/+gfZ/tfaHBXXiv1gWRmCej6wlX3mLY4bnLpI99wk=
14221424
google.golang.org/grpc/examples v0.0.0-20200728065043-dfc0c05b2da9/go.mod h1:5j1uub0jRGhRiSghIlrThmBUgcgLXOVJQ/l1getT4uo=
14231425
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=

processors/tenantidprocessor/tenantidprocessor_test.go

+106
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
11
package tenantidprocessor
22

33
import (
4+
"bytes"
45
"context"
6+
"fmt"
7+
"io"
8+
"io/ioutil"
9+
"net/http"
510
"testing"
611
"time"
712

13+
"github.com/apache/thrift/lib/go/thrift"
14+
"github.com/jaegertracing/jaeger/model"
15+
jaegerconvert "github.com/jaegertracing/jaeger/model/converter/thrift/jaeger"
16+
jaegerthrift "github.com/jaegertracing/jaeger/thrift-gen/jaeger"
817
"github.com/stretchr/testify/assert"
918
"github.com/stretchr/testify/require"
1019
"go.opentelemetry.io/collector/component"
1120
"go.opentelemetry.io/collector/component/componenttest"
1221
"go.opentelemetry.io/collector/config/configgrpc"
22+
"go.opentelemetry.io/collector/config/confighttp"
1323
"go.opentelemetry.io/collector/config/configtls"
1424
"go.opentelemetry.io/collector/consumer"
1525
"go.opentelemetry.io/collector/consumer/consumertest"
1626
"go.opentelemetry.io/collector/consumer/pdata"
1727
"go.opentelemetry.io/collector/exporter/otlpexporter"
28+
"go.opentelemetry.io/collector/receiver/jaegerreceiver"
1829
"go.opentelemetry.io/collector/receiver/otlpreceiver"
1930
"go.opentelemetry.io/collector/testutil"
31+
"go.opentelemetry.io/collector/translator/trace/jaeger"
2032
"go.uber.org/zap"
2133
"google.golang.org/grpc"
2234
"google.golang.org/grpc/metadata"
@@ -145,6 +157,54 @@ func TestReceiveOTLPGRPC(t *testing.T) {
145157
assert.Equal(t, reqTraces.SpanCount(), tenantAttrsFound)
146158
}
147159

160+
func TestReceiveJaegerThriftHTTP(t *testing.T) {
161+
sink := new(consumertest.TracesSink)
162+
tenantProcessor := &processor{
163+
logger: zap.NewNop(),
164+
tenantIDHeaderName: defaultTenantIdHeaderName,
165+
tenantIDAttributeKey: defaultTenantIdAttributeKey,
166+
}
167+
168+
addr := testutil.GetAvailableLocalAddress(t)
169+
cfg := &jaegerreceiver.Config{
170+
Protocols: jaegerreceiver.Protocols{
171+
ThriftHTTP: &confighttp.HTTPServerSettings{
172+
Endpoint: addr,
173+
},
174+
},
175+
}
176+
params := component.ReceiverCreateParams{Logger: zap.NewNop()}
177+
jrf := jaegerreceiver.NewFactory()
178+
rec, err := jrf.CreateTracesReceiver(context.Background(), params, cfg, multiConsumer{
179+
sink: sink,
180+
tenantIDprocessor: tenantProcessor,
181+
})
182+
require.NoError(t, err)
183+
184+
err = rec.Start(context.Background(), componenttest.NewNopHost())
185+
require.NoError(t, err)
186+
defer rec.Shutdown(context.Background())
187+
188+
td := GenerateTraceDataOneSpan()
189+
batches, err := jaeger.InternalTracesToJaegerProto(td)
190+
require.NoError(t, err)
191+
collectorAddr := fmt.Sprintf("http://%s/api/traces", addr)
192+
for _, batch := range batches {
193+
err := sendToJaegerHTTPThrift(collectorAddr, map[string]string{tenantProcessor.tenantIDHeaderName: testTenantID},jaegerModelToThrift(batch))
194+
require.NoError(t, err)
195+
}
196+
197+
traces := sink.AllTraces()
198+
assert.Equal(t, 1, len(traces))
199+
tenantAttrsFound := assertTenantAttributeExists(
200+
t,
201+
traces[0],
202+
tenantProcessor.tenantIDAttributeKey,
203+
testTenantID,
204+
)
205+
assert.Equal(t, td.SpanCount(), tenantAttrsFound)
206+
}
207+
148208
func assertTenantAttributeExists(t *testing.T, trace pdata.Traces, tenantAttrKey string, tenantID string) int {
149209
numOfTenantAttrs := 0
150210
rss := trace.ResourceSpans()
@@ -242,6 +302,8 @@ func fillSpanOne(span pdata.Span) {
242302
span.SetStartTime(TestSpanStartTimestamp)
243303
span.SetEndTime(TestSpanEndTimestamp)
244304
span.SetDroppedAttributesCount(1)
305+
span.SetTraceID(pdata.NewTraceID([16]byte{0, 1, 2}))
306+
span.SetSpanID(pdata.NewSpanID([8]byte{0, 1}))
245307
evs := span.Events()
246308
evs.Resize(2)
247309
ev0 := evs.At(0)
@@ -262,3 +324,47 @@ func fillSpanOne(span pdata.Span) {
262324
func initSpanEventAttributes(dest pdata.AttributeMap) {
263325
dest.InitFromMap(spanEventAttributes)
264326
}
327+
328+
func jaegerModelToThrift(batch *model.Batch) *jaegerthrift.Batch {
329+
return &jaegerthrift.Batch{
330+
Process: jaegerProcessModelToThrift(batch.Process),
331+
Spans: jaegerconvert.FromDomain(batch.Spans),
332+
}
333+
}
334+
335+
func jaegerProcessModelToThrift(process *model.Process) *jaegerthrift.Process {
336+
if process == nil {
337+
return nil
338+
}
339+
return &jaegerthrift.Process{
340+
ServiceName: process.ServiceName,
341+
}
342+
}
343+
344+
func sendToJaegerHTTPThrift(endpoint string, headers map[string]string, batch *jaegerthrift.Batch) error {
345+
buf, err := thrift.NewTSerializer().Write(context.Background(), batch)
346+
if err != nil {
347+
return err
348+
}
349+
req, err := http.NewRequest("POST", endpoint, bytes.NewBuffer(buf))
350+
if err != nil {
351+
return err
352+
}
353+
req.Header.Set("Content-Type", "application/x-thrift")
354+
for k, v := range headers {
355+
req.Header.Add(k, v)
356+
}
357+
358+
resp, err := http.DefaultClient.Do(req)
359+
if err != nil {
360+
return err
361+
}
362+
363+
io.Copy(ioutil.Discard, resp.Body)
364+
resp.Body.Close()
365+
366+
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
367+
return fmt.Errorf("failed to upload traces; HTTP status code: %d", resp.StatusCode)
368+
}
369+
return nil
370+
}

0 commit comments

Comments
 (0)