Small nit fixes, remove unnecessary mock and overrides (#3150)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
This commit is contained in:
parent
d5891ec866
commit
d1ee31e93c
|
@ -20,7 +20,6 @@ import (
|
|||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/component/componenthelper"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/consumer"
|
||||
"go.opentelemetry.io/collector/consumer/consumertest"
|
||||
)
|
||||
|
||||
|
@ -87,7 +86,3 @@ type nopExporter struct {
|
|||
component.Component
|
||||
consumertest.Consumer
|
||||
}
|
||||
|
||||
func (ne *nopExporter) Capabilities() consumer.Capabilities {
|
||||
return consumer.Capabilities{MutatesData: false}
|
||||
}
|
||||
|
|
|
@ -92,7 +92,3 @@ type nopProcessor struct {
|
|||
component.Component
|
||||
consumertest.Consumer
|
||||
}
|
||||
|
||||
func (*nopProcessor) Capabilities() consumer.Capabilities {
|
||||
return consumer.Capabilities{MutatesData: false}
|
||||
}
|
||||
|
|
|
@ -377,9 +377,7 @@ func TestReceiverContentTypes(t *testing.T) {
|
|||
r.Header.Add("content-type", test.content)
|
||||
r.Header.Add("content-encoding", test.encoding)
|
||||
|
||||
next := &zipkinMockTraceConsumer{
|
||||
ch: make(chan pdata.Traces, 10),
|
||||
}
|
||||
next := new(consumertest.TracesSink)
|
||||
cfg := &Config{
|
||||
ReceiverSettings: config.NewReceiverSettings(zipkinReceiverID),
|
||||
HTTPServerSettings: confighttp.HTTPServerSettings{
|
||||
|
@ -391,16 +389,12 @@ func TestReceiverContentTypes(t *testing.T) {
|
|||
|
||||
req := httptest.NewRecorder()
|
||||
zr.ServeHTTP(req, r)
|
||||
require.Equal(t, 202, req.Code)
|
||||
|
||||
select {
|
||||
case td := <-next.ch:
|
||||
require.NotNil(t, td)
|
||||
require.Equal(t, 202, req.Code)
|
||||
break
|
||||
case <-time.After(time.Second * 2):
|
||||
t.Error("next consumer did not receive the batch")
|
||||
break
|
||||
}
|
||||
assert.Eventually(t, func() bool {
|
||||
allTraces := next.AllTraces()
|
||||
return len(allTraces) != 0
|
||||
}, 2*time.Second, 10*time.Millisecond)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -412,16 +406,13 @@ func TestReceiverInvalidContentType(t *testing.T) {
|
|||
bytes.NewBuffer([]byte(body)))
|
||||
r.Header.Add("content-type", "application/json")
|
||||
|
||||
next := &zipkinMockTraceConsumer{
|
||||
ch: make(chan pdata.Traces, 10),
|
||||
}
|
||||
cfg := &Config{
|
||||
ReceiverSettings: config.NewReceiverSettings(zipkinReceiverID),
|
||||
HTTPServerSettings: confighttp.HTTPServerSettings{
|
||||
Endpoint: "",
|
||||
},
|
||||
}
|
||||
zr, err := New(cfg, next)
|
||||
zr, err := New(cfg, consumertest.NewNop())
|
||||
require.NoError(t, err)
|
||||
|
||||
req := httptest.NewRecorder()
|
||||
|
@ -438,17 +429,13 @@ func TestReceiverConsumerError(t *testing.T) {
|
|||
r := httptest.NewRequest("POST", "/api/v2/spans", bytes.NewBuffer(body))
|
||||
r.Header.Add("content-type", "application/json")
|
||||
|
||||
next := &zipkinMockTraceConsumer{
|
||||
ch: make(chan pdata.Traces, 10),
|
||||
err: errors.New("consumer error"),
|
||||
}
|
||||
cfg := &Config{
|
||||
ReceiverSettings: config.NewReceiverSettings(zipkinReceiverID),
|
||||
HTTPServerSettings: confighttp.HTTPServerSettings{
|
||||
Endpoint: "localhost:9411",
|
||||
},
|
||||
}
|
||||
zr, err := New(cfg, next)
|
||||
zr, err := New(cfg, consumertest.NewErr(errors.New("consumer error")))
|
||||
require.NoError(t, err)
|
||||
|
||||
req := httptest.NewRecorder()
|
||||
|
@ -510,20 +497,6 @@ func compressZlib(body []byte) (*bytes.Buffer, error) {
|
|||
return &buf, nil
|
||||
}
|
||||
|
||||
type zipkinMockTraceConsumer struct {
|
||||
ch chan pdata.Traces
|
||||
err error
|
||||
}
|
||||
|
||||
func (m *zipkinMockTraceConsumer) Capabilities() consumer.Capabilities {
|
||||
return consumer.Capabilities{MutatesData: false}
|
||||
}
|
||||
|
||||
func (m *zipkinMockTraceConsumer) ConsumeTraces(_ context.Context, td pdata.Traces) error {
|
||||
m.ch <- td
|
||||
return m.err
|
||||
}
|
||||
|
||||
func TestConvertSpansToTraceSpans_JSONWithoutSerivceName(t *testing.T) {
|
||||
blob, err := ioutil.ReadFile("./testdata/sample2.json")
|
||||
require.NoError(t, err, "Failed to read sample JSON file: %v", err)
|
||||
|
@ -545,9 +518,7 @@ func TestReceiverConvertsStringsToTypes(t *testing.T) {
|
|||
r := httptest.NewRequest("POST", "/api/v2/spans", bytes.NewBuffer(body))
|
||||
r.Header.Add("content-type", "application/json")
|
||||
|
||||
next := &zipkinMockTraceConsumer{
|
||||
ch: make(chan pdata.Traces, 10),
|
||||
}
|
||||
next := new(consumertest.TracesSink)
|
||||
cfg := &Config{
|
||||
ReceiverSettings: config.NewReceiverSettings(zipkinReceiverID),
|
||||
HTTPServerSettings: confighttp.HTTPServerSettings{
|
||||
|
@ -560,44 +531,38 @@ func TestReceiverConvertsStringsToTypes(t *testing.T) {
|
|||
|
||||
req := httptest.NewRecorder()
|
||||
zr.ServeHTTP(req, r)
|
||||
require.Equal(t, 202, req.Code)
|
||||
|
||||
select {
|
||||
case td := <-next.ch:
|
||||
require.NotNil(t, td)
|
||||
require.Equal(t, 202, req.Code)
|
||||
require.Eventually(t, func() bool {
|
||||
allTraces := next.AllTraces()
|
||||
return len(allTraces) != 0
|
||||
}, 2*time.Second, 10*time.Millisecond)
|
||||
|
||||
span := td.ResourceSpans().At(0).InstrumentationLibrarySpans().At(0).Spans().At(0)
|
||||
td := next.AllTraces()[0]
|
||||
span := td.ResourceSpans().At(0).InstrumentationLibrarySpans().At(0).Spans().At(0)
|
||||
|
||||
expected := pdata.NewAttributeMap().InitFromMap(map[string]pdata.AttributeValue{
|
||||
"cache_hit": pdata.NewAttributeValueBool(true),
|
||||
"ping_count": pdata.NewAttributeValueInt(25),
|
||||
"timeout": pdata.NewAttributeValueDouble(12.3),
|
||||
"clnt/finagle.version": pdata.NewAttributeValueString("6.45.0"),
|
||||
"http.path": pdata.NewAttributeValueString("/api"),
|
||||
"http.status_code": pdata.NewAttributeValueInt(500),
|
||||
"net.host.ip": pdata.NewAttributeValueString("7::80:807f"),
|
||||
"peer.service": pdata.NewAttributeValueString("backend"),
|
||||
"net.peer.ip": pdata.NewAttributeValueString("192.168.99.101"),
|
||||
"net.peer.port": pdata.NewAttributeValueInt(9000),
|
||||
}).Sort()
|
||||
expected := pdata.NewAttributeMap().InitFromMap(map[string]pdata.AttributeValue{
|
||||
"cache_hit": pdata.NewAttributeValueBool(true),
|
||||
"ping_count": pdata.NewAttributeValueInt(25),
|
||||
"timeout": pdata.NewAttributeValueDouble(12.3),
|
||||
"clnt/finagle.version": pdata.NewAttributeValueString("6.45.0"),
|
||||
"http.path": pdata.NewAttributeValueString("/api"),
|
||||
"http.status_code": pdata.NewAttributeValueInt(500),
|
||||
"net.host.ip": pdata.NewAttributeValueString("7::80:807f"),
|
||||
"peer.service": pdata.NewAttributeValueString("backend"),
|
||||
"net.peer.ip": pdata.NewAttributeValueString("192.168.99.101"),
|
||||
"net.peer.port": pdata.NewAttributeValueInt(9000),
|
||||
}).Sort()
|
||||
|
||||
actual := span.Attributes().Sort()
|
||||
actual := span.Attributes().Sort()
|
||||
|
||||
assert.EqualValues(t, expected, actual)
|
||||
break
|
||||
case <-time.After(time.Second * 2):
|
||||
t.Error("next consumer did not receive the batch")
|
||||
break
|
||||
}
|
||||
assert.EqualValues(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestFromBytesWithNoTimestamp(t *testing.T) {
|
||||
noTimestampBytes, err := ioutil.ReadFile("../../translator/trace/zipkin/testdata/zipkin_v2_notimestamp.json")
|
||||
require.NoError(t, err, "Failed to read sample JSON file: %v", err)
|
||||
|
||||
next := &zipkinMockTraceConsumer{
|
||||
ch: make(chan pdata.Traces, 10),
|
||||
}
|
||||
cfg := &Config{
|
||||
ReceiverSettings: config.NewReceiverSettings(config.NewID(typeStr)),
|
||||
HTTPServerSettings: confighttp.HTTPServerSettings{
|
||||
|
@ -605,7 +570,7 @@ func TestFromBytesWithNoTimestamp(t *testing.T) {
|
|||
},
|
||||
ParseStringTags: true,
|
||||
}
|
||||
zi, err := New(cfg, next)
|
||||
zi, err := New(cfg, consumertest.NewNop())
|
||||
require.NoError(t, err)
|
||||
|
||||
hdr := make(http.Header)
|
||||
|
|
Loading…
Reference in New Issue